Jump to content

%SystemRoot% used in registry - what am I missing?


Recommended Posts

I am in the process of adding the feature to copy i386 from my unattended CD to my hard drive. I read all the posts on the topic and found two solutions that seem the best to try.

Gosh Method is to use an xcopy script to copy the files

Jazkal Method is to put a second copy of i386 in the $OEM$\$1 folder and use the -o switch with cdimage so as not to suffer from duplicates on your CD.

My problem is adding the source location in the registry so that Windows knows where to go when it needs source files.

Currently this registry file works great but it is not very flexible since I am forced to C: instead of using variables. I tried replacing the C: with %SystemDrive% but then the registy shows exactly that "%SystemDrive%" and when I try to install anything that needs the CD you get the prompt asking for the CD and the default location is %SystemDrive%.

How can I get this to work?

WORKING

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup]
"Installation Sources"=hex(7):43,00,3a,00,5c,00,49,00,33,00,38,00,36,00,00,00,\
00,00
"SourcePath"="C:"
"ServicePackSourcePath"="C:"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\\I386"

NOT WORKING

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup]
"Installation Sources"=hex(7):43,00,3a,00,5c,00,49,00,33,00,38,00,36,00,00,00,\
00,00
"SourcePath"="%SystemDrive%"
"ServicePackSourcePath"="%SystemDrive%"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="%SystemDrive%\\I386"

Link to comment
Share on other sites


It's impossible to use system variables in the registry or in inf/hive files. That's a common known fact. It's just if you don't know it :P

The solution to fix this is in most cases to run a batch file that adds the specific settings to the registry, using these system variables in the command. The commandline interpreter will replace it by the 'real' value.

Link to comment
Share on other sites

You actually can use environment variables in the registry. Make the registry value have a type of REG_EXPAND_SZ. Can't do that with REGEDIT.EXE but you can with REGEDT32.EXE. As far as doing it with REG or INF files, you can do it with REG files but its less than desirable considering it shows up as hex and isn't exactly human readable. That's why I prefer to use INF's if I have to use an environment variable.

Example:

HKCR,"CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}","LocalizedString",0x00020000,"%USERNAME% / %COMPUTERNAME%"

0x00020000 is REG_EXPAND_SZ

This will store, literally, "%USERNAME%" and "%COMPUTERNAME%" and won't expand them until they are actually used.

And if you were wondering, that entry I used as an example will display the current username and computername as the text for the "My Computer" icon rather than just saying "My Computer"

Hope this helps.

Link to comment
Share on other sites

You can achieve what you are after in a couple of ways:

Add this to your .cmd file (as Bâshrat the Sneaky stated):

REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup" /v "Installation Sources" /t REG_MULTI_SZ /d "%SystemDrive%\I386" /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup" /v SourcePath /t REG_SZ /d "%SystemDrive%" /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup" /v ServicePackSourcePath /t REG_SZ /d "%SystemDrive%" /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v SourcePath /t REG_SZ /d "%SystemDrive%\I386" /f

Alternatively, (contrary to what Bâshrat the Sneaky said), use an inf:

[Version]
Signature=$CHICAGO$

[DefaultInstall]
AddReg = Reg.Settings

[Reg.Settings]
HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Setup,"Installation Sources",0x10000,"%24%\I386"
HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Setup,SourcePath,,"%24%"
HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Setup,ServicePackSourcePath,,"%24%"
HKLM,SOFTWARE\Microsoft\Windows NT\CurrentVersion,SourcePath,,"%24%\I386"

I suppose for the Installation Sources key, you could forget about the "%SysyemDrive%\I386" bit, and because it's a MULTI_SZ value, put something like this in instead "C:\I386,D:\I386,E:\I386,F:\I386,G:\I386,H:\I386", you would then cover your hard disk and optical drives too!

Link to comment
Share on other sites

Great info guys,

You both beat me back to this post, after the command line suggestion I worked out the same code pretty much. Here is what I was about to post as using in my cmd file

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup" /v "Installation Sources" /t REG_MULTI_SZ /d "%SystemDrive%\Support\i386" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup" /v SourcePath /d %SystemDrive%\Support /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup" /v ServicePackSourcePath /d %SystemDrive%\Support /f

reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v SourcePath /d %SystemDrive%\Support\I386 /f

Good to know also about REG_EXPAND_SZ, I was not aware that you could use variables as long as you use REG_EXPAND_SZ

So if I wanted to use REG_EXPAND_SZ in my reg file I would not be able to import it using regedit /s ?

How would I do an expandable multi value like Installation Sources?

It does seem the simplest method is the 4 reg add lines pasted above and just add them to the install.cmd that kicks off all my stuff.

EDIT

did a test by creating registry entries using REG_EXPAND_SZ with a value of %SystemDrive%\Support but this did not work. I was asked for the CD and the path still was looking for %SystemDrive%\Support so it was never converted.

Not that I need to learn this method since adding the 4 lines to cmd file works but I must be doing something wrong getting the REG_EXPAND_SZ working.

Dennis

Link to comment
Share on other sites

In a reg file, if you were wanting to use the REG_EXPAND_SZ method, your reg would start to look something like this:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup]
"Installation Sources"=hex(7):43,00,3a,00,5c,00,49,00,33,00,38,00,36,00,00,00,\
00,00;REG_MULTI_SZ (C:\I386)
"SourcePath"=hex(2):25,53,79,73,74,65,6d,44,72,69,76,65,25,00;REG_EXPAND_SZ (%SystemDrive%)
"ServicePackSourcePath"=hex(2):25,53,79,73,74,65,6d,44,72,69,76,65,25,00;REG_EXPAND_SZ (%SystemDrive%)

i.e you would need your variables in hex format....

Link to comment
Share on other sites

I made this reg file using binary data but it still wont work. The paths are correct in the registry (I think?)

reg file

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup]
"Installation Sources"=hex(7):43,00,3a,00,5c,00,53,00,75,00,70,00,70,00,6f,00,\
 72,00,74,00,5c,00,69,00,33,00,38,00,36,00,00,00,00,00
"SourcePath"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,44,00,72,00,69,\
 00,76,00,65,00,25,00,5c,00,53,00,75,00,70,00,70,00,6f,00,72,00,74,00,00,00
"ServicePackSourcePath"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,44,00,\
 72,00,69,00,76,00,65,00,25,00,5c,00,53,00,75,00,70,00,70,00,6f,00,72,00,74,\
 00,00,00

Here is what the reg looks like

reg.gif

Dennis

Link to comment
Share on other sites

Did you create the keys in the registry editor, and export them out, then find that the reg wouldn't import?

or are you telling us that a REG_EXPAND_SZ key is not working for the SourcePath entries.

I doubt that you can just blindly change all REG_SZ entries for REG_EXPAND_SZ and expect them to work!

Stick with the CMD or INF methods

This would be the INF to match your CMD

[Version]
Signature=$CHICAGO$

[DefaultInstall]
AddReg = Reg.Settings

[Reg.Settings]
HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Setup,"Installation Sources",0x10000,"%24%\Support\i386"
HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Setup,SourcePath,,"%24%\Support"
HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Setup,ServicePackSourcePath,,"%24%\Support"
HKLM,SOFTWARE\Microsoft\Windows NT\CurrentVersion,SourcePath,,"%24%\Support\i386"

Link to comment
Share on other sites

Thanks,

Your right, it already works easily this way and much easier to read in the reg. The info worked perfectly. I will use cmd for cmd importing from my runonce.cmd file and use the inf for quick fixes. Is there a way to use an inf from the command line and have it install or import?

Dennis

Link to comment
Share on other sites

example from cmdlines.txt when inf is in same folder as it

[Commands]
"rundll32.exe setupapi,InstallHinfSection DefaultInstall 128 .\whatever.inf"

example from a cmd

ECHO Applying Whatever.inf
rundll32.exe setupapi.dll,InstallHinfSection DefaultInstall 132 "Drive\Path\whatever.inf"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...