Jump to content

Script to add printers works in xp but not Win7


Recommended Posts

I've made a script for my company that allows me to choose a printer and install it remotely to a list of machines given by hostname or ip. It works perfectly when run from a Windows xp machine to install to xp machines, but when I run it from a Win7 machine, it doesn't add the port, driver, or printer to an xp machine. I hate having to keep an xp machine arund just to use this. I've copied the part of the code below that does the installs.

$mkport = "cscript /nologo %windir%\system32\prnport.vbs -a -s " & $hostname & " -r " & $PrintHostname & " -h  " & $PrintHostname & " -o raw -n 9100"
$installdriver = 'rundll32 printui.dll,PrintUIEntry /c\\' & $hostname & ' /ia /m "' & $PrintModel & '" /h "Intel" /v "Windows 2000 or XP" /u /f "' & $DriverPath & '"'
$addprinter = 'rundll32 printui.dll,PrintUIEntry /c\\' & $hostname & ' /if /b "' & $Friendlyname & '" /u /f "%windir%\inf\ntprint.inf" /r ' & $PrintHostname & ' /m "' & $PrintModel & '" /z'
$result1=RunAsWait($admin,  @ComputerName, $adminpw, 0, $mkport,-1, @sw_hide)
MsgBox(0,'1',$result1)
$result2=RunAsWait($admin,  @ComputerName, $adminpw, 0, $installdriver,-1, @sw_hide)
MsgBox(0,'2',$result2)
$result3=RunAsWait($admin,  @ComputerName, $adminpw, 0, $addprinter,-1, @sw_hide)
MsgBox(0,'3',$result3)

I've just temporarily added the $result msgboxes to see what's happening. When run from 7, they output '0', which means there was an error, but for the life of me, i don't know what. I've tried changing the logon flag to all 4 choices with no luck. I've also added #requireadmin with no luck.

Anyone out there smarter than me (not saying a lot!) able to help?

Link to comment
Share on other sites

  • 5 months later...

I check in systemdir, the file prnport.vbs doesnt exist. Maybe this is the reason why it fail...

Oh I got it, the file path is incorrect in Window 7,

Win 7:

cscript /nologo %windir%/System32\Printing_Admin_Scripts\en-USc/prnport.vbs

Win XP:

cscript /nologo %windir%\system32\prnport.vbs

Hope this helps, I can't try it here.

Edited by nfaustin
[font="Palatino Linotype"][size="2"]*** The information contained in this post should be considered and certified WORKS ON MY MACHINE ***[/size][/font][font="Palatino Linotype"][size="2"] [/size][/font]
Link to comment
Share on other sites

I've made a script for my company that allows me to choose a printer and install it remotely to a list of machines given by hostname or ip. It works perfectly when run from a Windows xp machine to install to xp machines, but when I run it from a Win7 machine, it doesn't add the port, driver, or printer to an xp machine. I hate having to keep an xp machine arund just to use this. I've copied the part of the code below that does the installs.

$mkport = "cscript /nologo %windir%\system32\prnport.vbs -a -s " & $hostname & " -r " & $PrintHostname & " -h  " & $PrintHostname & " -o raw -n 9100"
$installdriver = 'rundll32 printui.dll,PrintUIEntry /c\\' & $hostname & ' /ia /m "' & $PrintModel & '" /h "Intel" /v "Windows 2000 or XP" /u /f "' & $DriverPath & '"'
$addprinter = 'rundll32 printui.dll,PrintUIEntry /c\\' & $hostname & ' /if /b "' & $Friendlyname & '" /u /f "%windir%\inf\ntprint.inf" /r ' & $PrintHostname & ' /m "' & $PrintModel & '" /z'
$result1=RunAsWait($admin,  @ComputerName, $adminpw, 0, $mkport,-1, @sw_hide)
MsgBox(0,'1',$result1)
$result2=RunAsWait($admin,  @ComputerName, $adminpw, 0, $installdriver,-1, @sw_hide)
MsgBox(0,'2',$result2)
$result3=RunAsWait($admin,  @ComputerName, $adminpw, 0, $addprinter,-1, @sw_hide)
MsgBox(0,'3',$result3)

I've just temporarily added the $result msgboxes to see what's happening. When run from 7, they output '0', which means there was an error, but for the life of me, i don't know what. I've tried changing the logon flag to all 4 choices with no luck. I've also added #requireadmin with no luck.

Anyone out there smarter than me (not saying a lot!) able to help?

At our company, we use the following in a .bat (RunAsAdmin) on all machines and it seems to work just fine...maybe you can adapt it to your situation.

rundll32.exe printui.dll,PrintUIEntry /in /n "\\PrintServer\PrinterName"
rundll32.exe SHELL32.DLL, SHHelpShortcuts_RunDLL PrintersFolder

-Mike

Link to comment
Share on other sites

#RequireAdmin didn't help. And good catch on the vbs location; fixed that but it still doesn't work.

I can run the lines from the command line of Win7 and they work fine (filling in the variables with real info) but won't from AutoIT. I'm stumped. I've tried running the whole exe I made as admin(right-click, run as...) no luck there either.

I'll keep plugging away and if I ever get it, I'll be sure to post. Thanks for the replies. Keep 'em coming if anyone has any other ideas.

Link to comment
Share on other sites

  • 2 weeks later...

Just as a couple last thoughts...

If it's not already, add this line to your directives:

#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator

Also, are you compiling your Output arch to use x86 or x64? Try both/the other, just in case.

Lastly, it UAC enabled? IF so, disable, reboot and try again. Just a thought.

These are all little things that have helped me in the past.

Good luck!

-Mike

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