We a basic VBS Script to add a printer and then set it as default.
Nothing special about the script and as Domain Admin Works perfectly.
However as a non domain admin, the script maps the printer and makes it available to the user for use with no problems but fails to set it as default.
What could stop the user from being able to execute the vbs to set the default print.
The user can go into devices and printers and set the printer default manually
As said, nothing special about the script, it works as administrator every time, it appears to be a permission issue but can't work out where or how.
Any suggestion's appreciated
VBS Default Printing Failing
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- jazz albert
- Posts: 16
- Last visit: Sat Nov 05, 2016 3:09 pm
Re: VBS Default Printing Failing
Would you please explain the insertion of this script with the help of visuals?jvierra wrote:Try this:
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "HP Printer"
- jazz albert
- Posts: 16
- Last visit: Sat Nov 05, 2016 3:09 pm
- jazz albert
- Posts: 16
- Last visit: Sat Nov 05, 2016 3:09 pm
- devereux0110
- Posts: 38
- Last visit: Mon Oct 02, 2017 7:11 am
Re: VBS Default Printing Failing
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "HP Printer"
is basically the script we have
not at work at moment but it is the above with the extra line to add the printer first the set it as default.
We know the script works as when run as Domain Administrator it works, it doesn't work when logged on as normal user.
The printer is added to the client no problem, it just doesn't get set as default, even tried adding a loop to check after 5 seconds what the default printer was and then if not the one we where trying to make default, run the line WSHNetwork.SetDefaultPrinter "HP Printer" again and again but script just loops as it never manages to successful set it as default.
The user can print to the printer by selecting the printer from the options available and is able to manually set the printer as default in devices and printers, the script just seems to fail to do the job, what could stop such a simple script working?
WSHNetwork.SetDefaultPrinter "HP Printer"
is basically the script we have
not at work at moment but it is the above with the extra line to add the printer first the set it as default.
We know the script works as when run as Domain Administrator it works, it doesn't work when logged on as normal user.
The printer is added to the client no problem, it just doesn't get set as default, even tried adding a loop to check after 5 seconds what the default printer was and then if not the one we where trying to make default, run the line WSHNetwork.SetDefaultPrinter "HP Printer" again and again but script just loops as it never manages to successful set it as default.
The user can print to the printer by selecting the printer from the options available and is able to manually set the printer as default in devices and printers, the script just seems to fail to do the job, what could stop such a simple script working?
- devereux0110
- Posts: 38
- Last visit: Mon Oct 02, 2017 7:11 am
Re: VBS Default Printing Failing
Hello All - Update
It turned out there was nothing wrong with the script, it is an issue with setting a default printer in a Citrix Session.
Reverted to using printui.dll to set the default printer instead of the .SetDefaultPrinter option
Script below which includes check to make sure default sets and runs command again if it fails first time, sometimes caused by timing where on slow machine your printer may not have finished installing when you try set it as default
Script below between lines
------------------------------------------------------------------------------------------------------------------------------
Set WS = CreateObject("Wscript.Shell")
Set net = CreateObject("WScript.Network")
originaldefaultprinter = ""
requireddefaultprinter = "\\ServerName\PrinterName"
strComputer = "."
net.AddWindowsPrinterConnection requireddefaultprinter
WScript.Sleep 5000
Do Until originaldefaultprinter = requireddefaultprinter
' net.SetDefaultPrinter requireddefaultprinter
WScript.Sleep 5000
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Default = TRUE")
For Each objPrinter in colPrinters
originaldefaultprinter = objPrinter.Name
Next
WS.run "RUNDLL32.EXE printui.dll,PrintUIEntry /y /n " & requireddefaultprinter
Loop
WScript.Quit
------------------------------------------------------------------------------------
It turned out there was nothing wrong with the script, it is an issue with setting a default printer in a Citrix Session.
Reverted to using printui.dll to set the default printer instead of the .SetDefaultPrinter option
Script below which includes check to make sure default sets and runs command again if it fails first time, sometimes caused by timing where on slow machine your printer may not have finished installing when you try set it as default
Script below between lines
------------------------------------------------------------------------------------------------------------------------------
Set WS = CreateObject("Wscript.Shell")
Set net = CreateObject("WScript.Network")
originaldefaultprinter = ""
requireddefaultprinter = "\\ServerName\PrinterName"
strComputer = "."
net.AddWindowsPrinterConnection requireddefaultprinter
WScript.Sleep 5000
Do Until originaldefaultprinter = requireddefaultprinter
' net.SetDefaultPrinter requireddefaultprinter
WScript.Sleep 5000
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Default = TRUE")
For Each objPrinter in colPrinters
originaldefaultprinter = objPrinter.Name
Next
WS.run "RUNDLL32.EXE printui.dll,PrintUIEntry /y /n " & requireddefaultprinter
Loop
WScript.Quit
------------------------------------------------------------------------------------