added SetRegView to allows access to the x64 registry view

this method was chosen over a new switch for all regsitry commands to allow easy transition of existing scripts


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5070 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2007-04-14 12:50:32 +00:00
parent 1f116b5f3d
commit 357c44ac38
7 changed files with 60 additions and 4 deletions

View file

@ -80,6 +80,7 @@ typedef struct {
int instdir_error;
int rtl;
int errlvl;
int alter_reg_view;
} exec_flags_type;
typedef struct {

View file

@ -65,6 +65,29 @@ Sets the error level of the installer or uninstaller to \e{error_level}. See \R{
\c IfRebootFlag 0 +2
\c SetErrorLevel 4
\S2{setregview} SetRegView
\c \\<b\\>32\\</b\\>|64
Sets the registry view affected by \R{registry}{registry commands}. On Windows x64 there are two views. One for 32-bit applications and one for x64 applications. By default, 32-bit applications running on x64 systems under WOW64 have access only to the 32-bit view. Using \c{SetRegView 64} allows the installer to access keys in the x64 view of the registry.
Affects \R{deleteregkey}{DeleteRegKey}, \R{deleteregvalue}{DeleteRegValue}, \R{enumregkey}{EnumRegKey}, \R{enumregvalue}{EnumRegValue}, \R{readregdword}{ReadRegDWORD}, \R{readregstr}{ReadRegStr}, \R{writeregbin}{WriteRegBin}, \R{writeregdword}{WriteRegDWORD}, \R{writeregstr}{WriteRegStr} and \R{writeregexpandstr}{WriteRegExpandStr}.
Does not affect \R{ainstalldirregkey}{InstallDirRegKey}. Instead, the registry can be read using \R{readregstr}{ReadRegStr} in \R{oninit}{.onInit}.
\c SetRegView 32
\c ReadRegStr $0 HKLM Software\Microsoft\Windows\CurrentVersion ProgramFilesDir
\c DetailPrit $0 # prints C:\Program Files (x86)
\c SetRegView 64
\c ReadRegStr $0 HKLM Software\Microsoft\Windows\CurrentVersion ProgramFilesDir
\c DetailPrit $0 # prints C:\Program Files
\c Function .onInit
\c SetRegView 64
\c ReadRegStr $INSTDIR HKLM Software\NSIS ""
\c SetRegView 32
\c FunctionEnd
\S2{setshellvarcontext} SetShellVarContext
\c \\<b\\>current\\</b\\>|all

View file

@ -125,13 +125,22 @@ static char * NSISCALL GetStringFromParm(int id_)
}
#ifdef NSIS_SUPPORT_REGISTRYFUNCTIONS
REGSAM NSISCALL AlterRegistrySAM(REGSAM sam)
{
if (g_exec_flags.alter_reg_view)
{
return sam | KEY_WOW64_64KEY;
}
return sam;
}
// based loosely on code from Tim Kosse
// in win9x this isn't necessary (RegDeleteKey() can delete a tree of keys),
// but in win2k you need to do this manually.
static LONG NSISCALL myRegDeleteKeyEx(HKEY thiskey, LPCTSTR lpSubKey, int onlyifempty)
{
HKEY key;
int retval=RegOpenKeyEx(thiskey,lpSubKey,0,KEY_ENUMERATE_SUB_KEYS,&key);
int retval=RegOpenKeyEx(thiskey,lpSubKey,0,AlterRegistrySAM(KEY_ENUMERATE_SUB_KEYS),&key);
if (retval==ERROR_SUCCESS)
{
// NB - don't change this to static (recursive function)
@ -146,7 +155,16 @@ static LONG NSISCALL myRegDeleteKeyEx(HKEY thiskey, LPCTSTR lpSubKey, int onlyif
if ((retval=myRegDeleteKeyEx(key,buffer,0)) != ERROR_SUCCESS) break;
}
RegCloseKey(key);
retval=RegDeleteKey(thiskey,lpSubKey);
{
typedef (WINAPI * RegDeleteKeyExAPtr)(HKEY, LPCTSTR, REGSAM, DWORD);
RegDeleteKeyExAPtr RDKE = (RegDeleteKeyExAPtr)
myGetProcAddress("ADVAPI32.dll","RegDeleteKeyExA");
if (RDKE)
retval=RDKE(thiskey,lpSubKey,AlterRegistrySAM(0),0);
else
retval=RegDeleteKey(thiskey,lpSubKey);
}
}
return retval;
}
@ -163,7 +181,7 @@ static HKEY NSISCALL GetRegRootKey(int hRootKey)
static HKEY NSISCALL myRegOpenKey(REGSAM samDesired)
{
HKEY hKey;
if (RegOpenKeyEx(GetRegRootKey(parms[1]), GetStringFromParm(0x22), 0, samDesired, &hKey) == ERROR_SUCCESS)
if (RegOpenKeyEx(GetRegRootKey(parms[1]), GetStringFromParm(0x22), 0, AlterRegistrySAM(samDesired), &hKey) == ERROR_SUCCESS)
{
return hKey;
}
@ -1190,7 +1208,7 @@ static int NSISCALL ExecuteEntry(entry *entry_)
const char *rkn UNUSED=RegKeyHandleToName(rootkey);
exec_error++;
if (RegCreateKeyEx(rootkey,buf1,0,0,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,0,&hKey,0) == ERROR_SUCCESS)
if (RegCreateKeyEx(rootkey,buf1,0,0,0,AlterRegistrySAM(KEY_SET_VALUE),0,&hKey,0) == ERROR_SUCCESS)
{
LPBYTE data = (LPBYTE) buf2;
DWORD size = 0;

View file

@ -509,6 +509,7 @@ typedef struct
int instdir_error;
int rtl;
int errlvl;
int alter_reg_view;
} exec_flags;
#define FIELDN(x, y) (((int *)&x)[y])

View file

@ -3555,6 +3555,17 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (process_jump(line,1,&ent.offsets[0])) PRINTHELP()
SCRIPT_MSG("Goto: %s\n",line.gettoken_str(1));
return add_entry(&ent);
case TOK_SETREGVIEW:
{
ent.which=EW_SETFLAG;
ent.offsets[0]=FLAG_OFFSET(alter_reg_view);
// "64" results in setting the flag to 1 which alters the view
int k=line.gettoken_enum(1,"32\0" "64\0");
if (k<0) PRINTHELP()
ent.offsets[1]=add_intstring(k);
SCRIPT_MSG("SetRegView: %s\n",line.gettoken_str(1));
}
return add_entry(&ent);
case TOK_SETSHELLVARCONTEXT:
{
ent.which=EW_SETFLAG;

View file

@ -194,6 +194,7 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_SETOVERWRITE,"SetOverwrite",1,0,"on|off|try|ifnewer|ifdiff",TP_ALL},
{TOK_SETPLUGINUNLOAD,"SetPluginUnload",1,0,"(manual|alwaysoff)",TP_ALL},
{TOK_SETREBOOTFLAG,"SetRebootFlag",1,0,"true|false",TP_CODE},
{TOK_SETREGVIEW,"SetRegView",1,0,"32|64",TP_CODE},
{TOK_SETSHELLVARCONTEXT,"SetShellVarContext",1,0,"all|current",TP_CODE},
{TOK_SETSILENT,"SetSilent",1,0,"silent|normal",TP_CODE},
{TOK_SHOWDETAILS,"ShowInstDetails",1,0,"(hide|show|nevershow)",TP_GLOBAL},

View file

@ -254,6 +254,7 @@ enum
TOK_INSTTYPEGETTEXT,
TOK_GETCURINSTTYPE,
TOK_SETCURINSTTYPE,
TOK_SETREGVIEW,
TOK_SETSHELLVARCONTEXT,
TOK_PLUGINDIR,
TOK_INITPLUGINSDIR,