Solved

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

Posted on 2013-01-26
6
458 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 55

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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