$theTitle=wp_title(" - ", false); if($theTitle != "") { ?>
About Virtualization, VDI, SBC, Application Compatibility and anything else I feel like
13 Dec // php the_time('Y') ?>
I usually change the text below the “This Computer” icon to reflect the current username and servername:
This is an ancient trick, just set the the LocalizedString Value of the following key:
1 | HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D} |
to “%USERNAME% on %COMPUTERNAME%”.
It get’s a little more complicated if you want to set this from a script, because the environment variables are replaced with the actual value BEFORE they are entered in the Registry.
So I always did this with a small VBScript but I figured we should be able to do it with a simple oneliner.
I first tried the Reg command because the help describes that you can use the caret sign (^) and even gives an example:
1 | REG ADD HKLM\Software\MyCo /v Path /t REG_EXPAND_SZ /d ^%systemroot^% |
It actually works if we do this:
1 | REG ADD HKCR\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D} /v LocalizedString /t REG_EXPAND_SZ /d ^%USERNAME^% |
But it fails if we try this:
1 | REG ADD HKCR\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D} /v LocalizedString /t REG_EXPAND_SZ /d "^%USERNAME^% on ^%COMPUTERNAME^%" |
My next try was to do it in PowerShell but if using the “& {<command>}” syntax it fails because of the same reason.
So I came up with the following code:
1 2 | Set TEXT=@USERNAME@ OP @COMPUTERNAME@ powershell.exe "& {Set-ItemProperty -path 'HKLM:Software\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}' -name LocalizedString -value ('%TEXT%' -replace '@',[char]0x25)}" |
Basically I use an environment var to set a readable string where the % sign is replaced by the @ sign.
And in the PowerShell statement I use the -replace operator to replace the @ with a % again.
I used [char]0x25 (0x25 is the Hex value of the ASCII code for %) because a single % sign is removed in a bat file.
Basically I use an environment var to set a readable string where the % sign is replaced by the @ sign.
And in the PowerShell statement I use the -replace operator to replace the @ with a % again.
I used [char]0x25 (0x25 is the Hex value of the ASCII code for %) because a single % sign is removed in a bat file.
One Response for "Writing Environment Variables to the Registry from a Script"
In *.CMD use:
REG.EXE Add … /T REG_EXPAND_SZ /D “%%USERNAME%% on %%COMPUTERNAME%%” /F
Leave a reply