0
我試圖從java創建Exchange服務器上的郵箱。我正在服務器上創建一個批處理文件並嘗試執行它,因此它會運行並創建郵箱。批處理文件正在創建,但尚未創建。我發現它試圖在本地機器而不是服務器上查找文件。有沒有辦法強制它在服務器上運行?我的代碼如下從Java遠程運行批處理文件創建Exchange 2010郵箱
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 [email protected] -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); } } }
希望任何建議/幫助。我不是一個高級程序員,並且在互聯網的幫助下完成了這個編碼。