Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to execute vbscript through java

807591Jun 20 2008 — edited Jun 20 2008
hi i m trying to run vbscript (that accept some command line arguments) through java .
my vbs file is stored in c: drive
purpose of vbs file : to map network drives.
i normally run it from command prompt using following syntax
c:\cscript map.vbs l: \\10.22.122.35\d$ <username> <password>
------------------------------------------
code in map.vbs
map.vbs
Dim objNetwork
Set objNetwork = WScript.CreateObject("WScript.Network")
strLocalDrive = WScript.Arguments.Item(0)
strRemoteShare = WScript.Arguments.Item(1)
strPer = "FALSE"
strUsr = WScript.Arguments.Item(2)
strPas = WScript.Arguments.Item(3)
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPas
-------------------------------------------------
my problem is i can easily accomplish this by using .batch file but i dont want to reveal my username and password
i just want to know is there any way thru which i can somehow link java program with dos command and execute vbs file
from my java program.
the code that i have got is not working properly or has to be modified to work.

String os = System.getProperty("os.name").toLowerCase();


if (os.indexOf("windows") != -1)
{
String[] command = new String[]{"cmd.exe", "/c","cscript","c:\\map.vbs", '"'+strDrive+'"','"'+strPath+'"',"<username>" ,"<password>"};

Runtime.getRuntime().exec(command);

Kindly help me as this is very urgent.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 18 2008
Added on Jun 20 2008
1 comment
2,644 views