Sign in to follow this  
Followers 0
CBHR4u

Help Me Convert this VBS to AutoIT

7 posts in this topic

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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

: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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by wraithdu

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0