Shootking
(Lurker)
2005-02-24 03:49 PM
Insert environment variables in registry

I'm having trouble with inserting environment variables in my registry. I am executing a script containing this row:

$temp = WRITEVALUE("HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "LocalizedString", "%computername% %username%", "REG_EXPAND_SZ")

The problem is that the value %computername% and %username% doesn't get written into the regisrty. It is converted to the username of the current user and the computername of the current compter. I want this to be updated if another user is logged on.

Anyone who can help me with this?

Regards Jens


Glenn BarnasAdministrator
(KiX Supporter)
2005-02-24 07:23 PM
Re: Insert environment variables in registry

You need to "escape" the "%" sign so Kix doesn't interpret it. That requires a "%%" at each end. The end of your command should look like
Code:
 "LocalizedString", "%%USERNAME%% on %%COMPUTERNAME%%", "REG_EXPAND_SZ") 



Glenn


Kdyer
(KiX Supporter)
2005-02-24 07:26 PM
Re: Insert environment variables in registry

Welcome to the board..

You are probably going to run into a couple of snags here.. First, you are going to want to use something like the UDF Name2SID() and Macros @wksta and @userid.

Thanks,

Kent


Glenn BarnasAdministrator
(KiX Supporter)
2005-02-24 07:57 PM
Re: Insert environment variables in registry

Kent,

While it's good to know about macro alternatives, the question was "how to place environment vars in the registry key". If he uses macros, he'll have the same problem he's having now, writing the value to the reg instead of the VarName.

Also, this isn't a user-specific SID - it's a GUID that represents the text for the My Computer desktop icon. For Win2K and higher systems, the code we use here is
Code:
 ; LOCALIZEDSTRING for 2K & higher
If Val(@DOS) >= 5
; delete original
$RTN = DelValue($TARGET + "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "LocalizedString")
; create as Reg_Exp_Sz
$RTN = WriteValue($TARGET + "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "LocalizedString", "%%USERNAME%% on %%COMPUTERNAME%%", "REG_EXPAND_SZ")
EndIf


Note that we DELETE the key first, because by default it is a REG_SZ and not a REG_EXPAND_SZ format, and would not expand the environment var values.


Sealeopard
(KiX Master)
2005-02-25 03:45 AM
Re: Insert environment variables in registry

And it requires admin privs to make changes to that section of the registry.