Question

  Asked: May 14 2008   6:09 AM GMT
  Asked by: Ilana


run vbscript on remote computer from java


VBScript, Remote computer, Java

How do I run vbscript on remote computer from java application?

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



Googling I found this (http://www.rgagnon.com/javadetails/java-0014.html) so I'd suppose that if you adjust the code below:
========
import java.io.*;
public class CmdExec {

public static void main(String argv[]) {
try {
String line;
Process p = Runtime.getRuntime().exec
(System.getenv("windir") +"\\system32\\"+"tree.com /A");
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
}
catch (Exception err) {
err.printStackTrace();
}
}
}
========
By changing:
Process p = Runtime.getRuntime().exec
(System.getenv("windir") +"\\system32\\"+"tree.com /A");
in

Process p = Runtime.getRuntime().exec
(System.getenv("windir") +"\\system32\\"+"wscript.exe c:\yourscript.vbs hosttocheck");

coule lead you to the solution.
In the vbscript I suggest you to use command-line arguments in order to be able to pass the remote host's name/ip
E.g.
' VbScript code
Dim HostToCheck
Set objArgs = WScript.Arguments
If objArgs.Count > 0 Then
HostToCheck = objArgs(0)
End If
....

I hope this helps
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Development and Microsoft Windows.

Looking for relevant Development Whitepapers? Visit the SearchSQLServer.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register