2014-10-09 19 views
0

我試圖在從Web門戶導入的遠程服務器上運行DelTemp-Final.vbs。 我試圖使用本機C#來完成任務,沒有運氣。所以我選擇了PS工具來幫助我。我被困在他下面的情況。請幫助無法使用c#Asp.Net運行遠程服務器上的VB腳本

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. 

然而,包括在同一命令不起作用用c#在asp.net爲兩個服務器

Process p=new Process(); 
p.StartInfo.UseShellExecute=false; 
p.StartInfo.RedirectStandardOutput=true; 
p.StartInfo.RedirectStandardError=true; 
p.StartInfo.RedirectStandardInput=true; 
[email protected]"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 +="<br/> 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... 

請幫助..我需要對腳本做任何更改嗎?任何幫助是極大的讚賞。

非常感謝:)

回答

0

嘗試將您的輸出指向事件處理程序。我在遠程機器上用psexec執行ipconfig在我的服務器上運行了一個變體,我可以查看所有輸出。

  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.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived); 
     p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived); 
     p.Start(); 
     p.BeginOutputReadLine(); 
     p.BeginErrorReadLine(); 
     p.WaitForExit(); 
     txtValueA.Text += "PSexec argument :" + p.StartInfo.Arguments; 
     txtValueA.Text += "<br/> Output : " + output + "| error messsage: " + errormessage; 
    } 
    public static void p_ErrorDataReceived(object sender, DataReceivedEventArgs e) 
    { 
     Console.WriteLine(e.Data); 
    } 

    //Standard output event handler for PSEXEC 
    public static void p_OutputDataReceived(object sender, DataReceivedEventArgs e) 
    { 
     Console.WriteLine(e.Data); 
    } 
相關問題