我正在尝试在从Web门户导入的远程服务器上运行DelTemp-Final.vbs。
我尝试使用原生C#来完成任务,没有运气。所以我选择PS工具来帮助我。我坚持下面的情景。请帮忙
Psexec正在使用命令提示符,但不使用c#
下面是命令提示输出,它正常工作:
C:\inetpub\wwwroot\DelTemp\Scripts>psexec \\testusit1 -u XXXX\xxxxxxx -p xxxx
Xxxxxxxx -accepteula -i 0 -d c:\windows\system32\cscript.exe /nologo "\\testusi
t2\C$\karthik\DelTemp-Final.vbs"
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
c:\windows\system32\cscript.exe started on testusit1 with process ID 5452.
C:\inetpub\wwwroot\DelTemp\Scripts>psexec \\testusit2 -u XXXX\xxxxxxx -p xxxxx
xxxxxxxxx -accepteula -i 0 -d c:\windows\system32\cscript.exe /nologo "\\testusi
t2\C$\karthik\DelTemp-Final.vbs"
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
c:\windows\system32\cscript.exe started on testusit2 with process ID 7416.
然而,当在asp.net中包含c#时,相同的命令不起作用
Process p=new Process();
p.StartInfo.UseShellExecute=false;
p.StartInfo.RedirectStandardOutput=true;
p.StartInfo.RedirectStandardError=true;
p.StartInfo.RedirectStandardInput=true;
p.StartInfo.FileName=@"C:\inetpub\wwwroot\DelTemp\Scripts\PsExec.exe";
p.StartInfo.Arguments="\\\\"+li.Text+" -u XXXX\\xxxxxx -p xxxxxxxxxxx -accepteula -i 0 -d c:\\windows\\system32\\cscript.exe /nologo \\\\testusit2\\C$\\karthik\\DelTemp-Final.vbs";
p.Start();
string output=p.StandardOutput.ReadToEnd();
string errormessage=p.StandardError.ReadToEnd();
p.WaitForExit();
txtValueA.Text +="PSexec argument :" + p.StartInfo.Arguments;
txtValueA.Text +="
Output : " + output+"| error messsage: "+errormessage;
两台服务器的上述代码输出如下:
PSexec argument :\\testusit1 -u XXXX\xxxxxxxxxx -p xxxxxxxxxx -accepteula -i 0 -d
c:\windows\system32\cscript.exe /nologo \\testusit2\C$\karthik\DelTemp-Final.vbs Output : | error
messsage: PsExec v2.11 - Execute processes remotely Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com The handle is invalid. Connecting to testusit1... Starting
PSEXESVC service on testusit1... Connecting with PsExec service on testusit1... Error deriving
session key:
PSexec argument :\\testusit2 -u XXXX\xxxxxxxxxxx-p xxxxxxxxxx -accepteula -i 0 -d
c:\windows\system32\cscript.exe /nologo \\testusit2\C$\karthik\DelTemp-Final.vbs Output : | error
messsage: PsExec v2.11 - Execute processes remotely Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com Access is denied. Connecting to testusit2... Starting PSEXESVC
service on testusit2... Could not start PSEXESVC service on testusit2: Connecting to testusit2...
Starting PSEXESVC service on testusit2...
请帮助..我需要对脚本进行任何更改吗?非常感谢任何帮助。
提前多多感谢:)