2011-02-22 45 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 
}) { 

} 
相关问题