Sign in to follow this  
Followers 0
polara

How to detect if Win XP is running

11 posts in this topic

I am building a script to run a Robocopy backup of user data on Vista workstations. Since the data locations are different in Vista, I need to confirm that the script is running only on Vista machines. Can anyone help with some code to:

1. Detect if the OS is Win XP.

2. If yes, pop up a warning window and a button to close the script.

3. If no, continue script.

Thanks.

Share this post


Link to post
Share on other sites



@OSVersion :)

Share this post


Link to post
Share on other sites

Maybe...

; @OSVersion
; Returns one of the following: "WIN_VISTA", "WIN_2003", "WIN_XP", "WIN_2000", "WIN_NT4", "WIN_ME", "WIN_98", "WIN_95"
 
 If @OSVersion = "WIN_XP" Then MsgBox(0x0, "WIN_XP", "Do this....    ")
 
 If @OSVersion = "WIN_VISTA" Then MsgBox(0x0, "WIN_VISTA", "Do this....    ")

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Maybe...

; @OSVersion
; Returns one of the following: "WIN_VISTA", "WIN_2003", "WIN_XP", "WIN_2000", "WIN_NT4", "WIN_ME", "WIN_98", "WIN_95"
 
 If @OSVersion = "WIN_XP" Then MsgBox(0x0, "WIN_XP", "Do this....    ")
 
 If @OSVersion = "WIN_VISTA" Then MsgBox(0x0, "WIN_VISTA", "Do this....    ")

8)

This looks good and it does check the OS. However, 2 Things:

1. I probably don't need the If @OSVersion = "WIN_VISTA" line since I only care if it's XP. I assume I can just remove this?

2. If it is XP, what do I need to add to - If @OSVersion = "WIN_XP" Then MsgBox(0x0, "WIN_XP", "Do this.... ") - to halt the script with a "close" button?

Thanks again.

Share this post


Link to post
Share on other sites

If @OSVersion <> "Win_Vista" Then
   MsgBox(0x0, "Error", "This application will not run on your version of Windows" & @CRLF & "The application will now close.")
   Exit
EndIf


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

If @OSVersion <> "Win_Vista" Then
   MsgBox(0x0, "Error", "This application will not run on your version of Windows" & @CRLF & "The application will now close.")
   Exit
EndIf
Running this in XP or Vista produces the error:

EndIf

Error:"EndIf" statement with no matching "If" statement.

Share this post


Link to post
Share on other sites

Running this in XP or Vista produces the error:

EndIf

Error:"EndIf" statement with no matching "If" statement.

No, it doesn't...

Share this post


Link to post
Share on other sites

No, it doesn't...

Hmm.. Maybe the problem is what I have following this. Here's my entire script:

; ----------------------------------------------------------------------------

;

; AutoIt Version: 3.1.0

; Author:

;

; Script Function: ; Robocopy backup for Vista users

;

; ----------------------------------------------------------------------------

; Robocopy Backup - For Vista Only v1.1 12-10-2007

; @OSVersion

; Returns one of the following: "WIN_VISTA", "WIN_2003", "WIN_XP", "WIN_2000", "WIN_NT4", "WIN_ME", "WIN_98", "WIN_95"

If @OSVersion <> "Win_Vista" Then MsgBox(0x0, "Error", "This backup is for Vista only. Please run the Win XP backup" & @CRLF & "The application will now close.")

Exit

EndIf

$ol = ObjGet("", "outlook.Application")

If @error Then

$ol = ObjCreate("outlook.Application")

;no outlook to grab onto

EndIf

$update = MsgBox(1, "Backup", "Backup needs to close Outlook before it can run. Click Ok to continue or Cancel if you do not want to close Outlook at this time.")

If $update = 2 Then

MsgBox(0, "Backup", "Backup has been canceled.")

Exit

EndIf

$ol.quit

;EndIf

RunWait("\\myserver\share\Scripts\dbu_Vista.cmd")

MsgBox(0, "Backup", "Backup has finished. Please remember to run backup regularly.")

;This errors if Outlook is already closed

Share this post


Link to post
Share on other sites

Here's your problem:

If @OSVersion <> "Win_Vista" Then MsgBox(0x0, "Error", "This backup is for Vista only. Please run the Win XP backup" & @CRLF & "The application will now close.")
Exit
EndIf

If you do If <condition> then <code>, you don't need the Endif cos you did it in one line.

This is how that should be:

If @OSVersion <> "Win_Vista" Then
 MsgBox(0x0, "Error", "This backup is for Vista only. Please run the Win XP backup" & @CRLF & "The application will now close.")
Exit
EndIf

Share this post


Link to post
Share on other sites

Here's your problem:

If @OSVersion <> "Win_Vista" Then MsgBox(0x0, "Error", "This backup is for Vista only. Please run the Win XP backup" & @CRLF & "The application will now close.")
Exit
EndIf

If you do If <condition> then <code>, you don't need the Endif cos you did it in one line.

This is how that should be:

If @OSVersion <> "Win_Vista" Then
 MsgBox(0x0, "Error", "This backup is for Vista only. Please run the Win XP backup" & @CRLF & "The application will now close.")
Exit
EndIf
Wow! What a difference a CR makes. Thanks for your patience and help. You are awesome.....

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