Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB Script to Check if the OS is Windows XP, if so then continue..

Posted on 2013-01-26
6
Medium Priority
?
461 Views
Last Modified: 2013-01-31
Experts,

I need a VB script that will do a Check to see if the OS is any version Windows XP. If so, then continue with the printer install portion of the script. If NOT, then close.

Here is my printer portion:

Set WshNetwork = CreateObject("WScript.Network")
On error resume next
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Commercial Invoice Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Commercial Laser Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Office BoxTag Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Office Invoice Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Office Laser Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Back Office Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\OfficeTag"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Retail Front Invoice Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Scheduling Color Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Scheduling Invoice Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Scheduling Laser Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Tempe Laser Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Warehouse Office Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Warehouse Reciever Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Office Management Laser Printer"
WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Front Desk Laser Printer"
WshNetwork.SetDefaultPrinter "\\az1svr1\Front Desk Laser Printer"
0
Comment
Question by:Glenn M
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38823321
Does the second example here help?
0
 
LVL 58

Accepted Solution

by:
Bill Prew earned 700 total points
ID: 38823354
Can't test this here, but this should work:

Set oShell = CreateObject("WScript.Shell")
If Instr(oShell.ExpandEnvironmentStrings("%OS%"), "XP") > 0 Then
   Set WshNetwork = CreateObject("WScript.Network")
   On error resume next
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Commercial Invoice Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Commercial Laser Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Office BoxTag Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Office Invoice Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Office Laser Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Back Office Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\OfficeTag"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Retail Front Invoice Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Scheduling Color Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Scheduling Invoice Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Scheduling Laser Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Tempe Laser Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Warehouse Office Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Warehouse Reciever Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Office Management Laser Printer"
   WshNetwork.AddWindowsPrinterConnection "\\az1svr1\Front Desk Laser Printer"
   WshNetwork.SetDefaultPrinter "\\az1svr1\Front Desk Laser Printer" 
End If

Open in new window

~bp
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 38823716
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:Glenn M
ID: 38824496
MartinLiss, I am not very Vb savy, so it doesn't help me. I actually need someone to write it for me. :)

billprew, it failed agaisnt the machine, I thing the WMI lookup isn't correct as it goes to zero.

RobSampson, I am trying to incorporate some of your previous solutions, I don't think I have it down yet.
0
 
LVL 2

Author Comment

by:Glenn M
ID: 38825147
OK,

I got it to work as long as the machine is XP, but ideally how can i get it to run a different part of the script of the wmi detects it is windows 7?

here is what I have so far:

strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select Caption From Win32_OperatingSystem")
 
For Each objItem in colItems
     strOS = objItem.Caption
Next
 
Set objShell = CreateObject("WScript.Shell")
If InStr(strOS, "XP") > 0 Then

Set WshNetwork = CreateObject("WScript.Network")
On error resume next
WshNetwork.AddWindowsPrinterConnection "\\AZPRINT\Tempe Office Laser"
WshNetwork.AddWindowsPrinterConnection "\\AZPRINT\TempeTag"
WshNetwork.AddWindowsPrinterConnection "\\AZPRINT\Tempe Fax Printer"
WshNetwork.AddWindowsPrinterConnection "\\AZPRINT\Tempe Color Printer"
WshNetwork.SetDefaultPrinter "\\AZPRINT\Tempe Fax Printer"

End If
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 700 total points
ID: 38826078
You can add other ElseIf statements per OS you need.  I have left a space for Windows 7 code below.

Regards,

Rob.

strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select Caption From Win32_OperatingSystem")
 
For Each objItem in colItems
     strOS = objItem.Caption
Next
 
Set objShell = CreateObject("WScript.Shell")
On error resume next
If InStr(strOS, "XP") > 0 Then

Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\AZPRINT\Tempe Office Laser"
WshNetwork.AddWindowsPrinterConnection "\\AZPRINT\TempeTag"
WshNetwork.AddWindowsPrinterConnection "\\AZPRINT\Tempe Fax Printer"
WshNetwork.AddWindowsPrinterConnection "\\AZPRINT\Tempe Color Printer"
WshNetwork.SetDefaultPrinter "\\AZPRINT\Tempe Fax Printer" 

ElseIf InStr(strOS, "7") > 0 Then
   ' put the Windows 7 code here

End If 

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question