?
Solved

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

Posted on 2013-01-26
6
Medium Priority
?
460 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 48

Expert Comment

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

770 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