Jump to content

XP setup script to fix renaming program files to something complex


mrjrt

Recommended Posts

Hello all. I've been using this site as a reference for quite some time and figured I should probably give something back. No idea if anyone will find it useful or not, but here it is, regardless.

 

Basically, I've been tweaking away on a final customised XP install so I never have to fiddle with the d**n thing again and when I need it, it'll be ready. To this end, I've done a fair bit of tweaking and integrating, but there were a few things that I didn't spot cropping up anywhere, so here they are. I'll separate them into multiple posts to keep things coherent.

 

Handy tidbit #1 - Complex renaming of the program files directory.

The winnt.sif options for program files are deceptively restrictive - if they're invalid, setup will just ignore them and use the defaults. IIRC, they have to be in 8.3 format, and IIRC, can't have subdirectories (can't be too sure as I put this together a couple of months ago, but gist is - it's flaky)

 

However, I found that if you simply update the registry yourself at T-39, then you're fine, as long as you take a couple of precautions as setup.exe's environment won't be refreshed, and scripts started by it will inherit that environment. All you have to do is manually update the variables and you're fine. Here's my detached.cmd

@ECHO OFFSetlocal EnableDelayedExpansionecho Detached > %SYSTEMDRIVE%\setupcomplete.logdate /T >> %SYSTEMDRIVE%\setupcomplete.logtime /T >> %SYSTEMDRIVE%\setupcomplete.logset >> %SYSTEMDRIVE%\setupcomplete.logSET val=FOR /F delims^=^"^ tokens^=2 %%i in ('findstr /B "ProgramFilesDir" %SystemRoot%\System32\$WinNT$.inf') DO SET val=%%iECHO Program Files Dir specified as !val! >> %SYSTEMDRIVE%\setupcomplete.logIF NOT "%val%" == "" (	IF "%val:~0,1%" == "\" SET val=%SystemDrive%!val!	ECHO Program Files Dir set to !val! >> %SYSTEMDRIVE%\setupcomplete.log	REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion /v ProgramFilesDir /t REG_SZ /d "!val!" /f >> %SYSTEMDRIVE%\setupcomplete.log)rem ECHO REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion /v ProgramFilesPath /t REG_EXPAND_SZ /d %%ProgramFiles%% /f >> %SYSTEMDRIVE%\setupcomplete.logSET val=FOR /F delims^=^"^ tokens^=2 %%i in ('findstr /B "CommonProgramFilesDir" %SystemRoot%\System32\$WinNT$.inf') DO SET val=%%iECHO Common Program Files Dir specified as !val! >> %SYSTEMDRIVE%\setupcomplete.logIF NOT "%val%" == "" (	IF "%val:~0,1%" == "\" SET val=%SystemDrive%!val!	ECHO Common Program Files Dir set to !val! >> %SYSTEMDRIVE%\setupcomplete.log	REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion /v CommonFilesDir /t REG_SZ /d "!val!" /f >> %SYSTEMDRIVE%\setupcomplete.log)set >> %SYSTEMDRIVE%\setupcomplete.logEndLocalEXIT

...this parses the local copy of the winnt.sif file and extracts the actual value you specified, and updates the registry with it.

 

The corresponding safety stub in your other scripts is:

REM Make sure we're using what the registry says - setup won't pick up changes REM and will pass its environment to child processesFOR /F "delims=	 tokens=3" %%i in ('reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion /v ProgramFilesDir') DO SET ProgramFiles=%%iFOR /F "delims=	 tokens=3" %%i in ('reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion /v CommonFilesDir') DO SET CommonProgramFiles=%%i

...and that's pretty much it. You will end up with an empty "Program Files" directory that setup creates, but that can be safely deleted whenever you like. All installers will have the correct paths, and scripts (and installers launched from them) will be correct as long as you update the environment as above.

 

Personally, I have mine set to:

ProgramFilesDir="\Opt\i386-Win32"
CommonProgramFilesDir="\Opt\i386-Win32\Common Files"

 

...and it all works fine.

Edited by mrjrt
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...