Jump to content

Installing a printer with cscript in AutoIT


Recommended Posts

Hi all!

A few months ago I made a batch file to install printers for my enterprise and it's been working very well and I've decided to convert it over into AutoIT to make it a little nicer. The problem is, I'm having some trouble with some of the conversions.

Basically, the script checks to see if a printer driver directory exists on the machine and if not, copies over the drivers and windows built in VBS files to install them, asks the user the name of the print server, printer name, and model (xerox or HP) and gets to work installing. 

I've got almost all of that working except the last bit. My batch file used this line to install the driver: 

Cscript "C:\FAIS\Printers\Scripts\Prndrvr.vbs" -a -m "Xerox GPD PCL6 V3.5.404.8.0" -i "C:\FAIS\Printers\Drivers\Xerox Drivers\x2UNIVX.inf" -h "C:\FAIS\Printers\Drivers\Xerox Drivers" >nul

And this this line to attach the driver to the printer name and path

Cscript "C:\FAIS\Printers\Scripts\Prnmngr.vbs" -a -p "%PrinterName%" -m "Xerox GPD PCL6 V3.5.404.8.0" -r %PrinterPath% >nul

I thought this would be pretty simple, but something isn't working right, here's my best attempt at it using the tiny bit I know so far about AutoIT:

RunWait(@COMSPEC & 'cscript "C:\FAIS\Printers\Scripts\Prndrvr.vbs" -a -m "Xerox GPD PCL6 V3.5.404.8.0" -i "C:\FAIS\Printers\Drivers\Xerox Drivers\x2UNIVX.inf" -h "C:\FAIS\Printers\Drivers\Xerox Drivers" >nul')

RunWait(@COMSPEC & 'cscript "C:\FAIS\Printers\Scripts\Prnmngr.vbs" -a -p "'& $PrinterName & '" -m "Xerox GPD PCL6 V3.5.404.8.0" -r "'& $PrinterPath & '" >nul')

 

I don't know if it's relevant, but these are inside a function (Func XeroxInstall()) that gets called after identifying the model, and the variables $PrinterName and $PrinterPath are declared as global inside another earlier function.

Any help?

Link to comment
Share on other sites

And because I'm also too dumb to figure out how to (if possible) edit a post, I'll add here - when I run my script, it pops up asks for the print server and printer name and model like it should, then it just ends, almost like it's ignoring those two lines entirely.

Link to comment
Share on other sites

  • Developers

Try something like:

RunWait(@COMSPEC & ' /c cscript "C:\FAIS\Printers\Scripts\Prndrvr.vbs" -a -m "Xerox GPD PCL6 V3.5.404.8.0" -i "C:\FAIS\Printers\Drivers\Xerox Drivers\x2UNIVX.inf" -h "C:\FAIS\Printers\Drivers\Xerox Drivers"')

RunWait(@COMSPEC & ' /c cscript "C:\FAIS\Printers\Scripts\Prnmngr.vbs" -a -p "'& $PrinterName & '" -m "Xerox GPD PCL6 V3.5.404.8.0" -r "'& $PrinterPath & '"')

Change /c to /k in case there is an error

Jos

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

Link to comment
Share on other sites

Thanks for the response! 

So I tried what you suggested and it did pretty much the same thing, except it flashed the cmd prompt windows and shut down. As per your suggestion, I changed the c to a k and it's throwing up an error with each one - "Unable to add printer driver (long xerox driver name) Win32 error code 87" which I used to get a lot when I was building the batch file before I realized it needed to be elevated. Now, at the beginning of my code I did #RequireAdmin and assumed that would elevate everything inside - is that not correct? Do I need to elevate the cmd prompt line some how? The second line gives a different, longer error but I think it's because the driver wasn't installed with the previous line and this one is also not elevated.

Link to comment
Share on other sites

  • Developers
1 minute ago, lfernandes said:

Now, at the beginning of my code I did #RequireAdmin and assumed that would elevate everything inside - is that not correct?

Either way works:  Adding the #RequireAdmin will ensure the script is ran at elevated rights in case it isn't yet.

Jos

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

Link to comment
Share on other sites

  • Developers
55 minutes ago, lfernandes said:

even with that, the code isn't working. 

Thought it was. :)
So start simple: ensure you have the correct commandline by running it from an elevated CMD prompt.
Take that correct command and put that into the script with the #RequireAdmin and RunWait statements.
When it still doesn't work that post the working command and the script you translated that to so see we can find a reason.

Jos

Edited by Jos

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

Link to comment
Share on other sites

Ok! So with your help I figured out some of the issues!


The errors it was throwing wasn't related to admin rights, it was because the print spooler wasn't running. In my batch file, I had to stop and restart the print spooler to make it work, and in my AutoIT file I restarted it in the wrong place, causing the rest to fail. My original code was still wrong (and yours fixed that!) but so far so good now! Thanks for your help!

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