CBHR4u Posted February 24, 2010 Posted February 24, 2010 I have this code that works perfectly as a VBS but when i try to convert it to AuoIt it doesn't. I don't get any error messages in AutoIt. Any help would be greatly appreciated! Thanks! Const wbemPrivilegeLoadDriver = 9 strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & _ strComputer & "\root\cimv2") objWMIService.Security_.Privileges.Add _ wbemPrivilegeLoadDriver, True Set objPrinter = objWMIService.Get _ ("Win32_Printer.DeviceID='Xerox ColorQube 9201 PS'") Set colDrivers = objPrinter.Associators_ _ ("Win32_DriverForDevice", "Win32_PrinterDriver") WScript.Echo objPrinter.DeviceID objPrinter.Delete_ For Each objDriver In colDrivers WScript.Echo objDriver.Name objDriver.Delete_ Next
dani Posted February 24, 2010 Posted February 24, 2010 It would help if you also show the Autoit code you created which does not give any errors, as you say.
CBHR4u Posted February 24, 2010 Author Posted February 24, 2010 It would help if you also show the Autoit code you created which does not give any errors, as you say. Sure thing, here you go. Thanks for any help. #RequireAdmin Const $wbemPrivilegeLoadDriver = 9 $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $oWMIService.Security_.Privileges.Add _ $wbemPrivilegeLoadDriver, True ObjCreate $objPrinter = $oWMIService.Get _ ("Win32_Printer.DeviceID='Xerox ColorQube 9201 PS'") ObjCreate $colDrivers = $objPrinter.Associators_ _ ("Win32_DriverForDevice", "Win32_PrinterDriver") $objPrinter.Delete_ For $objDriver In $colDrivers $objDriver.Delete_ Next
PsaltyDS Posted February 24, 2010 Posted February 24, 2010 Put parens around the parameters you are passing to the .Privileges.Add() method. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
CBHR4u Posted February 25, 2010 Author Posted February 25, 2010 Put parens around the parameters you are passing to the .Privileges.Add() method. I tried that and still no go, here is the updated code. Thanks for any help you can provide! #RequireAdmin Const $wbemPrivilegeLoadDriver = 9 $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $oWMIService.Security_.Privileges.Add _ ($wbemPrivilegeLoadDriver, True) ObjCreate $objPrinter = $oWMIService.Get _ ("Win32_Printer.DeviceID='Xerox ColorQube 9201 PS'") ObjCreate $colDrivers = $objPrinter.Associators_ _ ("Win32_DriverForDevice", "Win32_PrinterDriver") $objPrinter.Delete_ For $objDriver In $colDrivers $objDriver.Delete_ Next
wraithdu Posted February 25, 2010 Posted February 25, 2010 (edited) ObjCreate $objPrinter = $oWMIService.Get _ ("Win32_Printer.DeviceID='Xerox ColorQube 9201 PS'") ^^^^ Not quite right. Did you read the help file about using COM? $objPrinter = $oWMIService.Get("Win32_Printer.DeviceID='Xerox ColorQube 9201 PS'") Assuming your COM method call is correct... Edited February 25, 2010 by wraithdu
PsaltyDS Posted February 25, 2010 Posted February 25, 2010 Whoa, that code is much worse than I thought. Are you saying that VBScript in the OP actually works? To begin with, "Associators Of" is a query that you pass in, for example: colAssociations = objWMIService.ExecQuery _ ("Associators of {Win32_Share.Name='" & objShare.Name & "'} " _ & " Where AssocClass=Win32_ShareToDirectory") Which would look like this in AutoIt: $colAssociations = $objWMIService.ExecQuery("Associators of {Win32_Share.Name='" & $objShare.Name & "'} Where AssocClass=Win32_ShareToDirectory") Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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