Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

added printers using a script

Posted on 2004-10-13
17
Medium Priority
?
300 Views
Last Modified: 2008-02-01
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
Comment
Question by:madforit2501
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
17 Comments
 
LVL 11

Expert Comment

by:pratap_r
ID: 12296687
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
 

Author Comment

by:madforit2501
ID: 12317281
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
 
LVL 11

Expert Comment

by:pratap_r
ID: 12317671
from command line? you might have to go for WSH scripts is that ok?

Pratap
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:madforit2501
ID: 12317694
I guess but how hard is that i dont know wsh script ?
0
 
LVL 11

Expert Comment

by:pratap_r
ID: 12317709
its vbscript basically

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

Pratap
0
 

Author Comment

by:madforit2501
ID: 12317728
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
 
LVL 11

Expert Comment

by:pratap_r
ID: 12318395
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
 

Author Comment

by:madforit2501
ID: 12320955
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
 
LVL 11

Accepted Solution

by:
pratap_r earned 1000 total points
ID: 12322699
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
 

Author Comment

by:madforit2501
ID: 12336841
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
 
LVL 11

Expert Comment

by:pratap_r
ID: 12340734
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
 
LVL 11

Expert Comment

by:pratap_r
ID: 12388457
hey did you try adding the printer connection first and then using the /y command? seems to work for me

Pratap
0
 

Author Comment

by:madforit2501
ID: 12401594
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
 
LVL 11

Expert Comment

by:pratap_r
ID: 12407685
that should work, i tried it as 2 commands, first add the printer and then set it as default...
0
 

Author Comment

by:madforit2501
ID: 12411950
i will try that and let you know

thanks again
0

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Progress

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question