Support Forums

VBS Default Printing Failing

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.
User avatar
devereux0110
Posts: 36
Joined: Thu Aug 31, 2006 4:34 am

VBS Default Printing Failing

Postby devereux0110 » Sat Nov 05, 2016 1:27 pm

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
User avatar
jvierra
Posts: 10783
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: VBS Default Printing Failing

Postby jvierra » Sat Nov 05, 2016 2:10 pm

Try this:

Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "HP Printer"
User avatar
jazz albert
Posts: 16
Joined: Fri Nov 04, 2016 2:32 pm

Re: VBS Default Printing Failing

Postby jazz albert » Sat Nov 05, 2016 2:25 pm

jvierra wrote:Try this:

Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "HP Printer"


Would you please explain the insertion of this script with the help of visuals?
User avatar
jazz albert
Posts: 16
Joined: Fri Nov 04, 2016 2:32 pm

Re: VBS Default Printing Failing

Postby jazz albert » Sat Nov 05, 2016 2:26 pm

As a layman it is difficult to do so on my own!
User avatar
jvierra
Posts: 10783
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: VBS Default Printing Failing

Postby jvierra » Sat Nov 05, 2016 2:31 pm

Just put it in a file and run it. Use notepad or any other text editor.
User avatar
jazz albert
Posts: 16
Joined: Fri Nov 04, 2016 2:32 pm

Re: VBS Default Printing Failing

Postby jazz albert » Sat Nov 05, 2016 2:46 pm

Thank yo so much for your prompt response!
User avatar
devereux0110
Posts: 36
Joined: Thu Aug 31, 2006 4:34 am

Re: VBS Default Printing Failing

Postby devereux0110 » Sun Nov 06, 2016 10:27 am

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?
User avatar
devereux0110
Posts: 36
Joined: Thu Aug 31, 2006 4:34 am

Re: VBS Default Printing Failing

Postby devereux0110 » Mon Nov 07, 2016 12:45 am

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

Return to “VBScript”

Who is online

Users browsing this forum: No registered users and 1 guest