I'm trying to create mailbox on exchange server from java. I am creating a batch file on the server and trying to execute it, so it runs and creates the mailbox. The batch file is being created but is not being created. I've figured out that it is trying to look for the file in my local machine instead of the server. Is there a way I can force it to run on the server? My code is as below
package com.exchange;
import java.io.*;
public class CreateMailbox { public static void main(String[] args) throws IOException, InterruptedException { try {
String COMMAND1="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe
-command \".'C:\\Program Files\\Microsoft\\Exchange Server\\V14\\bin\\RemoteExchange.ps1';Connect-ExchangeServer
-auto;Enable-Mailbox admin123@imbl.corp -Database \"TESTDB\"\"> C:\\Users\\admin\\Desktop\\ActiveSyncDeviceAccessRule_output.txt 2>C:\\Users\\admin\\Desktop\\standardError.txt";
System.out.println(COMMAND1);
String ErrorCommand1 = "echo %errorlevel% >C:\\exitCode.txt";
String SPACE = " ";
final File file = new File("\\\\192.168.205.245\\C$\\Users\\admin\\Desktop\\Create.bat");
Boolean CreatenewFileVar = file.createNewFile();
if(CreatenewFileVar)
{
System.out.println("File Created in: " + file);
}
PrintWriter writer = new PrintWriter(file, "UTF-8");
writer.println(COMMAND1);
writer.println(ErrorCommand1);
writer.println(SPACE);
writer.close();
Process p1 = Runtime.getRuntime().exec("cmd /c Start \\\\192.168.205.245\\c$\\Users\\admin\\Desktop\\Create.bat");
int exitVal = p1.waitFor();
System.out.println("Exited with error code "+exitVal);
} catch (final IOException e) {
System.out.println("Error " + e); } } }
Would appreciate any suggestion / help. I am not an advanced programmer and have done this coding with the help of internet.