Solved

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

Posted on 2013-01-26
6
452 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
6 Comments
 
LVL 46

Expert Comment

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

Accepted Solution

by:
Bill Prew earned 175 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

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 1

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 175 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now