Click to See Complete Forum and Search --> : Help! Adding a network printer to a remote workstation


paultown
10-28-2004, 11:09 PM
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
Set 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 helpfull...

neil9999
10-29-2004, 01:49 AM
If this is a java question, you might want to try the java forum. Remember java and javascript are totally different languages.

http://www.webdeveloper.com/forum/forumdisplay.php?s=&forumid=31

Neil

jbot
10-29-2004, 03:46 AM
Originally posted by neil9999
If this is a java question, you might want to try the java forum. Remember java and javascript are totally different languages.

it's not. it's a JScript question. but as usual he's not sure of the difference betwixt JS and Java. his example uses VBScript.

paultown: have you tried googling for "windows scripting". i did once and came across a wealth of sites for Windows admin. another term to investigate is "Windows Script Host". the kinda scripts you are writing are called "WSH scripts". but you write them in either VBS (as you've got above) or in JScript.

hope that helps :)

quick note: JavaScript is Netscape's brand of Javascript (JS). JScript is M$ version of Javascript. Javascript is therefore the generic name for the langauge: it's not JAVA script, so don't call it Java for short because that just confuses things!

paultown
10-31-2004, 07:02 PM
Thanks for the quick replies neil9999 and jbot, will try a WHS script forum.
Thanks again....