#134483 - 2005-02-24 03:49 PM
Insert environment variables in registry
|
Shootking
Lurker
Registered: 2005-02-24
Posts: 1
|
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
|
Top
|
|
|
|
#134485 - 2005-02-24 07:26 PM
Re: Insert environment variables in registry
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
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
|
Top
|
|
|
|
#134486 - 2005-02-24 07:57 PM
Re: Insert environment variables in registry
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
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.
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 515 anonymous users online.
|
|
|