Boards.ie uses cookies. By continuing to browse this site you are agreeing to our use of cookies. Click here to find out more x
Post Reply  
 
Thread Tools Search this Thread
29-08-2005, 10:11   #1
davil
Registered User
 
davil's Avatar
 
Join Date: Dec 2002
Location: Drogheda
Posts: 337
Determine OS version in batch file

Hi everyone,
Apart from writing a program in basic myself that just does a ver into a text file and checks it, is there any easy way (a command-line utility) I can determine OS version from a script? And I'm not going to be using VBS because for the time being we have multiple service packs on different machines (I know I know I'll get it sorted) and some of them will not support so I need something that should run on any 98/NT/2K/XP system without any trouble.

Anyway, this would make my life as an admin a helluva lot easier. any help appreciated.

P.S. just in case I have to go the basic route, could anybody using 98 please post the output from the VER dos command in 98? Thanks in advance.
davil is offline  
Advertisement
29-08-2005, 10:16   #2
Mr E
Administrator
 
Mr E's Avatar
 
Join Date: Nov 2001
Posts: 28,894
A bit of googling found this:
Code:
@echo off 
::parse the VER command 
FOR /F "tokens=5*" %%G IN ('ver') DO SET v_version=%%G 
:: show the result 
echo %v_version%
(It had tokens=4*, but that just returned the word 'version', so I changed it to 5 to return the number). Also, I'm not sure how to get rid of the square bracket at the end....

Return full version string with:
Code:
@echo off 
::parse the VER command 
FOR /F "tokens=*" %%G IN ('ver') DO SET v_version=%%G 
:: show the result 
echo %v_version%

Last edited by Mr E; 29-08-2005 at 10:23.
Mr E is offline  
29-08-2005, 10:20   #3
Try1ng
Registered User
 
Join Date: May 2005
Location: Kildare
Posts: 110
Have you looked at Kix?
http://www.kixtart.org/

Heres a list of built in macros from kix:
_________________________________________
KiXtart Reference

Macro Reference

Macros can be used anywhere an expression is expected. Supported macros are defined in the following table.

Bold items are new to this release

Macro Definition
@Address Address of the network adapter
@Build Build number of the operating system
@Comment User comment (Description field in User Manager)
@CPU Name of the CPU (e.g.: "Intel Pentium III")
@CRLF Returns a carriage-return line-feed combination
@CSD CSD information (eg: "Service Pack 2")
@CurDir Current directory
@Date Date (in the format YYYY/MM/DD)
@Day Day of the week (Monday, Tuesday, etc.)
@Domain Domain or workgroup the computer belongs to
@DOS Version of Windows NT
@Error Return code of the most recent command or function. A return code of 0 means the command or function was successful. Any other value indicates an error.
@FullName Full name of current user
@HomeDir Short name of the directory part of home directory
@HomeDrive* Drive letter of drive containing home directory
@HomeShr Server and share name part of home directory
@HostName Fully qualified TCP/IP host name (including TCP/IP domain name)
@InWin Operating system: 1 = Windows NT; 2 = Windows 9x
@IPaddressX TCP/IP address (possible values for X are 0 - 3).
Note: Addresses are padded so that the resulting string always consists of four sets of three characters separated by periods. For example, if your IP address is 123.45.6.7, @IPADDRESS0 is "123. 45. 6. 7"
@KiX Version of KiXtart
@LanRoot Directory where network software resides (usually Systemroot\System32)
@LDomain* Logon domain
@LDrive Drive that is redirected to \\logonserver\NETLOGON
@LM Version of network software
@LogonMode If 1, indicates that KiXtart assumes to be running during the logon sequence
@LongHomeDir Long name of the directory part of home directory
@LServer Logon server
@MaxPWAge Maximum password age (Note: if passwords are set not to expire, this value is set to ((unsigned long)-1) (or 0xFFFFFFFF in hex). This evaluates to 4294967295 decimal).
@MDayNo Day of the month (1-31)
@MHz Approximation of the CPU speed (not available on Windows 9x)
@MonthNo Month number, beginning with January (1-12)
@Month Name of the month
@MSecs Milliseconds part of the current time
@PrimaryGroup* Current user's primary group
@Priv User's privilege level (GUEST, USER, ADMIN)
@ProductSuite OS Suite. Possible Values: 1 "Small Business"
2 "Enterprise"
4 "BackOffice"
8 "CommunicationServer"
16 "Terminal Server"
32 "Small Business (Restricted)"
64 "Embedded NT"
128 "DataCenter"
256 "Single User Terminal Server"
512 "Home Edition"
1024 "Blade Server"

@ProductType OS type. Possible values:
"Windows 95"
"Windows 98"
"Windows Me"
"Windows NT Workstation"
"Windows NT Server"
"Windows NT Domain Controller"
"Windows 2000 Professional"
"Windows 2000 Server"
"Windows 2000 Domain Controller"
"Windows XP Home Edition"
"Windows XP Professional"
"Windows .Net Server"
"Windows .Net Domain Controller"
@PWAge Password age
@RAS Number of active Remote Access Service (RAS) connections
@RServer* KXRPC server used for the current session
@ScriptDir Directory of current script
@ScriptName Name of the current script
@SError Error text corresponding with @ERROR
@SID* Current user's Windows NT Security Identifier (SID)
@Site** Name of the site in which the system resides
@StartDir Directory from which KiXtart was started
@SysLang Full English name of the language of the operating system specified in the format defined by ISO Standard 639. (example : “0413Dutch (Standard)”).
@Ticks Number of milliseconds elapsed since computer was last booted.
@Time Current time (in the format HH:MM:SS)
@UserID Current user's Windows NT user ID
@UserLang Full English name of the language selected by the current user specified in the format defined by ISO Standard 639. (example : “0413Dutch (Standard)”).
@WDayNo Days since Sunday (1 – 7)
@Wksta Computer name
@WUserID Current user's Windows user ID
@YDayNo Days since January 1 (1 – 365)
@Year Current year

--------------------------------------------------------------------------------

*Available on computers running Windows 9x only if the KiXtart RPC service is running.
**Only available on clients with full Active Directory support.

Note: During the logon sequence, @WUserID is empty on computers running Windows 9x if Windows NT Networking has been configured as the system's primary network provider.

The following examples show the correct use of KiXtart macros:

@LM
"2.10"

@DATE
"1997/10/03"

DISPLAY @USERID + ".TXT"
displays the file "RUUDV.TXT"

CD "\DATA\" + @DOMAIN
changes the current directory to "\DATA\your-domain"

_______________________________________________
Try1ng is offline  
29-08-2005, 10:23   #4
davil
Registered User
 
davil's Avatar
 
Join Date: Dec 2002
Location: Drogheda
Posts: 337
Thanks guys for your prompt responses. I'll look at kix now but as regards TMB's post I'm not looking for the version number, I'm looking for the Windows 2000 / Windows XP bit, but I can adapt your script to do the same. My knowledge of the if command aint amazin and I googled this myself and found sweet F.A.

Thanks again. Will report my findings.
davil is offline  
29-08-2005, 10:24   #5
Mr E
Administrator
 
Mr E's Avatar
 
Join Date: Nov 2001
Posts: 28,894
I modified my post to show out to output the full string.....
Mr E is offline  
Advertisement
29-08-2005, 10:25   #6
davil
Registered User
 
davil's Avatar
 
Join Date: Dec 2002
Location: Drogheda
Posts: 337
Thanks but as I said I could modify no problem.
davil is offline  
29-08-2005, 10:27   #7
Try1ng
Registered User
 
Join Date: May 2005
Location: Kildare
Posts: 110
Here's an example of how i use the product type in kix:
_________________________________________________
If @PRODUCTTYPE = "Windows XP Professional"
WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.kix","Application","kix32.exe","REG_SZ")
copy "@Lserver\NETLOGON\OtherSettings\*.*" "%SystemRoot%\system32\drivers\etc"
Copy "@Lserver\NETLOGON\OtherSettings\Wireless - Out of the Office.lnk" "C:\Documents and Settings\" + @userID + "\Desktop\*.*"
endif
Try1ng is offline  
29-08-2005, 10:29   #8
davil
Registered User
 
davil's Avatar
 
Join Date: Dec 2002
Location: Drogheda
Posts: 337
Ah this is good stuff lads. keep it coming.
davil is offline  
29-08-2005, 11:21   #9
davil
Registered User
 
davil's Avatar
 
Join Date: Dec 2002
Location: Drogheda
Posts: 337
Actually, the only problem is the Windows 98 Clients need to have a couple of DLLs installed so maybe to make it simple I might do something like this:

if exist KX16.DLL copy %LOGONSERVER%\NETLOGON\kix\98c\KX16.dll %windir%\system32
if exist KX32.DLL copy %LOGONSERVER%\NETLOGON\kix\98c\KX16.dll %windir%\system32
if exist KX95.DLL copy %LOGONSERVER%\NETLOGON\kix\98c\KX16.dll %windir%\system32


( LAST ONE IS ONLY IF i'M GOING TO BE USING THE RPC SERVICE )
davil is offline  
Advertisement
30-08-2005, 18:44   #10
Capt'n Midnight
00:00
 
Capt'n Midnight's Avatar
 
Join Date: Mar 2003
Posts: 45,285
IIRC find with a 0 errorlevel means that the substring is found

Ver | find "Version 4.0.950"
if not errorlevel 1 echo "Windows something"
Capt'n Midnight is offline  
31-08-2005, 15:28   #11
galactus
Registered User
 
galactus's Avatar
 
Join Date: Mar 2003
Location: Cork, boy!
Posts: 972
Sorry for butting in but Bill Stewart's Windows Admin Script Tools is worth a look.

...PS I am *not* Bill Stewart...
galactus is offline  
02-09-2005, 11:00   #12
davil
Registered User
 
davil's Avatar
 
Join Date: Dec 2002
Location: Drogheda
Posts: 337
Thanks
davil is offline  
Post Reply

Quick Reply
Message:
Remove Text Formatting
Bold
Italic
Underline

Insert Image
Wrap [QUOTE] tags around selected text
 
Decrease Size
Increase Size
Please sign up or log in to join the discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Share Tweet