Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch Files 1

Status
Not open for further replies.

bobbytupper

IS-IT--Management
Joined
Feb 26, 2002
Messages
46
Location
GB
I want to create a batch file that can determine the version of the operating system. I dont want to use the %os% variable as it is same on Windows NT and Windows 2000.

I was thinking of outputting ver to c:\ver.txt and the using the contents of that file to determine the OS version.

I am stuck and any help would be muchly appreciated

Thanks

James
 
This should provide you with a starting point. I dont know what ver returns on NT4, so couldn't do that one.

****************************************************
@echo off
ver |FIND "Windows 2000" > nul
if not errorlevel=1 goto win2K

ver |FIND "Windows 9" > nul
if not errorlevel=1 goto win9x

echo Your operating system is not supported.
goto eof

:win2k
echo You are using win2k
goto eof

:win9x
echo You are using win9x
goto eof

:eof
****************************************************

<< JOC >>

 
Mate you are a star - I actually got around it by using if exist and referencing things like uniqe os files. This is what I really wanted to do though.

You you maybe explain in laymens terms what it is actually doing please.

Thanks again.

James
 
OK... all it does is takes the output of the &quot;ver&quot; command (which you have already found) and uses the output as the input to a FIND command. This is done using the pipe command |

The find command searches the input string for a match and sets errorcode to the return code of the FIND. As FIND normally prints the line that the match was found on I have used &quot;> nul&quot; to redirect the output to the nul device - basically just throws it away.

The IF statement checks to see what the previous line in the batch file set the errorcode to, and if it returned 0 executes the GOTO which jumps to the :win2k label. (this could be rewritten a number of ways i.e. if errorlevel 0 goto win2K - but I was always told to do it this way, and cant remember why!!!)

<< JOC >>
 
Brilliant - I did try and use the FIND command but couldnt figure out how to use the result ie if string not found set the error code. Obviously (now :) I wass missing the pipe. Thanks for your help Joc most kind!!

This is how I got around it and following using your method. I am using this to change proxy settings to point to a pac file and it works beautifully!

**********************************************************
My way;

@echo off
net use /d q:
net use q: \\wyg1\netlogon
cd q:
if exist &quot;c:\documents and settings&quot; goto windows2000chk
if exist &quot;c:\winnt&quot; goto nt
if exist &quot;c:\windows\defrag.exe&quot; goto 95

:windows2000chk
if &quot;%os%&quot;==&quot;Windows_NT&quot; goto windows2000

:windows2000
echo Your OS is win2k Configuring Proxy Settings
regedit.exe /s q:\NT5.reg
goto end

:nt
echo Your OS is Winnt Configuring Proxy Settings
regedit.exe /s q:\NT.reg
goto end

:95
echo your OS is Win95
Configuring Proxy Settings
regedit.exe /s q:\95.reg
goto end

:end
net use /d q:
*****************************************************

*****************************************************
Your way


@echo off
net use /d q:
net use q: \\wyg1\netlogon
cd q:

ver |FIND &quot;Windows 2000&quot; > nul
if not errorlevel=1 goto win2K

ver |FIND &quot;Windows XP&quot; > nul
if not errorlevel=1 goto win2k

ver |FIND &quot;Windows NT&quot; > nul
if not errorlevel=1 goto nt

ver |FIND &quot;Windows 9&quot; > nul
if not errorlevel=1 goto 9x



:win2k
echo Your OS is win2k Configuring Proxy Settings
regedit.exe /s q:\NT5.reg
goto end

:nt
echo Your OS is Winnt Configuring Proxy Settings
regedit.exe /s q:\NT.reg
goto end

:9x
echo your OS is Win95
Configuring Proxy Settings
regedit.exe /s q:\95.reg
goto end

:end
net use /d q:
******************************************************

Again thanks a million!!
 
You r welcome ...
Not much call for batch files these days - then 3 come along at once!! Had to clear out the cobwebs, haven't done any batch file stuff for years!

<< JOC >>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top