2011-05-04 5 views
6

ASP.Net 페이지를 통해 서버에서 배치 파일을 실행하려고하면 내 미친 소리가납니다. 아래 코드를 실행하면 아무런 문제가 없습니다.이 코드가 실행되는 일부 로그 문을 볼 수는 있지만 함수에 전달한 .bat 파일은 절대 실행되지 않습니다.ASP.Net 페이지에서 배치 파일 실행

아무도 내가 뭘 잘못하고 있다고 말할 수 있습니까?

오류있는 응용 프로그램 cmd.exe를, 버전 6.0.6001.18000을 :에서

public void ExecuteCommand(string batchFileLocation) 
{ 
    Process p = new Process(); 

    // Create secure password 
    string prePassword = "myadminpwd"; 
    SecureString passwordSecure = new SecureString(); 
    char[] passwordChars = prePassword.ToCharArray(); 
    foreach (char c in passwordChars) 
    { 
     passwordSecure.AppendChar(c); 
    } 

    // Set up the parameters to the process 
    p.StartInfo.FileName = @"C:\\Windows\\System32\cmd.exe"; 
    p.StartInfo.Arguments = @" /C " + batchFileLocation; 
    p.StartInfo.LoadUserProfile = true; 
    p.StartInfo.UserName = "admin"; 
    p.StartInfo.Password = passwordSecure; 
    p.StartInfo.UseShellExecute = false; 
    p.StartInfo.CreateNoWindow = true; 

    // Run the process and wait for it to complete 
    p.Start(); 
    p.WaitForExit(); 
} 

은 '응용 프로그램'이벤트 뷰어, 서버에 내가 이것을 실행하려고 할 때마다 로그, 다음과 같은 문제가 발생하는 것 같습니다 , 타임 스탬프 0x47918bde, 오류 모듈 kernel32.dll, 버전 6.0.6001.18000, 타임 스탬프 0x4791a7a6, 예외 코드 0xc0000142, 오류 오프셋 0x00009cac, 프로세스 ID 0x8bc, 응용 프로그램 시작 시간 0x01cc0a67825eda4b.

UPDATE

다음 코드는 잘 작동은 (는 배치 파일을 실행) :

Process p = new Process(); 
p.StartInfo.FileName = batchFileLocation; 
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(batchFileLocation); 
p.StartInfo.UseShellExecute = false; 

// Run the process and wait for it to complete 
p.Start(); 
p.WaitForExit(); 

이 그러나하지 않습니다 (내가 특정 사용자로 실행하려고 할 때) :

Process p = new Process(); 

// Create secure password 
string prePassword = "adminpassword"; 
SecureString passwordSecure = new SecureString(); 
char[] passwordChars = prePassword.ToCharArray(); 
foreach (char c in passwordChars) 
{ 
     passwordSecure.AppendChar(c); 
} 

p.StartInfo.FileName = batchFileLocation; 
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(batchFileLocation); 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.UserName = "admin"; 
p.StartInfo.Password = passwordSecure; 

// Run the process and wait for it to complete 
p.Start(); 
p.WaitForExit(); 

답변

1

약간의 구글 날이 IIS forum을 가리키는 "응용 프로그램 cmd.exe를 오류있는"에.

CreateProcessWithLogon 메서드를 사용하지 않으면 IIS의 백그라운드에서 새 프로세스를 만들 수없는 것으로 보입니다. (나는 이것을 시험하지 않았다).

+0

이것은 내가보기에 문제가있는 것처럼 보입니다 .- 불행히도 IIS 포럼 스레드의 솔루션에 대한 링크가 다운 된 것처럼 보입니다. –

4

바로 배치 파일을

p.StartInfo.FileName = batchFileLocation; 

또한, WorkingDirectory가 올바른 위치로 설정되어 있는지 확인합니다 :

p.StartInfo.WorkingDirectory= Path.GetDirectoryName(batchFileLocation); 
+0

나는 이것을 이미 시도했지만, 나는 같은 결과를 얻는다. 코드는 정상적으로 실행되지만 배치 파일은 절대 시작되지 않습니다. –

+0

@ 지미 - 전달 된 매개 변수를 확인 했습니까? 파일이 올바른 위치에 있습니까? – Oded

+0

그래, 나는 그것을 확인하기 위해 로그 파일에 매개 변수를 넣고 실제 파일이 존재하는지 확인했다. –