Solved

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

Posted on 2013-01-26
6
451 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 45

Expert Comment

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

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
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, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

13 Experts available now in Live!

Get 1:1 Help Now