Solved

added printers using a script

Posted on 2004-10-13
17
288 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
  • 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
 

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now