Jump to content

Set Os Version And Type As Variable.


Recommended Posts

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.vbs

WScript.Echo SystemRole

Function 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

Next

End Function

Putting 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.

REM

REM Pre

REM

:Pre

REM

echo starting Pre section >> %windir%\apps.log

REM first part - get windows version

ver | find "Microsoft Windows 95" > nul

if not errorlevel 1 goto Win_95

ver | find "Microsoft Windows 98" > nul

if not errorlevel 1 goto Win_98

ver | find "Microsoft Windows NT" > nul

if not errorlevel 1 goto Win_NT

ver | find "Microsoft Windows 2000" > nul

if not errorlevel 1 goto Win_2000

ver | find "Microsoft Windows XP" > nul

if not errorlevel 1 goto win_xp

ver | find "5.2.3790" > nul

if not errorlevel 1 goto win_2k3

goto Unknown_OS

:win_95

set ostype=win95

goto part2

:win_98

set ostype=win98

goto part2

:win_nt

set ostype=winnt

goto part2

:win_2000

set ostype=win2k

goto part2

:win_xp

systeminfo | find "Microsoft Windows XP Professional" > nul

if not errorlevel 1 set ostype=winxppro

systeminfo | find "Microsoft Windows XP Home" > nul

if not errorlevel 1 set ostype=winxphome

goto part2

:win_2k3

set ostype=win2k3

goto part2

:Unknown_OS

set ostype=unknown

goto part2

REM Second part - see if server or workstation

:part2

echo OSType=%ostype% >> %windir%\apps.log

if not exist %windir%\system32\os.vbs goto Needscript

for /f "tokens=*" %%a in ('cscript //nologo "%windir%\system32\os.vbs"') do (

    set product_type=%%a)

goto middle

REM - if %product_type%==Workstation

REM - if %product_type%==Server goto Server

:Needscript

Echo You need os.vbs installed for this to work!

REM

REM Middle (installing software)

REM

:middle

echo Product_type=%product_type% >> %windir%\apps.log

CLS

ECHO Please wait as applications are installed.  This may take several minutes.

@echo.

ECHO Installing Norton Antivirus

start /min /wait %windir%\Apps\Norton\%product_type%.bat

ECHO Installing AOL Instant Messenger (AIM)

start /min /wait %windir%\Apps\AIM\silent.bat

ECHO Installing Winrar 3.20

start /min /wait %windir%\Apps\Winrar\silent.bat

ECHO Installing Windows Media Player (WMP) 9.0 Build 2980

start /min /wait %windir%\Apps\WMP9\%ostype%.bat

ECHO Installing DirectX 9.0b

start /min /wait %windir%\Apps\DX9\silent.bat

ECHO Installing Adobe Acrobat 6.0

start /min /wait %windir%\Apps\Adobe6\silent.bat

ECHO Installing Recovery console and making local source

start /min /wait %windir%\Source.bat

So 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


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

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

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" > nul

if not errorlevel 1 goto viafound

That'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

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...