Sign in to follow this  
Followers 0
rchamberlin

Determining Windows Version?

8 posts in this topic

I'm pretty new to Autoit, but I'm writing a script to do an automated install of a program. The problem is I only want it to install on Windows 2000/XP and not Windows NT.

I did a search on these forums, but didn't really find anything. What I'd like to do is basically

If Winver = NT Then
Exit
Else
Run Script...
Exit

Any ideas? Thanks for any help. I would assume this has to have come up before.

Share this post


Link to post
Share on other sites



AutoIt3 has these Macros defined (Cut&Paste from the helpfile):

@OSType

Returns "WIN32_NT" for NT/2000/XP and returns "WIN32_WINDOWS" for 95/98/Me

@OSVersion

Returns one of the following: WIN_XP, WIN_2000, WIN_NT4, WIN_ME, WIN_98, WIN_95

@OSBuild

Returns the OS build number. For example, Windows 2003 Server returns 3790

@OSServicePack

Service pack info in the form of "Service Pack 3" or, for Windows 95, it may return "B"

So in your code you can refer to them with something like:

If @OSTYPE = "WIN32_NT" then
  ; run your pgm 
EndIF

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Searching the helpfile would of been a better choice than the forum. Straight from the help file:

@OSType

Returns "WIN32_NT" for NT/2000/XP and returns "WIN32_WINDOWS" for 95/98/Me

@OSVersion

Returns one of the following: WIN_XP, WIN_2000, WIN_NT4, WIN_ME, WIN_98, WIN_95

@OSBuild

Returns the OS build number. For example, Windows 2003 Server returns 3790

@OSServicePack

Service pack info in the form of "Service Pack 3" or, for Windows 95, it may return "B"

Share this post


Link to post
Share on other sites

So I'm not the only one to start an answer just to find out that somebody has beaten me to it :whistle:


GrahamS

Share this post


Link to post
Share on other sites

rchamberlin,

If I understand your post correctly, you want to install ONLY to Windows 2000 or Windows XP? And specifically NOT to Windows NT 4.0? The following code should be of some help, I also added code to filter out the Windows 9x & ME Clients as well.

$OS = @OSVersion
$OSVer = @OSType

If $OSVer <> 'Win32_NT' Then; Filters out Windows 9x & ME clients
    Exit
EndIf
If $OS = 'Win_NT' Then; Filters out Windows NT 4.0
  MsgBox(0, "Operating System", "Incorrect Operating System - Windows XP or 2000 Required")
  Exit (0)
EndIf
MsgBox(0, "Operating System", "Running Windows 2000 or XP")

I tested it quickly on my own XP machine and it seemed to work as expected. I hope it helps.

Z/K

Share this post


Link to post
Share on other sites

rchamberlin,

  If I understand your post correctly, you want to install ONLY to Windows 2000 or Windows XP? And specifically NOT to Windows NT 4.0? The following code should be of some help, I also added code to filter out the Windows 9x & ME Clients as well.

$OS = @OSVersion
$OSVer = @OSType

If $OSVer <> 'Win32_NT' Then; Filters out Windows 9x & ME clients
    Exit
EndIf
If $OS = 'Win_NT' Then; Filters out Windows NT 4.0
  MsgBox(0, "Operating System", "Incorrect Operating System - Windows XP or 2000 Required")
  Exit (0)
EndIf
MsgBox(0, "Operating System", "Running Windows 2000 or XP")

I tested it quickly on my own XP machine and it seemed to work as expected. I hope it helps.

Z/K

If $OS = 'Win_NT' Then; Filters out Windows NT 4.0

should be

If $OS = 'Win_NT4' Then; Filters out Windows NT 4.0

Can I suggest you rename your variable $OS and $OSVer or you use directly the @.. It is a little confusing the way you define them. :whistle:

Share this post


Link to post
Share on other sites

DOH!!!! :whistle:

JPM, you are absolutely correct!! Thats what I get for being hasty (and not having enough sleep...). Below is the 'cleaned up' code:

If @OSType <> 'Win32_NT' Then; Filters out Windows 9x & ME clients
    Exit
EndIf
If @OSVersion = 'Win_NT4' Then; Filters out Windows NT 4.0
  MsgBox(0, "Operating System", "Incorrect Operating System - Windows XP or 2000 Required")
  Exit (0)
EndIf
MsgBox(0, "Operating System", "Running Windows 2000 or XP")

Thanks again for the callout, I hate passing along faulty script

Z/K

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Another way to skin the proverbial cat:

If (@OSType <> "Win32_NT") Or (@OSVersion = "Win_NT4") Then
  MsgBox(4096,"Error", "Incorrect OS; Win XP or 2000 required")
   Exit(1)
EndIf

MsgBox(0, "Note", "Proceeding with installation...")

By the way, you could also do something like this:

If StringInStr("Win_2000;Win_XP", @OSVersion) Then MsgBox(0,"","Correct OS")

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
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
Sign in to follow this  
Followers 0