Jump to content
mithandir1

Help with Run @comspec with spaces.

Recommended Posts

mithandir1

This is part of script to help streamline printer installation in my office.  We have multiple printers that all use the same drivers.  The only only difference is the printers IP and a descriptive name.  The script is compiled and is in the parent directory(named PrinterInstaller) that contains subdirectories containing 32 and 64 bit dirvers.  I would like to make this folder "portable" so that it will run correctly no matter where on the hard drive it is placed.  Currently it must be placed on C:\.  If i replace "C:\PrinterInstaller"  with @scriptdir and "\"Windows gives me an error.  Also if the rename the folder Printer Installer(with a space) and change the script to match I get an error from windows.

Run(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /if /b "' & $name & '" /f C:\PrinterInstaller\' & $bit & '\oemsetup.inf /r "IP_' & $ip & '" /m "PCL6 Driver for Universal Print"', "", @SW_HIDE)

 

Edited by mithandir1

Share this post


Link to post
Share on other sites
javiwhite

Try putting this in your script, right above the run command, Then once the script exits, Paste whatever is on clipboard to notepad and debug whatever is being parsed to cmd.

ClipPut(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /if /b "' & $name & '" /f ' & @ScriptDir & '\PrinterInstaller\' & $bit & '\oemsetup.inf /r "IP_' & $ip & '" /m "PCL6 Driver for Universal Print"')

Cheers

Javi


give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Share this post


Link to post
Share on other sites
mithandir1

Well that was a good idea but  I get this: error: ClipPut() [built-in] called with wrong number of args.

Share this post


Link to post
Share on other sites
Jewtus

Easier way... ConsoleWrite the line and a @CRLF

ConsoleWrite(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /if /b "' & $name & '" /f ' & @ScriptDir & '\PrinterInstaller\' & $bit & '\oemsetup.inf /r "IP_' & $ip & '" /m "PCL6 Driver for Universal Print"'&@CRLF)

I use this when testing command line. I put a msg box up after the console write to validate the syntax first.

 

I'd also suggest Using ' instead of " to start your comspec... the reason I say that is " is required for most CMDs and ' wont work.

Edited by Jewtus
  • Like 1

Share this post


Link to post
Share on other sites
javiwhite

Mithandir1, Really? Because running the code exactly as it is in my previous comment works fine. Did you copy the code from my comment? Or wrap your run function in a ClipPut?

Copy the code in my previous comment and insert it.

Alternatively, you can use:

ClipPut('rundll32 printui.dll,PrintUIEntry /if /b "' & $name & '" /f ' & @ScriptDir & '\PrinterInstaller\' & $bit & '\oemsetup.inf /r "IP_' & $ip & '" /m "PCL6 Driver for Universal Print"')

and then paste directly into cmd and run.

ConsoleWrite will work as Jewtus suggested, I just prefer using the clipboard for debugging external code, as it means you can run the code to emulate the script, And identify where the external command is failing.

Neither way has a significant benefit over the other, It's just down to personal preference really.

Cheers 

Javi

  • Like 2

give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Share this post


Link to post
Share on other sites
mithandir1

Thanks guys. Now that I can see the command I think I have it figured out.  Quotation marks  are needed around the file location when there is a space.

Run(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /if /b "' & $name & '" /f "' & @ScriptDir & '\' & $bit & '\oemsetup.inf" /r "IP_' & $ip & '" /m "PCL6 Driver for Universal Print"', "", @SW_HIDE)

 

Edited by mithandir1

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

×