java/scala Web 应用程序和 psexec
我正在开发一个网络应用程序,它应该处理文件系统中的一些资源,并以特定用户的权限运行一些应用程序。到目前为止,我调用了 Windows 7 和其他版本中可用的 ProcessBuilder 和 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 上报告了错误,因为无法打开弹出窗口。
经过大量测试,我发现我必须将“user1”和“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 在文件系统中工作(创建、复制、移动文件),是否有更好且安全的解决方案来执行此操作?
谢谢万。
弗拉维奥
I'm developing a webapp that should handle some resources in the filesystem and run some application with privileges of a specific user. Until now I called the ProcessBuilder and the psexec service available with Windows 7 and other version:
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
}) {
}
The application server is running as a special user like TOMCATUSER and I'm trying to call a batchfile as "user1". This code works fine with Windows 7 x64, but I have an issue with Windows 2008 sp2.
Using Windows 2008 server sp2, the execution of the psexec from the java application returned a 1073741502 error and watching the eventviewr I can see that the OS reported an error on cmd.exe because is not able to upen the popup window.
After alot of test I found that I have to assign the "user1" and "tomcatuser" to the administrator group in the system where psexec is called, and call the psexec with the hostname parameter like this:
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
}) {
}
Is there a way to avoid this issue? I don't want to assign administrator privileges to the user1 account, because I only need to run a script as user1. I use psexec because I mainly need to work in the filesystem as "user1" and not as tomcatuser (create, copy, move files), is there a better and safe solution to do this?
Thanks million.
Flavio
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用Windows 2008提供的winrs/winrm解决了这个问题,
我配置了winrm服务器,之后客户端代码是:
I solved the problem using winrs/winrm provided by windows 2008
I configured the winrm server and after that the client code is: