gshaw Posted July 7, 2009 Posted July 7, 2009 Been trying to do this for ages now and it's driving me nuts! Basically we've got an old 16-bit app that can only print to a local IP printer... which needs admin rights to map. I've got a VBS script I found to do it and want to use AutoIt to run the VBS with elevated rights and then compile to an EXE to hide the credentials. Found this... RunAs("USERNAME", "DOMAIN", "PASSWORD", 0, 'wscript.exe "' & @ScriptDir & '\print.vbs"') But when compiled and run I get wscript access denied error?! The wscript process is running as the admin account I put in the gaps above so what's going on?
Developers Jos Posted July 7, 2009 Developers Posted July 7, 2009 What is the WorkDir at the time you run this? Try setting it to a directory that you are sure of is accessible for the account used in the RunAs() command. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
gshaw Posted July 7, 2009 Author Posted July 7, 2009 The directory should definitely be accessible, tried it with a high level account that should be able to access all areas! The script fails at line 25, where it starts to try and add the port so it seems somehow the script isn't getting the admin privileges even though the wscript is?
spudw2k Posted July 7, 2009 Posted July 7, 2009 The directory should definitely be accessible, tried it with a high level account that should be able to access all areas! The script fails at line 25, where it starts to try and add the port so it seems somehow the script isn't getting the admin privileges even though the wscript is?Does this make a difference? RunAs("USERNAME", "DOMAIN", "PASSWORD", 0, @comspec & ' /c ' & @WindowsDir & '\system32\wscript.exe "' & @ScriptDir & '\print.vbs"') Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
gshaw Posted July 8, 2009 Author Posted July 8, 2009 Does this make a difference? RunAs("USERNAME", "DOMAIN", "PASSWORD", 0, @comspec & ' /c ' & @WindowsDir & '\system32\wscript.exe "' & @ScriptDir & '\print.vbs"') Just gave it a go but only saw a brief flicker of a CMD window pop up and then disappear?
jinxter Posted July 8, 2009 Posted July 8, 2009 Try to use the /k switch to let the command window 'stay' after execution. RunAs("USERNAME", "DOMAIN", "PASSWORD", 0, @comspec & ' /k ' & @WindowsDir & 'system32wscript.exe "' & @ScriptDir & 'print.vbs"') > there are 10 types of people in the world, those who understand binary and those who don't.
gshaw Posted July 8, 2009 Author Posted July 8, 2009 (edited) Just gave it a go but only saw a brief flicker of a CMD window pop up and then disappear? Edit: just found why that didn't work... forum removed all the slashes from the path! Got it working but still received the same error when the script tried to run... access denied on line 25 For reference here's the vbscript it's trying to run... My guess is that somewhere in the vbscript it's using the credentials of the currently logged-on user rather than the one that called the script i.e. the autoit RunAs user? expandcollapse popupPrnName = "StudyScan Printer" PrnLocation = "Reception" PrnComment = "Printer for StudyScan software" PrnDrv = "HP LaserJet 4" DrvPath = "C:\WINDOWS\system32\spool\drivers\w32x86\3" InfPath = DrvPath & "\UNIDRV.DLL" PortIP = "10.10.10.10" PortName = "IP_" & PortIP strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") '''''''''''''''''''''''''' ' create ip-printer-port '''''''''''''''''''''''''' Set objNewPort = objWMIService.Get _ ("Win32_TCPIPPrinterPort").SpawnInstance_ objNewPort.Name = PortName objNewPort.Protocol = 1 objNewPort.HostAddress = PortIP objNewPort.PortNumber = "9100" objNewPort.SNMPEnabled = False objNewPort.Put_ ' wsh.echo "port created" '''''''''''''''''''''''''' ' install printer driver '''''''''''''''''''''''''' ' If the driver is not signed, one cannot use WMI scripting ' to install the driver. ' Make sure the cat file for the package is copied to the same ' location as the driver objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True Set objDriver = objWMIService.Get("Win32_PrinterDriver") objDriver.Name = PrnDrv objDriver.SupportedPlatform = "Windows NT x86" objDriver.Version = "3" objDriver.DriverPath = DrvPath objDriver.Infname = InfPath intResult = objDriver.AddPrinterDriver(objDriver) ' wsh.echo "driver installed" '''''''''''''''''''''''''' ' Add local printer '''''''''''''''''''''''''' Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_ objPrinter.DriverName = PrnDrv objPrinter.PortName = PortName objPrinter.DeviceID = PrnName objPrinter.Location = PrnLocation objPrinter.Comment = PrnComment objPrinter.Network = True objPrinter.Put_ ' wsh.echo "printer added" Edited July 8, 2009 by gshaw
Juvigy Posted July 8, 2009 Posted July 8, 2009 The VBS script uses WMI . On which operating system do you run it? Also if you log in with an admin account and run the script does it work?
dot45 Posted July 8, 2009 Posted July 8, 2009 (edited) The VBS script uses WMI . On which operating system do you run it?Also if you log in with an admin account and run the script does it work?Log onto the computer with the local administrator account, then try to run the script. there is a convertor for vbs to autoit that i have used. I scripted the printmig.exe tool that Microsoft created. Its in the example forum. http://www.autoitscr...=1&#entry698665I found that while you can use RunAs, its better if you dont have to.You could use my tool, and create the printer on one computer, then backup the printer configuration using the tool. You can then hard code the tool to restore that file to any pc you run it on. You need to run the tool using an account with local admin rights. We dont allow local accounts to have any network access in our environment, so i have it mapping the network drive where the files sit using an account that only has access to that share. Edited July 8, 2009 by dot45 Tools I've Created & Shared[/url][url="http://www.autoitscript.com/forum/index.php?showtopic=97177&st=0&p=698665&hl=printer&fromsearch=1&#entry698665"]Printer Migration Tool
Venom007 Posted July 8, 2009 Posted July 8, 2009 Been trying to do this for ages now and it's driving me nuts!Basically we've got an old 16-bit app that can only print to a local IP printer... which needs admin rights to map. I've got a VBS script I found to do it and want to use AutoIt to run the VBS with elevated rights and then compile to an EXE to hide the credentials.Found this...RunAs("USERNAME", "DOMAIN", "PASSWORD", 0, 'wscript.exe "' & @ScriptDir & '\print.vbs"')But when compiled and run I get wscript access denied error?! The wscript process is running as the admin account I put in the gaps above so what's going on?Don't you think it will help to try and convert the VBS script to AutoIt Script. Just asking. I don't use vb scripts anymore. I converted all my scripts to AutoIt.
gshaw Posted July 10, 2009 Author Posted July 10, 2009 Don't you think it will help to try and convert the VBS script to AutoIt Script. Just asking. I don't use vb scripts anymore. I converted all my scripts to AutoIt.Tried to do that but the converter failed so went for other avenues...In the end I found "rundll printui.dll" from a batch file did the trick... called it from AutoIt using RunAs and it did the job perfectly Also had to code in a VBS popup box to act as a splash screen while the driver installation was going on but eventually it's all doing what it's meant to and solves the problem so result!Thanks for the advice and info
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