2011-02-22 44 views
1

我正在開發一個web應用程序,該應用程序應該處理文件系統中的一些資源並使用特定用戶的特權運行某些應用程序。到現在爲止我叫的ProcessBuilder和適用於Windows 7和其他版本的PSEXEC服務:java/scala web應用程序和psexec

def get() = { 
    var currentOutputLine = "" 
    val pb = new ProcessBuilder("psexec.exe", "/ACCEPTEULA", 
    "-u", "user1", "-p", "password", "-w", batchpath, batchfile) 
    pb.directory(new File(batchpath)) 
    pb.redirectErrorStream(true) 
    val proc = pb.start 
    val input = new BufferedReader(new InputStreamReader(proc.getInputStream)) 
while ({ 
    currentOutputLine = input.readLine(); 
    currentOutputLine != null 
    }) { 

} 

應用服務器運行像TOMCATUSER一個特殊的用戶,我試圖調用批處理文件爲「USER1」。此代碼適用於Windows 7 x64,但我在Windows 2008 SP2中遇到了問題。

使用Windows 2008服務器sp2,從java應用程序執行psexec返回1073741502錯誤,並觀察eventviewr,我可以看到操作系統在cmd.exe上報告了錯誤,因爲無法打開彈出窗口。

很多的測試,我發現,我已經指派「用戶1」和「tomcatuser」去哪兒PSEXEC是所謂的系統管理員組,並調用PSEXEC與主機參數是這樣的後:

def get() = { 
    var currentOutputLine = "" 
    val pb = new ProcessBuilder("psexec.exe","\\\\localhost", "/ACCEPTEULA", 
    "-u", "user1", "-p", "password", "-w", batchpath, batchfile) 
    pb.directory(new File(batchpath)) 
    pb.redirectErrorStream(true) 
    val proc = pb.start 
    val input = new BufferedReader(new InputStreamReader(proc.getInputStream)) 
while ({ 
    currentOutputLine = input.readLine(); 
    currentOutputLine != null 
    }) { 

} 

有沒有辦法避免這個問題?我不想將管理員權限分配給user1帳戶,因爲我只需要以user1身份運行腳本。我使用psexec是因爲我主要需要在文件系統中以「user1」而不是tomcatuser(創建,複製,移動文件)的方式工作,是否有更好更安全的解決方案?

Thanks million。

弗拉維奧

回答

0

我解決使用winrs問題/ WinRM的由2008年的窗戶

我配置將WinRM服務器,之後的客戶端代碼是提供:

def get() = { 
var currentOutputLine = "" 
val pb = new ProcessBuilder("winrs.exe", "-r:http://localhost:5985", "-u:user1", "-p:password", 
"-ad","-d:workingpath","\""+commandtorun+"\"") 

pb.directory(new File(batchpath)) 
pb.redirectErrorStream(true) 
val proc = pb.start 
val input = new BufferedReader(new InputStreamReader(proc.getInputStream)) 
while ({ 
    currentOutputLine = input.readLine(); 
    currentOutputLine != null 
}) { 

} 
相關問題