VB script Error

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<div style="border:0px; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; margin:1em 2em 0px 4.8em; outline:0px; padding:0px; color:#333333; font-size:13px; line-height:16px; text-align:left
<div style="border:0px; font-style:inherit; font-family:inherit; margin:0px 0px 2em; outline:0px; padding:0px; clear:right; font-size:1em
<p style="border:none; font-style:inherit; font-family:inherit; margin-bottom:5px; outline:0px; padding-right:0px
i have a VB script for adding printer and when i want to run it i have this error:
<p style="border:none; font-style:inherit; font-family:inherit; margin-bottom:5px; outline:0px; padding-right:0px
could not map \192.168.1.149PRINTQUEUE [-2147023095]
<p style="border:none; font-style:inherit; font-family:inherit; margin-bottom:5px; outline:0px; padding-right:0px

<p style="border:none; font-style:inherit; font-family:inherit; margin-bottom:5px; outline:0px; padding-right:0px
my VB Script is this:
Option Explicit <br/>
<br/>
Tell WSH to resume on errors, otherwise our error handling cant do its job <br/>
On Error Resume Next <br/>
<br/>
Dim variables <br/>
Dim objNetwork, objWMIService, objPrinter <br/>
Dim colInstalledPrinters <br/>
Dim strPrinterServer, strPrinterShare, strComputerName <br/>
Dim Return, LocalDefault, PrinterIsInstalled <br/>
<br/>
######## Define Printer Configuration here ######### <br/>
<br/>
strPrinterServer = "\192.168.1.249" <br/>
strPrinterShare = "PRINTQUEUE" <br/>
<br/>
######## Code below does not need to be modified unless logical changes are needed ######## <br/>
<br/>
PrinterIsInstalled = False <br/>
We will only set this to true if we can find this printer in the list <br/>
strComputerName = "." This Computer <br/>
<br/>
Get WMIService so we can run WMI queries (good stuff) <br/>
Set objWMIService = GetObject( _ <br/>
"winmgmts:" & "{impersonationLevel=impersonate}!\" _ <br/>
& strComputerName & "rootcimv2") <br/>
<br/>
Run a WMI query to get all the objects belonging to the <br/>
Win32_Printer Class (all the installed printers) <br/>
Set colInstalledPrinters = objWMIService.ExecQuery _ <br/>
("Select * from Win32_Printer") <br/>
<br/>
The WMI query returns a collection (hence, the col prefix), <br/>
so we have to loop through the objects <br/>
For Each objPrinter in colInstalledPrinters <br/>
Now we have objects... printer objects to be exact... <br/>
Check to see if the current printer object is the default printer <br/>
If objPrinter.Default = "True" Then <br/>
We found the default printer, so lets see if its a Local printer <br/>
(but NOT that Image Writer doohickey) <br/>
If objPrinter.ServerName = Null And objPrinter.Name <> "Microsoft Office Document Image Writer" Then <br/>
User has a local Default Printer, so set LocalDefault to True <br/>
LocalDefault = True <br/>
Else <br/>
User has a Network Default Printer, so set LocalDefault to False <br/>
LocalDefault = False <br/>
End If <br/>
End If <br/>
<br/>
Lets figure out if this printer is installed already by <br/>
checking each printer object for a match <br/>
If objPrinter.ServerName = strPrinterServer And _ <br/>
objPrinter.ShareName = strPrinterShare Then <br/>
Printer is already installed, so set PrinterIsInstalled to True <br/>
PrinterIsInstalled = True <br/>
End If <br/>
Next <br/>
<br/>
If the Printer is not installed, install it. If its already installed, do nothing. <br/>
This also serves to allow users to choose a different default printer, as we only <br/>
update the default printer if this printer has not been installed before AND they <br/>
do not have a local default printer. <br/>
If Not PrinterIsInstalled Then <br/>
Printer is not installed, so install it <br/>
<br/>
Create the Network Object <br/>
Set objNetwork = CreateObject("WScript.Network") <br/>
<br/>
Create a new connection to the specified Printer Path <br/>
objNetwork.AddWindowsPrinterConnection strPrinterServer & "" & strPrinterShare <br/>
<br/>
Check to see if an error was logged <br/>
If err.Number <> 0 Then <br/>
An error was logged, display a nice error message indicating the error number <br/>
WScript.Echo "Could not map " & strPrinterServer & "" _ <br/>
& strPrinterShare & " [" & err.Number & "]" <br/>
Err.Clear <br/>
Else <br/>
No errors were logged, so check to see if we should make this printer the default printer <br/>
If Not LocalDefault Then <br/>
User does not have a local default printer, so make this the default printer <br/>
objNetwork.SetDefaultPrinter strPrinterServer & "" & strPrinterShare <br/>
End If <br/>
End If <br/>
Else <br/>
Printer is already installed, so do nothing <br/>
End If <br/>
<br/>
Good practice to clear the main objects, ESPECIALLY WMI provider objects <br/>
Set objWMIService = Nothing <br/>
Set objNetwork = Nothing <br/>
<br/>
WScript.Quit
<p style="border:none; font-style:inherit; font-family:inherit; margin-bottom:5px; outline:0px; padding-right:0px
<br/>
please help me


<div style="border:0px; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; margin:0px 0.25em 0px 0px; outline:0px; padding:0px; font-size:0.85em; text-align:right; color:#333333; line-height:16px
<hr class="sig alfONso

View the full article
 

Similar threads

D
Replies
0
Views
153
Drew1903
D
K
Replies
0
Views
224
Khan345
K
D
Replies
0
Views
104
Donald Uko
D
Back
Top