I need to execute a net use command which is written in a batch file to enable a drive. Batch file is as follows:
net use * /delete /Y
net use l: \\<windows drive name> /user:<domain>\<username> <password>
The above batch file enables a drive for me and its visible as L: drive to me. I need to execute this batch file through java code and then write the some files onto this drive.
I am using the below code to execute this batch file:
String[] array = { "cmd", "/C", "start", "C:/file.bat" };
Runtime.getRuntime().exec(array);
Problem is when I try to access the drive to write the files it gives me a path not found exception. Sometimes it runs and sometimes it doesn't.
Friends can anyone help me to understand where is the issue. What wrong step I am performing. In case I am not clear with my question do let me know.