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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

test if the operating system is XP and run a script IF NOT run the other script

Status
Not open for further replies.

kjani

IS-IT--Management
Nov 1, 2012
8
US
I am a novice with vbscripting but have a desperate need for a script to do the following (EXTREMELY SIMILAR to the thread "Find if OS is x86 or x64 then Windows 7 or XP and run msi">

HOWEVER, all I need to do is test if the operating system is XP or NOT...and run a script

if XP I need to run
netswitchXP.vbs
ELSE
run netswitch.vbs

that is it.

I tried to modify the following (Ie...what am I doing wrong with this?)

strComputer = "."
Dim objWMI:Set objWMI = GetObject("winmgmts://" & strComputer & "\root\cimv2")

Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem", , 48)

For Each objItem in colItems
OSVersion = objItem.Caption
Next

Select Case OSVersion
Case "Microsoft Windows XP Professional"
cscript.exe netswitchXP.vbs, True
Case Else
cscript.exe netswitch.vbs
End Select


HELP please ~ and thank you so much...
 
A starting point:
Code:
Select Case OSVersion
Case "Microsoft Windows XP Professional"
   strProg = "netswitchXP.vbs"
Case Else
   strProg = "netswitch.vbs"
End Select
CreateObject("WScript.Shell").Run "cscript.exe " & strProg, 1, True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK - I need to put the following 'variables' after each netswitchXP.vbs OR netswitch.vbs commands

cscript.exe netswitchXP.vbs "Local Area Connection" "Wireless Network Connection"

or

cscript.exe netswitch.vbs "Local Area Connection" "Wireless Network Connection"

is that possible?
 
CreateObject("WScript.Shell").Run "cscript.exe " & strProg & " ""Local Area Connection"" ""Wireless Network Connection""", 1, True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK I tried running it and it looks like it works but does not really work? the screen flies by so fast -

I can run my netswitchXP.vbs script in a dos window with

cscript.exe netswitchXP.vbs "Local Area Connection" "Wireless Network Connection"

and IT WORKS.

but when I use the script (which I have garnered from the stuff above - it doesn't work and I cannot tell what is wrong?

Select Case OSVersion
Case "Microsoft Windows XP Professional"
strProg = "netswitchXP.vbs"
Case Else
strProg = "netswitch.vbs"
End Select
CreateObject("WScript.Shell").Run "cscript.exe " & strProg & " ""Local Area Connection"" ""Wireless Network Connection""", 1, True
 
I'd use the full pathname of netswitchXP.vbs

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I did it did not help. It runs fine...but does not do the netswitchXP.vbs

basically I need to TURN OFF the wireless network card on any computer regardless of O.S. IF the user has a WIRED CONNECTION. so that they cannot have a simultaneous connection of both wired and wireless.
the netswitchxp.vbs and netswitch.vbs scripts do this...but how do I make sure I run the right one for the right o.s.?

hence I wanted to test if it was xp then run this if it is a higher level system run the other one.

the script above is not working that way yet...I can take the vbs scripts and run them via a *.bat file with the

cscript.exe netswitchxp.vbs "Local Area Connection" "Wireless Network Connection"

and get it to do it (I can watch it turn off the wireless card.

Perhaps there is a better script that someone has than what i am trying to do?
 
how do I make sure I run the right one
Code:
MsgBox "OSVersion='" & OSVersion & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Well that gave me a result of OsVersion="

so that does not work

this is the code...what is WRONG?
Select Case OSVersion
Case "Microsoft Windows XP Professional"
strProg = "netswitchXP.vbs"
Case Else
strProg = "netswitch.vbs"
End Select
CreateObject("WScript.Shell").Run "cscript.exe " & strProg & " ""Local Area Connection"" ""Wireless Network Connection""", 1, True

MsgBox "OSVersion='" & OSVersion & "'"
 
Then OSVersion = "". The code is not wrong. Based on what you've posted above, it's just incomplete. You should be able to combine what you have learned in this thread with what you originally produced to come up with:

Code:
Set objWMI = GetObject("winmgmts://.\root\cimv2") 
Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem", , 48)

For Each objItem in colItems
   OSVersion = objItem.Caption
Next

Select Case OSVersion
   Case "Microsoft Windows XP Professional"
      strProg = "netswitchXP.vbs"
   Case Else
      strProg = "netswitch.vbs"
End Select

CreateObject("WScript.Shell").Run "cscript.exe " & strProg & " ""Local Area Connection"" ""Wireless Network Connection""", 1, True

-Geates

 
thank you MUCH APPRECIATION

THIS WAS INCORRECT

MsgBox "OSVersion='" & OSVersion & "'"

if I took the "OSVersion='" and got rid of the ' then the result was OSVersion='
then I took away the "'" and put just "" and got a blank

so I started experimenting...basically it did not return an OSVERSION value...it returned errors.

I am sorry I do not know more but I am learning. I misunderstood about the code and did not know I needed the whole thing.

Truly appreciate that you posted what you did and it appeared to work...NOW I only need to incorporate this scribt into a login script on the server for group policy...having some trouble getting it to push this to the computer logging in...
but I thank you truly for clarifying the code for me

thanks a bunch
 
THIS WAS INCORRECT ... MsgBox "OSVersion='" & OSVersion & "'"

From what I see, this is very correct. If OSVersion was equal to something, you would have seen [tt]OSVersion='something'[/tt]. But because OSVersion was nothing, you saw exactly what one would expect, [tt]OSVersion=''[/tt].

In my experience, GPO can be a bit shaky. Instead of pushing a login script via GPO, we push ours by populating the AD account property "logon script:"

-Geates


 
thank you so much

MAKES TOTAL SENSE...
and you are correct...the GPO was VERY shaky it didn't do anything. I think I will try the way you said AD account

also yes I see what you mean - the value was no good because I did not have the correct script.

da huh LOL sorry :)

MUCH APPRECIATON TO ALL...
K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top