Jump to content

Using Prnadmin.dll - VBScript to AutoIT help


Recommended Posts

Well I am having some minor trouble converting the follow VBScript code to AutoIT. No matter how I format the SERVER, PRINTER variables after "oMaster.PrinterDel" I get an error. I can get the Add printer code to work, just not the delete!

VBscript

CODE
set oMaster = CreateObject("PrintMaster.PrintMaster.1")

oMaster.PrinterDel ServerName, PrinterName

AutoIT Code... so far I have tried...

oMaster.PrinterDel $PRINTSERVER_NAME, $PRINTER_NAME

oMaster.PrinterDel($PRINTSERVER_NAME, $PRINTER_NAME)

oMaster.PrinterDel('"' & $PRINTSERVER_NAME & "," & '"' & $PRINTER_NAME & '"')

oMaster.PrinterDel '"' & $PRINTSERVER_NAME & "," & '"' & $PRINTER_NAME & '"'

oMaster.PrinterDel $PRINTSERVER_NAME & "," & $PRINTER_NAME

CODE
Func REMOVE_PRINT_QUEUE($PRINTSERVER_NAME, $PRINTER_NAME)

$P_OBJ_MASTER = ObjCreate("PrintMaster.PrintMaster.1")

$P_OBJ_MASTER.PrinterDel($PRINTSERVER_NAME, $PRINTER_NAME)

EndFunc

Any help would be appreciated. Thanks!

Hero's Dawn, an RPG Adventure completely coded in AutoITwmifunctions UDF, WMI UDF
Link to comment
Share on other sites

You might want to show the error you receive. :)

Also, what are you passing in for server and printer? If it is the local server you may want to try the keyword Default (not "Default", but Default) for the server name.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

CODE
set oMaster = CreateObject("PrintMaster.PrintMaster.1")

oMaster.PrinterDel ServerName, PrinterName

Assuming this works in VBS (does it?), you don't show how ServerName and PrinterName were defined in the VBS version.

:)

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

Assuming this works in VBS (does it?), you don't show how ServerName and PrinterName were defined in the VBS version.

:)

Sorry guys, I just assumed the Variable names were self explanitory. I am passing the Name of the server and Name of the printer (remotely) so the server variable would be "\\MYSERVER1" and Printer variable would be "PRINTER2".

I looked at how the add method worked and figured out that the VBScript code from Microxoft was incorrect (Whitepaper from MS "prnadmin.doc" comes with Toolkit) :D and here is what finally worked.

CODE
Func REMOVE_PRINT_QUEUE($PRINTSERVER_NAME, $PRINTER_NAME)

$P_OBJ_PRINTER.ServerName = "\\" & $PRINTSERVER_NAME

$P_OBJ_PRINTER.PrinterName = $PRINTER_NAME

$P_OBJ_MASTER.PrinterDel($P_OBJ_PRINTER)

$PRINTSERVER_NAME = ""

$PRINTER_NAME = ""

EndFunc

Hero's Dawn, an RPG Adventure completely coded in AutoITwmifunctions UDF, WMI UDF
Link to comment
Share on other sites

@all

just for the fun of it.

dim $oMaster
dim $oDriver

;The following code creates the required PrintMaster and Driver objects.
$oMaster = ObjCreate("PrintMaster.PrintMaster.1")
$oDriver = ObjCreate("Driver.Driver.1")

;The following code sets the driver name. It is required and the string cannot be empty.
$oDriver.ModelName = "HP LaserJet 4300 PCL6"

;The following code sets the driver processor. You must use either Intel or Itanium.
$oDriver.DriverArchitecture = "Intel"

;The following code specifies the operating system version for which the driver was written. If this setting is
;not configured, the caller's environment is used. You can use one of the following sets of values:
;"Windows 95, Windows 98, and Windows Millennium Edition"
;"Windows NT 4.0 or 2000"
;"Windows 2000, Windows XP and Windows Server 2003"
;"Windows XP and Windows Server 2003"
$odriver.DriverVersion = "Windows NT"

;The following code sets the driver cache. This setting is optional.
$oDriver.Path = "c:\temp"

;The following code sets the INF file. This setting is optional because if it is not set, the default directory,
;%windir%\inf\ntprint.inf, is used.
$oDriver.InfFile = "\\stmsr05\Support\Printers\Hp 4300 PCL6\hpc4300c.inf"

;The following code sets a server name to add a driver remotely. If you do not specify a ServerName, or if
;you use empty double quotes (""), the default, which adds a driver to the local computer, is used.
$oDriver.ServerName = ""

;The following code adds the driver.
$oMaster.DriverAdd ($oDriver)

;The following code uses the Err object to determine whether the driver was created successfully.
if @error <> 0 then
ConsoleWrite("An error occurred")
endif

regards,

ptrex

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...