두 가지 유형의 프로세스를 시작하는 프로세스 처리기를 만들었습니다. 관리자 아이디와 비밀번호로 상승 된 그룹 다른 사용자 이름과 비밀번호없이 정상적으로 실행되는 또 하나의 프로세스입니다.상승 된 하위 프로세스에서 오류 및 표준 출력 가져 오기
상승 된 프로세스에서 출력을 얻을 수있는 방법을 파악하는 데 어려움을 겪고 있습니다. 프로세스를 시작하는 응용 프로그램은 관리 자격 증명을 실행할 필요가 없으며 응용 프로그램이 스크립트 및 관리자 자격 증명이 필요한 다른 장소에서 사용하는 별도의 암호화 된 xml 파일에 관리 자격 증명이 입력됩니다.
응용 프로그램이 일반 사용자와 함께 실행되므로 응용 프로그램이 시작된 상승 된 프로세스에 액세스하는 것이 문제가되지 않는 것 같습니다. 나는 프로세스를 시작할 수 있으며 그것이 제공되는 일을했는지 쉽게 확인할 수는 있지만 문자열이나 로그에 해당 작업을 읽을 수는 없습니다.
public bool CreateProcessWithAdminRights(string filePath, string commandlineArgument, bool log)
{
if (!string.IsNullOrEmpty(filePath) && !string.IsNullOrEmpty(commandlineArgument) && _user.UserDataExsists())
{
var securePassword = GetSecureString(_user.Password);
ToolsProvider.Logger.Debug("Creating process with the following filepath: {0} and commandline argument: {1}", filePath, commandlineArgument.Replace(_user.Password, "<REPLACED>"));
ToolsProvider.Logger.Info("Creating Process with admin rights for {0} against {1}", _user.Name);
_proc = new Process
{
StartInfo =
{
FileName = @filePath,
Arguments = commandlineArgument,
ErrorDialog = false,
RedirectStandardInput = false,
RedirectStandardOutput = _log,
RedirectStandardError = _log,
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UserName = _user.Name,
Password = securePassword,
Domain = _user.Domain
}
};
_proc.ErrorDataReceived += ErrorDataReceived;
_proc.OutputDataReceived += OutputDataReceived;
return true;
}
return false;
}
과정은 사용하기 시작한다 : 나는 함께 프로세스에 추가 관리자 자격 증명없이뿐만 아니라 장자 클래스를 사용하여 프로세스를 시작하려고했습니다
private bool StartProcess()
{
if (_proc != null)
{
try
{
_proc.Start();
_proc.BeginErrorReadLine();
_proc.BeginOutputReadLine();
_proc.WaitForExit();
_proc.CancelOutputRead();
_proc.CancelErrorRead();
if (_standardOutput.Length > 2)
{
// use writeline, the builder itself will add the DEBUG/info tag
ToolsProvider.Logger.WriteLine(_standardOutput.ToString());
}
if (_errorBuilder.Length > 2)
{
// use writeline, the builder itself will add the DEBUG/info tag
ToolsProvider.Logger.WriteLine(_errorBuilder.ToString());
}
return true;
}
catch (Win32Exception ex)
{
ToolsProvider.Logger.Error(
"Missing file while trying to run an action: " + _proc.StartInfo.FileName, ex.Message);
}
}
ToolsProvider.Logger.Error("");
return false;
}
. 그래서
http://freshclickmedia.co.uk/2008/11/programmatic-impersonation-in-c/
다음 장자 클래스는
는 여기에서 장자 클래스를 가지고 ... 내가 바로 그겁니다 내가 관리자를 가장 한, acccess을 가지고 있지 않았다고 말해하지만 아무 짓도 안 했어요 , 상승되지 않은 프로세스에서 상승 된 프로세스로부터 표준 및 오류 출력을 얻으려면 어떻게해야합니까?
'Named Pipe'를 사용할 수 있습니다. http://msdn.microsoft.com/en-us/library/bb546085.aspx – SepehrM