implemented feature request #1124901 - Registry functions and ShellVarContext

all registry instructions now accept SHCTX which is replaced with HKLM or HKCU on runtime according to SetShellVarContext


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3907 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2005-02-17 21:20:05 +00:00
parent 023618b590
commit d192713026
4 changed files with 32 additions and 18 deletions

View file

@ -161,7 +161,7 @@ Write a string to the registry. See \R{writeregexpandstr}{WriteRegExpandStr} for
\c root_key subkey key_name value \c root_key subkey key_name value
Write a string to the registry. root_key must be one of: Write a string to the registry. \e{root_key} must be one of:
\b \e{HKCR} or \e{HKEY_CLASSES_ROOT} \b \e{HKCR} or \e{HKEY_CLASSES_ROOT}
@ -177,6 +177,10 @@ Write a string to the registry. root_key must be one of:
\b \e{HKPD} or \e{HKEY_PERFORMANCE_DATA} \b \e{HKPD} or \e{HKEY_PERFORMANCE_DATA}
\b \e{SHCTX} or \e{SHELL_CONTEXT}
If \e{root_key} is \e{SHCTX} or \e{SHELL_CONTEXT}, it will be replaced with \e{HKLM} if \R{setshellvarcontext}{SetShellVarContext} is set to \e{all} and with \e{HKCU} if \R{setshellvarcontext}{SetShellVarContext} is set to \e{current}.
The error flag is set if the string could not be written to the registry. The type of the string will be REG_SZ for WriteRegStr, or REG_EXPAND_STR for WriteRegExpandStr. If the registry key doesn't exist it will be created. The error flag is set if the string could not be written to the registry. The type of the string will be REG_SZ for WriteRegStr, or REG_EXPAND_STR for WriteRegExpandStr. If the registry key doesn't exist it will be created.
\c WriteRegExpandStr HKLM "Software\My Company\My Software" "Expand String Value" "%WINDIR%\notepad.exe" \c WriteRegExpandStr HKLM "Software\My Company\My Software" "Expand String Value" "%WINDIR%\notepad.exe"

View file

@ -133,10 +133,19 @@ static LONG NSISCALL myRegDeleteKeyEx(HKEY thiskey, LPCTSTR lpSubKey, int onlyif
return retval; return retval;
} }
static HKEY NSISCALL GetRegRootKey(int hRootKey)
{
if (hRootKey)
return (HKEY) hRootKey;
// HKEY_LOCAL_MACHINE - HKEY_CURRENT_USER == 1
return (HKEY) ((int) HKEY_CURRENT_USER + g_exec_flags.all_user_var);
}
static HKEY NSISCALL myRegOpenKey(REGSAM samDesired) static HKEY NSISCALL myRegOpenKey(REGSAM samDesired)
{ {
HKEY hKey; HKEY hKey;
if (RegOpenKeyEx((HKEY) parms[1], GetStringFromParm(0x22), 0, samDesired, &hKey) == ERROR_SUCCESS) if (RegOpenKeyEx(GetRegRootKey(parms[1]), GetStringFromParm(0x22), 0, samDesired, &hKey) == ERROR_SUCCESS)
{ {
return hKey; return hKey;
} }
@ -1129,7 +1138,7 @@ static int NSISCALL ExecuteEntry(entry *entry_)
{ {
char *buf2=GetStringFromParm(0x22); char *buf2=GetStringFromParm(0x22);
log_printf3("DeleteRegKey: %d\\%s",parm1,buf2); log_printf3("DeleteRegKey: %d\\%s",parm1,buf2);
res = myRegDeleteKeyEx((HKEY)parm1,buf2,parm4&2); res = myRegDeleteKeyEx(GetRegRootKey(parm1),buf2,parm4&2);
} }
if (res != ERROR_SUCCESS) if (res != ERROR_SUCCESS)
exec_error++; exec_error++;
@ -1138,13 +1147,13 @@ static int NSISCALL ExecuteEntry(entry *entry_)
case EW_WRITEREG: // write registry value case EW_WRITEREG: // write registry value
{ {
HKEY hKey; HKEY hKey;
int rootkey=parm0; HKEY rootkey=GetRegRootKey(parm0);
int type=parm4; int type=parm4;
int rtype=parm5; int rtype=parm5;
char *buf0=GetStringFromParm(0x02); char *buf0=GetStringFromParm(0x02);
char *buf1=GetStringFromParm(0x11); char *buf1=GetStringFromParm(0x11);
exec_error++; exec_error++;
if (RegCreateKeyEx((HKEY)rootkey,buf1,0,0,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,0,&hKey,0) == ERROR_SUCCESS) if (RegCreateKeyEx(rootkey,buf1,0,0,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,0,&hKey,0) == ERROR_SUCCESS)
{ {
LPBYTE data = (LPBYTE) buf2; LPBYTE data = (LPBYTE) buf2;
DWORD size = 0; DWORD size = 0;

View file

@ -802,11 +802,11 @@ int CEXEBuild::process_jump(LineParser &line, int wt, int *offs)
int CEXEBuild::doCommand(int which_token, LineParser &line) int CEXEBuild::doCommand(int which_token, LineParser &line)
{ {
static const char *rootkeys[2] = { static const char *rootkeys[2] = {
"HKCR\0HKLM\0HKCU\0HKU\0HKCC\0HKDD\0HKPD\0", "HKCR\0HKLM\0HKCU\0HKU\0HKCC\0HKDD\0HKPD\0SHCTX\0",
"HKEY_CLASSES_ROOT\0HKEY_LOCAL_MACHINE\0HKEY_CURRENT_USER\0HKEY_USERS\0HKEY_CURRENT_CONFIG\0HKEY_DYN_DATA\0HKEY_PERFORMANCE_DATA\0" "HKEY_CLASSES_ROOT\0HKEY_LOCAL_MACHINE\0HKEY_CURRENT_USER\0HKEY_USERS\0HKEY_CURRENT_CONFIG\0HKEY_DYN_DATA\0HKEY_PERFORMANCE_DATA\0SHELL_CONTEXT\0"
}; };
static HKEY rootkey_tab[] = { static HKEY rootkey_tab[] = {
HKEY_CLASSES_ROOT,HKEY_LOCAL_MACHINE,HKEY_CURRENT_USER,HKEY_USERS,HKEY_CURRENT_CONFIG,HKEY_DYN_DATA,HKEY_PERFORMANCE_DATA HKEY_CLASSES_ROOT,HKEY_LOCAL_MACHINE,HKEY_CURRENT_USER,HKEY_USERS,HKEY_CURRENT_CONFIG,HKEY_DYN_DATA,HKEY_PERFORMANCE_DATA,0
}; };
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT #ifdef NSIS_CONFIG_PLUGIN_SUPPORT
@ -1905,6 +1905,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (k == -1) k=line.gettoken_enum(1,rootkeys[1]); if (k == -1) k=line.gettoken_enum(1,rootkeys[1]);
if (k == -1) PRINTHELP() if (k == -1) PRINTHELP()
build_header.install_reg_rootkey=(int)rootkey_tab[k]; build_header.install_reg_rootkey=(int)rootkey_tab[k];
if (!build_header.install_reg_rootkey) PRINTHELP() // SHCTX is invalid here
build_header.install_reg_key_ptr = add_string(line.gettoken_str(2),0); build_header.install_reg_key_ptr = add_string(line.gettoken_str(2),0);
if (line.gettoken_str(2)[0] == '\\') if (line.gettoken_str(2)[0] == '\\')
warning_fl("%s: registry path name begins with \'\\\', may cause problems",line.gettoken_str(0)); warning_fl("%s: registry path name begins with \'\\\', may cause problems",line.gettoken_str(0));

View file

@ -53,8 +53,8 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_DBOPTIMIZE,"SetDatablockOptimize",1,0,"(off|on)",TP_ALL}, {TOK_DBOPTIMIZE,"SetDatablockOptimize",1,0,"(off|on)",TP_ALL},
{TOK_DELETEINISEC,"DeleteINISec",2,0,"ini_file section_name",TP_CODE}, {TOK_DELETEINISEC,"DeleteINISec",2,0,"ini_file section_name",TP_CODE},
{TOK_DELETEINISTR,"DeleteINIStr",3,0,"ini_file section_name entry_name",TP_CODE}, {TOK_DELETEINISTR,"DeleteINIStr",3,0,"ini_file section_name entry_name",TP_CODE},
{TOK_DELETEREGKEY,"DeleteRegKey",2,1,"[/ifempty] root_key subkey\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)",TP_CODE}, {TOK_DELETEREGKEY,"DeleteRegKey",2,1,"[/ifempty] root_key subkey\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE},
{TOK_DELETEREGVALUE,"DeleteRegValue",3,0,"root_key subkey entry_name\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)",TP_CODE}, {TOK_DELETEREGVALUE,"DeleteRegValue",3,0,"root_key subkey entry_name\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE},
{TOK_DELETE,"Delete",1,1,"[/REBOOTOK] filespec",TP_CODE}, {TOK_DELETE,"Delete",1,1,"[/REBOOTOK] filespec",TP_CODE},
{TOK_DETAILPRINT,"DetailPrint",1,0,"message",TP_CODE}, {TOK_DETAILPRINT,"DetailPrint",1,0,"message",TP_CODE},
{TOK_DIRTEXT,"DirText",0,4,"[directory_page_description] [directory_page_subtext] [browse_button_text] [browse_dlg_text]",TP_PG}, {TOK_DIRTEXT,"DirText",0,4,"[directory_page_description] [directory_page_subtext] [browse_button_text] [browse_dlg_text]",TP_PG},
@ -66,8 +66,8 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_ROOTDIRINST,"AllowRootDirInstall",1,0,"(true|false)",TP_GLOBAL}, {TOK_ROOTDIRINST,"AllowRootDirInstall",1,0,"(true|false)",TP_GLOBAL},
{TOK_CHECKBITMAP,"CheckBitmap",1,0,"local_bitmap.bmp",TP_GLOBAL}, {TOK_CHECKBITMAP,"CheckBitmap",1,0,"local_bitmap.bmp",TP_GLOBAL},
{TOK_ENABLEWINDOW,"EnableWindow",2,0,"hwnd (1|0)",TP_CODE}, {TOK_ENABLEWINDOW,"EnableWindow",2,0,"hwnd (1|0)",TP_CODE},
{TOK_ENUMREGKEY,"EnumRegKey",4,0,"$(user_var: output) rootkey subkey index\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)",TP_CODE}, {TOK_ENUMREGKEY,"EnumRegKey",4,0,"$(user_var: output) rootkey subkey index\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE},
{TOK_ENUMREGVAL,"EnumRegValue",4,0,"$(user_var: output) rootkey subkey index\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)",TP_CODE}, {TOK_ENUMREGVAL,"EnumRegValue",4,0,"$(user_var: output) rootkey subkey index\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE},
{TOK_EXCH,"Exch",0,1,"[$(user_var)] | [stack_item_index]",TP_CODE}, {TOK_EXCH,"Exch",0,1,"[$(user_var)] | [stack_item_index]",TP_CODE},
{TOK_EXEC,"Exec",1,0,"command_line",TP_CODE}, {TOK_EXEC,"Exec",1,0,"command_line",TP_CODE},
{TOK_EXECWAIT,"ExecWait",1,1,"command_line [$(user_var: return value)]",TP_CODE}, {TOK_EXECWAIT,"ExecWait",1,1,"command_line [$(user_var: return value)]",TP_CODE},
@ -139,8 +139,8 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_PUSH,"Push",1,0,"string",TP_CODE}, {TOK_PUSH,"Push",1,0,"string",TP_CODE},
{TOK_QUIT,"Quit",0,0,"",TP_CODE}, {TOK_QUIT,"Quit",0,0,"",TP_CODE},
{TOK_READINISTR,"ReadINIStr",4,0,"$(user_var: output) ini_file section entry_name",TP_CODE}, {TOK_READINISTR,"ReadINIStr",4,0,"$(user_var: output) ini_file section entry_name",TP_CODE},
{TOK_READREGDWORD,"ReadRegDWORD",4,0,"$(user_var: output) rootkey subkey entry\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)",TP_CODE}, {TOK_READREGDWORD,"ReadRegDWORD",4,0,"$(user_var: output) rootkey subkey entry\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE},
{TOK_READREGSTR,"ReadRegStr",4,0,"$(user_var: output) rootkey subkey entry\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)",TP_CODE}, {TOK_READREGSTR,"ReadRegStr",4,0,"$(user_var: output) rootkey subkey entry\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE},
{TOK_READENVSTR,"ReadEnvStr",2,0,"$(user_var: output) name",TP_CODE}, {TOK_READENVSTR,"ReadEnvStr",2,0,"$(user_var: output) name",TP_CODE},
{TOK_REBOOT,"Reboot",0,0,"",TP_CODE}, {TOK_REBOOT,"Reboot",0,0,"",TP_CODE},
{TOK_REGDLL,"RegDLL",1,1,"dll_path_on_target.dll [entrypoint_symbol]",TP_CODE}, {TOK_REGDLL,"RegDLL",1,1,"dll_path_on_target.dll [entrypoint_symbol]",TP_CODE},
@ -212,10 +212,10 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_UNREGDLL,"UnRegDLL",1,0,"dll_path_on_target.dll",TP_CODE}, {TOK_UNREGDLL,"UnRegDLL",1,0,"dll_path_on_target.dll",TP_CODE},
{TOK_WINDOWICON,"WindowIcon",1,0,"on|off",TP_GLOBAL}, {TOK_WINDOWICON,"WindowIcon",1,0,"on|off",TP_GLOBAL},
{TOK_WRITEINISTR,"WriteINIStr",4,0,"ini_file section_name entry_name new_value",TP_CODE}, {TOK_WRITEINISTR,"WriteINIStr",4,0,"ini_file section_name entry_name new_value",TP_CODE},
{TOK_WRITEREGBIN,"WriteRegBin",4,0,"rootkey subkey entry_name hex_string_like_12848412AB\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)",TP_CODE}, {TOK_WRITEREGBIN,"WriteRegBin",4,0,"rootkey subkey entry_name hex_string_like_12848412AB\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE},
{TOK_WRITEREGDWORD,"WriteRegDWORD",4,0,"rootkey subkey entry_name new_value_dword\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)",TP_CODE}, {TOK_WRITEREGDWORD,"WriteRegDWORD",4,0,"rootkey subkey entry_name new_value_dword\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE},
{TOK_WRITEREGSTR,"WriteRegStr",4,0,"rootkey subkey entry_name new_value_string\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)",TP_CODE}, {TOK_WRITEREGSTR,"WriteRegStr",4,0,"rootkey subkey entry_name new_value_string\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE},
{TOK_WRITEREGEXPANDSTR,"WriteRegExpandStr",4,0,"rootkey subkey entry_name new_value_string\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)",TP_CODE}, {TOK_WRITEREGEXPANDSTR,"WriteRegExpandStr",4,0,"rootkey subkey entry_name new_value_string\n root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD|SHCTX)",TP_CODE},
{TOK_WRITEUNINSTALLER,"WriteUninstaller",1,0,"uninstall_exe_name",TP_CODE}, {TOK_WRITEUNINSTALLER,"WriteUninstaller",1,0,"uninstall_exe_name",TP_CODE},
{TOK_XPSTYLE, "XPStyle",1,0,"(on|off)",TP_GLOBAL}, {TOK_XPSTYLE, "XPStyle",1,0,"(on|off)",TP_GLOBAL},
{TOK_P_PACKEXEHEADER,"!packhdr",2,0,"temp_file_name command_line_to_compress_that_temp_file",TP_ALL}, {TOK_P_PACKEXEHEADER,"!packhdr",2,0,"temp_file_name command_line_to_compress_that_temp_file",TP_ALL},