Furek86 Posted September 11, 2012 Share Posted September 11, 2012 Hi guys, I am having a problem with my script that maps printers at logon in my company. We run on windows 7 and when I try to map the printer silently as admin, all works perfectly. The issue occurs when I try to use my script when a non-admin account launches it and drivers need to be pulled from the print server. A window pops up asking if I want to install drivers and then windows is asking for admin credentials. My code is kind of elaborate cause I added a lot of logging and progress bar stuff around it, so I removed those lines and left only these that actually try to map the printer. Dim $WshNetwork $WshNetwork = ObjCreate("WScript.Network") $WshNetwork.AddWindowsPrinterConnection(\\printserver\printer01) Is it possible to suppress this behaviour and run windows printer mapping silently in Windows 7? Kuba Link to comment Share on other sites More sharing options...
rudi Posted September 14, 2012 Share Posted September 14, 2012 Hi.the locally logged on user has "Admin Rights"? I don't think so, as you wrote "... is asking for admin credentials" (if the user would have local admin rights, he/she would get a question like "would you like to allow ...")So my suggestion is to deploy these printers using GPOs (Group Policy Objects)Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Colyn1337 Posted September 14, 2012 Share Posted September 14, 2012 As part of a backup tool I once built I had to silently capture a users printers, including their default printer, and then readd them once they got their new computer. I'll share with you the two functions I used for this... Func PrinterRestore() Local $PrinterArray[1], $x, $File If FileExists($BrowseInputValue & "\printerlist.csv") Then $File = FileReadLine($BrowseInputValue & "\printerlist.csv") If Not $File = ("") Then _FileReadToArray($BrowseInputValue & "\printerlist.csv", $PrinterArray) For $x = 1 to 1 RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /in /n" & $PrinterArray[$x], "", @SW_HIDE) RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /y /n" & $PrinterArray[$x], "", @SW_HIDE) Next For $x = 2 to $PrinterArray[0] RunWait(@ComSpec & " /c " & "rundll32 printui.dll,PrintUIEntry /in /n" & $PrinterArray[$x], "", @SW_HIDE) Next EndIf EndIf EndFunc Func PrinterBackup() _FileCreate($BrowseInputValue & "\printerlist.csv") $csvfile = FileOpen($BrowseInputValue & "\printerlist.csv", 1) ; Pull default printer and write it to the first line of the file $objWMI = ObjGet("winmgmts:\\" & $Computer & "\root\CIMV2") $colPrinters = $objWMI.ExecQuery("SELECT * FROM Win32_Printer", "WQL", 0x10 + 0x20) If IsObj($colPrinters) Then For $objPrinter In $colPrinters If $objPrinter.Default = "True" And $objPrinter.Network = "-1" Then ConsoleWrite("Writing printer " & $objPrinter.Name & @CR) Sleep(500) FileWriteLine($csvfile, $objPrinter.Name & @CR) EndIf Next EndIf ; Then grab the rest of the printers, if any $objWMI = ObjGet("winmgmts:\\" & $Computer & "\root\CIMV2") $colPrinters = $objWMI.ExecQuery("SELECT * FROM Win32_Printer", "WQL", 0x10 + 0x20) If IsObj($colPrinters) Then For $objPrinter In $colPrinters If $objPrinter.Network = "-1" And $objPrinter.Default = ("") Then ConsoleWrite("Writing printer " & $objPrinter.Name & @CR) Sleep(500) FileWriteLine($csvfile, $objPrinter.Name & @CR) EndIf Next EndIf FileClose($csvfile) EndFunc Link to comment Share on other sites More sharing options...
rudi Posted September 18, 2012 Share Posted September 18, 2012 Hi. Q1: Do the users have admin or power user rights to the local Win7 installation? Q2: Does your script run in case you grant then one of these local group memberships? Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
gcue Posted September 18, 2012 Share Posted September 18, 2012 (edited) thanks for sharing but what about printer drivers? Edited September 18, 2012 by gcue Link to comment Share on other sites More sharing options...
Colyn1337 Posted September 18, 2012 Share Posted September 18, 2012 (edited) Hi.Q1: Do the users have admin or power user rights to the local Win7 installation?Q2: Does your script run in case you grant then one of these local group memberships?Regards, Rudi.@Rudi,By default "EVERYONE" has read access to WMI. As there are no methods being called, there should be no problems using that script for restricted users. In our shop, most of our users operate in the "users" group and there were no reported problems. thanks for sharing but what about printer drivers?@gcue,We run 2008 R2 print servers and this script was designed for network printers (can be configured for local tho). As such, when the restore function is run, the computer reaches out to the print server and automatically installs the drivers.Think of it this way, it's the exact same computer process as manually clicking thru the add a network printer option. It's just done without the GUI and talks directly to the DLL.EDIT:I should really drop that code in the Example Scripts section....... Edited September 18, 2012 by Colyn1337 Link to comment Share on other sites More sharing options...
rudi Posted September 21, 2012 Share Posted September 21, 2012 Hi. Adding a printer means adding a printer driver -> poweruser / admin is required, if the *USER* invokes this action. Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
StringingLong Posted September 21, 2012 Share Posted September 21, 2012 Try: #RequireAdmin at the top of your script. See if that solves the non-admin problem. Link to comment Share on other sites More sharing options...
rudi Posted September 21, 2012 Share Posted September 21, 2012 If I got him correctly, the users are just "user", by that they will be popped up to enter admin credetials (which they propably don't have) Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Colyn1337 Posted September 21, 2012 Share Posted September 21, 2012 If I got him correctly, the users are just "user", by that they will be popped up to enter admin credetials (which they propably don't have)Regards, Rudi.In our environment this does not occur.... Just sayin. Link to comment Share on other sites More sharing options...
rudi Posted October 4, 2012 Share Posted October 4, 2012 Hi. then in your environment the users are at least "poweruser", or the printers are pushed down from the print server (GPO or whatoever) Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Colyn1337 Posted October 4, 2012 Share Posted October 4, 2012 Hi.then in your environment the users are at least "poweruser", or the printers are pushed down from the print server (GPO or whatoever)Regards, Rudi.Nope, they're not poweruser's..... they're just regular bare bones users. We don't push pinters by GPO, but as stated before, we have print servers. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now