2009-08-13 4 views
0

C#에서 프로그래밍 방식으로 소프트웨어를 제거하는 방법?C에서 소프트웨어를 프로그램 적으로 제거하는 방법

Microsoft.Win32.RegistryKey Fregistry = Microsoft.Win32.Registry.LocalMachine.OpenSubKey ("소프트웨어") 나는 ** 라인과 같은 오류 .... NULL 참조 예외를 가지고

  .OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion") 
      .OpenSubKey("Installer").OpenSubKey("UserData") 
      .OpenSubKey("S-1-5-18").OpenSubKey("Products"); 
      string[] Names = Fregistry.GetSubKeyNames(); 
      string uninstall = ""; 
      string ApplicationName = "Studio V5"; 
      for (int i = 0; i < Names.Length; i++) 
      { 
       Microsoft.Win32.RegistryKey FTemp = Fregistry.OpenSubKey(Names[i]).OpenSubKey("InstallProperties"); 
       **if (FTemp.GetValue("DisplayName").ToString() == ApplicationName)** 
       { 
        object obj = FTemp.GetValue("UninstallString"); 
        if (obj == null) 
         uninstall = ""; 
        else 
         uninstall = obj.ToString(); 
        i = Names.Length; 
       } 
      } 

      System.Console.WriteLine(uninstall); 
      System.Diagnostics.Process FProcess = new System.Diagnostics.Process(); 
      string temp = "/x{" + uninstall.Split("/".ToCharArray())[1].Split("I{".ToCharArray())[2]; 
      //replacing with /x with /i would cause another popup of the application uninstall 
      FProcess.StartInfo.FileName = uninstall.Split("/".ToCharArray())[0]; 
      FProcess.StartInfo.Arguments = temp; 
      FProcess.StartInfo.UseShellExecute = false; 
      FProcess.Start(); 
      System.Console.Read(); 

.

답변

2

이것은 매우 불쾌한 방법이며, 어떤 경우에도 작동하는 것은 틀림 없습니다. 대신 Windows Installer API을 사용하고 MsiConfigureProduct 및/또는 MsiConfigureFeature 함수를 INSTALLSTATE_ABSENT과 프로그래밍 방식으로 제거해야합니다.

+0

* Windows Installer *를 사용하여 설치하지 않은 소프트웨어에서 작동합니까? – Treb

+0

이 경우 Windows Installer는 특정 설치 관리자 형식 (예 : .msi)이 아닌 API입니다. 비 .msi 설치 관리자는 여전히 WI API를 사용하여 설치하는 모든 구성 요소를 등록 할 수 있습니다. 그렇게하지 않으면'Microsoft \ Installer' 아래에 레지스트리 키를 쓰지 않고 어쨌든 발견 할 수 없습니다. –

관련 문제