# Help needed for creating .cmd files



## paultown (Oct 29, 2004)

I'm not sure if this is the forum but hopefully someone can reply to my problem. I am new to creating .cmd and .vbs files and have been teaching myself for the past 2 days and can't figure this one out.
I want to launch a JAVA script within a .cmd file so I can add a printer on a remote workstation. 
Basically I have no idea on how to do this. I have found a script that I saved as a .vbs to add a printer on a local workstation but would like to amplify this so it works is this .cmd file. 
The code I have come up with is this, but it doesn't work:- 
********************************************* 
@echo off 
cls 
echo Add Printer %2 on %1 
echo.

if {%1}=={} goto Syntax 
if {%2}=={} goto Syntax

psexec \\%1 -i -d -s notepad

*Dim net 
Se net = CreateObject("WScript.Network") 
net.AddWindowsPrinterConnection "%2"*

Saveas \\%1\c$\temp\printer.vbs

Launch \\%1\c$\temp\printer.vbs
Del \\%1\c$\temp\printer.vbs

:Syntax 
echo Adds a printer on the target workstation 
echo. 
echo Usage: Printer [Computername] [\\Server\Printer] 
echo.

:End 
pause 
********************************************* 
This works up until psexec launches notepad on the remote workstation. Then I just get a errors. I know the saveas and the vbs code is wrong but you get the jist of what I want this to do.

What I would like to know is how to add the Bold code to the notepad window that launched and then to save it on the workstation as a .vbs file. I think then I will be able to figure out the rest.

Is this possible? Can I do this?
Or is there another way?
Any replies would be very helpful...


----------



## paultown (Oct 29, 2004)

If no one can answer my above query, Has anybody got a good batch file or VBscript that I could use to add printers to a remote workstation without logging in? 
It must have a variable value as the printers change across the network.


----------



## paultown (Oct 29, 2004)

I have come up this this code and this creates the .vbs file that I need to run on the remote workstation but now I have one more problem; I need my batch file to launch the newly created printer.vbs file on the remote workstation.
My code is as follows:-

@echo off
cls
echo Add Printer \\%2\%3 on %1
echo Author : Paul Townsend 28\10\04
echo ____________________________________________
echo.

if {%1}=={} goto HowTo
if {%2}=={} goto HowTo

CALL
>>\\%1\c$\temp\printer.vbs ECHO '-------------------------------------------
>>\\%1\c$\temp\printer.vbs ECHO ' Printer Install for network printer:
>>\\%1\c$\temp\printer.vbs ECHO ' %2 
>>\\%1\c$\temp\printer.vbs ECHO '-------------------------------------------
>>\\%1\c$\temp\printer.vbs ECHO Dim net
>>\\%1\c$\temp\printer.vbs ECHO Set net = CreateObject("WScript.Network") 
>>\\%1\c$\temp\printer.vbs ECHO net.AddWindowsPrinterConnection "%2"
>>\\%1\c$\temp\printer.vbs ECHO '-------------------------------------------

psexec -i -d -s \\%1 c$\temp\printer.vbs

echo Printer %2 has been successfully added on %1.

Goto End

:HowTo
echo Adds a printer on the target workstation 
echo. 
echo Usage: Printer [Computername] [\\Server\Printer]
echo.

:End
pause

But when psexec tries to launch printer.vbs it says that the file cannot be found.
Anybody out there know why, or can maybe tell be another way???


----------

