2014-01-09 5 views
0

Windows 서비스 zip 파일을 다운로드하고 추출하는 이름이 MyCustomUpdater.exe 인 프로그램이 하나 있습니다.C# (바탕 화면 응용 프로그램)에서 Windows 서비스를 설치하는 방법

추출 폴더 내가

내가 그것을

Process process = new Process(); 
process.StartInfo.FileName = "cmd.exe"; 
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
process.StartInfo.RedirectStandardInput = true; 
process.StartInfo.RedirectStandardError = true; 
process.StartInfo.RedirectStandardOutput = true; 
process.StartInfo.UseShellExecute = false; 
process.StartInfo.Verb = "runas"; 
process.Start(); 

if (process != null) 
{ 
    process.StandardInput.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "\\Microsoft.NET\\Framework\\v4.0.30319\\installutil.exe /u \"" + "E:\Testing\MV.AutoUpdateWindowsService.exe" + "\""); 
    process.StandardInput.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "\\Microsoft.NET\\Framework\\v4.0.30319\\installutil.exe \"" + "E:\Testing\MV.AutoUpdateWindowsService.exe" + "\""); 
    process.StandardInput.Close(); 
} 
process.Close(); 

에 대한 노호 언급 코드를 사용 MyCustomUpdater.exe

에서 해당 MyWindowsServices.exe를 설치하려는 MyWindowsServices.exe이

를 제출해야하지만 설치하지 않습니다 Windows 서비스

이 코드는 하나의 빈 검은 색 명령 프롬프트 창을 엽니 다. 더 이상의 실행.

또한 2013


내 MyCustomUpdater.exe 에 대한 파일을 app.manifest 추가 내가 비주얼 스튜디오와 닷넷 프레임 워크 4.5을 사용

process.StartInfo.Arguments 

에서 Windows 서비스 설치 명령을 실행하려고 app.manifest를 포함시킨 후 설정했습니다. 오른쪽> 매니페스트가 나는 확률 코드 후 app.manifest 을 를 [드롭 다운을 클릭]를 선택 프로그램> 부동산> 응용 프로그램> 자원을 클릭

Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\Microsoft.NET\Framework\v4.0.30319\installutil.exe", _FilePath); 

이 제거 프로세스

에 대해 잘 작동하지만,
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\Microsoft.NET\Framework\v4.0.30319\installutil.exe", "/u " + _FilePath); 

또는

Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\Microsoft.NET\Framework\v4.0.30319\installutil.exe" + " /u ", _FilePath); 

작동하지

가 우는 소리는

<?xml version="1.0" encoding="utf-8"?> 
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <assemblyIdentity version="1.0.0.0" name="MyApplication.app" /> 
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> 
    <security> 
     <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> 
     <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> 
     </requestedPrivileges> 
     <applicationRequestMinimum> 
     <PermissionSet Unrestricted="true" ID="Custom" SameSite="site" /> 
     <defaultAssemblyRequest permissionSetReference="Custom" /> 
     </applicationRequestMinimum> 
    </security> 
    </trustInfo> 
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
    <application> 
    </application> 
    </compatibility> 
</asmv1:assembly> 

가 도와 app.manifest 파일의 코드입니다.

감사

+0

안녕하세요. installutil.exe를 직접 실행하지 않고 (즉,'StartInfo.FileName'에서) 표준 입력을 사용하여'cmd.exe'에 exe를 전달할 이유가 있습니까? – Rob

+0

'process.OutputDataReceived + = (s, e) => _ILog.Fatal (@ "OutputDataReceived :"+ e.Data); '을 추가했지만 출력을 얻을 수 없음 –

+0

어떻게 실패합니까? InstallUtil.InstallLog 파일에 단서가 있습니까? – Rob

답변

0

당신이 단순히 직접 설치 실행 파일을 실행할 수있을 때이 방법으로 cmd.exe를 사용하는 조금 이상한 것 같다. 하지만 실제로 cmd.exe 및 STDIN 리디렉션을 사용하려는 경우 "/ K"스위치를 지나서 interative 모드를 사용해야합니다.

자세한 내용은 answer을 참조하십시오.

+0

관리자 모드에서 내 응용 프로그램을 실행하려면 ** app.manifest **를 추가하십시오. 그 후'Process.Start'는 설치를 위해 작동합니다. –

0

관리자로 installutil.exe을 호출하려고하는 프로그램을 실행 한 다음 cmd의 도움없이 직접 installutil.exe을 실행해야합니다. 또한 PInvoke가 더 안정적이라고 생각합니다 (OpenSCManager, CreateService 참조).

0

실행 중

관리자 모드에서 app.manifest 프로그램이 실행됩니다. [코드는 위에 언급되었습니다]

벨로우는 "자동"모드에서 Windows 서비스를 설치하는 코드입니다.

Process _Process = new Process(); 
_Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
_Process.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\Microsoft.NET\Framework\v4.0.30319\installutil.exe"; 
_Process.StartInfo.Arguments = "/u \"" + _FilePath + "\""; 
_Process.Start(); 
System.Threading.Thread.Sleep(8000); 
_Process.Close(); 
_Process = new Process(); 
_Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
_Process.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\Microsoft.NET\Framework\v4.0.30319\installutil.exe"; 
_Process.StartInfo.Arguments = _FilePath; 
_Process.Start(); 
_Process.Close(); 

감사합니다.

관련 문제