Page 1 of 1 1
Topic Options
#134483 - 2005-02-24 03:49 PM Insert environment variables in registry
Shootking Offline
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
#134484 - 2005-02-24 07:23 PM Re: Insert environment variables in registry
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#134485 - 2005-02-24 07:26 PM Re: Insert environment variables in registry
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#134486 - 2005-02-24 07:57 PM Re: Insert environment variables in registry
Glenn Barnas Administrator Offline
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! \:D

Top
#134487 - 2005-02-25 03:45 AM Re: Insert environment variables in registry
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
And it requires admin privs to make changes to that section of the registry.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.054 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org