gosh Posted October 18, 2003 Share Posted October 18, 2003 I have very ambitious goals for my next cd. One goal i have is to make a batch file that can tell what OS version and OS type you have during installation, and set it as a variable. This will allow you to make 1 batch file that you could use to install on win2k/xp/etc. Most people won't find a use for this, but for people looking for advanced options in an unattended cd, this is priceless. Took me 2 months to figure out.One of my requirements was to make a batch or vbs file that would run on a default install of xp. In other words, i didn't want to do anything such as registering 3rd party files, or mess with xp. I just wanted a script i could run that could set os version and type as a variable that i could use later in a batch file. I also wanted something very simple and easy to use.To fit this requirement i came up with os.vbs and a script. Below is os.vbs, put it in your $OEM$\$$\System32 folder. Make sure unattend file has oempreinstall=yes.os.vbsWScript.Echo SystemRoleFunction SystemRole Dim wmi, wql, Systems, System Set wmi = getobject("winmgmts:") wql = "select DomainRole from Win32_ComputerSystem" Set Systems = wmi.execquery(wql) For Each System In Systems Select Case System.DomainRole Case 0 SystemRole = "Workstation" Case 1 SystemRole = "Workstation" Case 2 SystemRole = "Server" Case 3 SystemRole = "Server" Case 4 SystemRole = "Server" Case 5 SystemRole = "Server" Case Else SystemRole = "Unknown" End Select Exit For NextEnd FunctionPutting os.vbs into $OEM$ folder allows it to be available during unattended install.Now here's part of my apps.bat file. Using os.vbs, it sets the OS type and version as variables, then installs programs using those variables. I call it the pre section of the file, since it sets everything up.REMREM PreREM:PreREMecho starting Pre section >> %windir%\apps.logREM first part - get windows versionver | find "Microsoft Windows 95" > nulif not errorlevel 1 goto Win_95ver | find "Microsoft Windows 98" > nulif not errorlevel 1 goto Win_98ver | find "Microsoft Windows NT" > nulif not errorlevel 1 goto Win_NTver | find "Microsoft Windows 2000" > nulif not errorlevel 1 goto Win_2000ver | find "Microsoft Windows XP" > nulif not errorlevel 1 goto win_xpver | find "5.2.3790" > nulif not errorlevel 1 goto win_2k3goto Unknown_OS:win_95set ostype=win95goto part2:win_98set ostype=win98goto part2:win_ntset ostype=winntgoto part2:win_2000set ostype=win2kgoto part2:win_xpsysteminfo | find "Microsoft Windows XP Professional" > nulif not errorlevel 1 set ostype=winxpprosysteminfo | find "Microsoft Windows XP Home" > nulif not errorlevel 1 set ostype=winxphomegoto part2:win_2k3set ostype=win2k3goto part2:Unknown_OSset ostype=unknowngoto part2REM Second part - see if server or workstation:part2echo OSType=%ostype% >> %windir%\apps.logif not exist %windir%\system32\os.vbs goto Needscriptfor /f "tokens=*" %%a in ('cscript //nologo "%windir%\system32\os.vbs"') do ( set product_type=%%a)goto middleREM - if %product_type%==Workstation REM - if %product_type%==Server goto Server:NeedscriptEcho You need os.vbs installed for this to work!REMREM Middle (installing software)REM:middleecho Product_type=%product_type% >> %windir%\apps.logCLSECHO Please wait as applications are installed. This may take several minutes.@echo.ECHO Installing Norton Antivirus start /min /wait %windir%\Apps\Norton\%product_type%.batECHO Installing AOL Instant Messenger (AIM)start /min /wait %windir%\Apps\AIM\silent.batECHO Installing Winrar 3.20start /min /wait %windir%\Apps\Winrar\silent.batECHO Installing Windows Media Player (WMP) 9.0 Build 2980start /min /wait %windir%\Apps\WMP9\%ostype%.batECHO Installing DirectX 9.0bstart /min /wait %windir%\Apps\DX9\silent.batECHO Installing Adobe Acrobat 6.0start /min /wait %windir%\Apps\Adobe6\silent.batECHO Installing Recovery console and making local sourcestart /min /wait %windir%\Source.batSo when this batch file is run with os.vbs, it'll set the ostype to the version of windows, and it'll set the product_type to the os type (workstation or server, if you wanted to you could customize it to what type of server).The second part of the batch file uses the variables to install applications. For example, to install norton i call %product_type%.bat. In the norton folder, i have workstation.bat and server.bat. If workstation.bat is called, is installs norton antivirus corp edition for clients, if server.bat is called, it installs norton antivirus server edition. You could see how useful these variables could be.Another example is media player. There's different versions of media player 9 for win2k and xp. If apps.bat is run on win2k, it calls win2k.bat which installs the win2k version of wmp9. If apps.bat is run on xp, it calls winxppro.bat or winxphome.bat which installs the xp version of wmp9.So as you can see, it would be very possible to make a single batch file that can be used to install win2k and xp. Most people won't need this type of customization. I originally came up with this idea for 2 reasons:1 - I've made many unattended cd's, and a very common problem is trying to use the latest version of my $OEM$ Folder. Each cd i make has an updated version of $OEM$. When i make a new cd, i have to look through my cd's to see what is the newest version of $OEM$. With one common script for every OS, i wouldn't have to modify it for each cd. Instead i could use one $OEM$ folder for every unattended cd, saving time and making things simpler.2 - I've made cd's that install 2 different os', such as my XP2k cd. It would be very useful to have 1 $OEM$ folder for everything, rather than editing each $OEM$ folder for each install.So again, my method is not for everyone. For some people such as myself, this method is invaluable. It took me a couple months of research to put it all together. From my research i can safely say it's not easy to do what this does!Enjoy,-gosh Link to comment Share on other sites More sharing options...
visaversa Posted October 18, 2003 Share Posted October 18, 2003 Thanks for sharing again your great work. I myself was thinking doing the same in a later stadium of building unattended installs.So you give me a great head start. What can I say more. :-)THXW Link to comment Share on other sites More sharing options...
gosh Posted October 18, 2003 Author Share Posted October 18, 2003 thanku I hope people appreciate my work and use it in their unattended cd's.-gosh Link to comment Share on other sites More sharing options...
un4given1 Posted October 18, 2003 Share Posted October 18, 2003 Gosh: This is a method I use for software installations for the company I work for. I have a script that determines windows version, office version, Norton version, Lotus Notes version, Acrobat Reader version, as well as other softwares and then updates them accordingly. I use batch files myself to accomplish this. It's a great idea though. The script I have goes as far as disecting the IP address on the machine and determining which store it is at, and since each store has a different norton server it updates accordingly. As it is run on each PC it dumps a log file on a network location including all of the information. I have found that there is almost nothing that can't be done with batch scripts. Link to comment Share on other sites More sharing options...
gosh Posted October 18, 2003 Author Share Posted October 18, 2003 Great. If you have any scripts you'd like to share please post them for all to learn from.-gosh Link to comment Share on other sites More sharing options...
RyanVM Posted October 19, 2003 Share Posted October 19, 2003 I'd still be interested in figuring out a way to have certain program install only on computers meeting a requirement. For example, only installing Hyperion drivers on VIA based systems or Forceware on nForce boards. Link to comment Share on other sites More sharing options...
gosh Posted October 19, 2003 Author Share Posted October 19, 2003 Find some command that returns via specific values.For example, is there a registry key or file only on VIA systems? Like the enum key?I don't know if that info would be in systeminfo.exe, but if it was you could simply do:systeminfo | find "via" > nulif not errorlevel 1 goto viafoundThat's purely hypothetical, but you see my point. If some program returned a value that showed via was installed, you could use that to search for it. You could also look on the hard drive for a file specific to via. I'm thinking devcon.exe might be useful.-gosh Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now