Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

added printers using a script

Hi all

this is my problem i have a printer script which i found online which can remotley install a networked printer on a remote machine.

THIS IS THE SCRIPT

REM add the specified printer to the specified computer
@Echo On
rundll32 printui.dll,PrintUIEntry /ga /c\\%1 /n\\%2
@Echo off
REM stop the print spooler on the specified computer and wait until the sc command finishes
@Echo On
start /wait sc \\%1 stop spooler
@Echo off
REM start the print spooler on the specified computer and wait until the sc command finishes
@Echo On
start /wait sc \\%1 start spooler

now this work fine but the problem i have is that i also have a list of computer names in a txt file which i would like the script to look through  and substitue %2 with so that i dont have to keep typing every computer name in.

any ideas

Madforit









0
madforit2501
Asked:
madforit2501
  • 8
  • 7
1 Solution
 
pratap_rCommented:
simple..

invoke your batch file with the help of a for loop

type this at command prompt
FOR /f "usebackq" %f IN (`type machines.lst`) DO Remote %f

substitute machines.lst with your list file name
and Remote with your batch file name

if you use it from inside a batch file be sure to put %f as %%f

Enjoy!
Pratap
0
 
madforit2501Author Commented:
That work thanks

one other question.

i would like to set the printer to default.

and maybe delete all printers in the control panel
0
 
pratap_rCommented:
from command line? you might have to go for WSH scripts is that ok?

Pratap
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
madforit2501Author Commented:
I guess but how hard is that i dont know wsh script ?
0
 
pratap_rCommented:
its vbscript basically

what are you looking for exactly.. let me see if i can come up with a snippet

Pratap
0
 
madforit2501Author Commented:
i am just thinking of setting the new printer to default.

but the normal command line does not work

C:\>RUNDLL32 PRINTUI.DLL,PrintUIEntry /ga  /c\\ilodt06721 /y /n\\ilofile01\Print
er-45
0
 
pratap_rCommented:
check this site

http://www.codecomments.com/archive300-2004-6-204632.html

there is a detailed message about doing this

let me know if you have doubts

Enjoy!
Pratap
0
 
madforit2501Author Commented:
that's cool.

and it works but how would i put a for loop or somthing in it so that it reads from a text file

cheers

madforit
0
 
pratap_rCommented:
you can put the entire loop inside the vb script itself.. but for the sake of simplicity ill do it in the batch file itself

assuming your vbscript file is setprinter.vbs and it accepts a printer name as parameter

use the previous syntax i mentioned about and construct a batch file which does

FOR /f "usebackq" %f IN (`type machines.lst`) DO cscript setprinter.vbs %f

does this look ok? let me know if you want it inside the vbs itself

"cscript setprinter.vbs" will execute the vb script

pratap
0
 
madforit2501Author Commented:
OK  that was great on the local machine but it will not work on a remote machine it seems only to work for local machines do you have anything that will work on remote machines.

Cheers

madforit2501

0
 
pratap_rCommented:
you mean setting the default printer on the remote machine? hmm wonder if that is possible directly, let me check and tell you. It should be possible indirectly though. i'll post after some research..
0
 
pratap_rCommented:
hey did you try adding the printer connection first and then using the /y command? seems to work for me

Pratap
0
 
madforit2501Author Commented:
ok so for example

i am using this to add the printer rundll32 printui.dll,PrintUIEntry /ga /c\\%1 /n\\servername\Printername

so what would i do to remotely add the printer.

would it be

rundll32 printui.dll,PrintUIEntry /ga /c\\%1 /n\\ilofile01\Printer-51 /y

i aws not sure of the syntax

cheers  


Madforit2501



0
 
pratap_rCommented:
that should work, i tried it as 2 commands, first add the printer and then set it as default...
0
 
madforit2501Author Commented:
i will try that and let you know

thanks again
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now