Sign in to follow this  
Followers 0
grunewald6

Script to add printers works in xp but not Win7

8 posts in this topic

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?

Share this post


Link to post
Share on other sites



No takers?

Share this post


Link to post
Share on other sites

I still haven't figured this one out. Anyone have a working script (one that works in Win7?)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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]

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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

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