Jump to content

Help Me Convert this VBS to AutoIT


CBHR4u
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Put parens around the parameters you are passing to the .Privileges.Add() method.

:mellow:

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
Link to comment
Share on other sites

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 by wraithdu
Link to comment
Share on other sites

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

:mellow:

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
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...