2012-03-20 2 views
0

이 함수는 을 사용하여 설치된 응용 프로그램을 찾습니다.응용 프로그램별로 설치된 응용 프로그램 경로를 가져 오는 올바른 방법입니다. 이름은 C#

그러나 매개 변수 "InstallLocation"이 전혀 작동하지 않습니다.

단서가 있습니까?

감사합니다.

void FindApplication(string appName) 
{ 
    StringBuilder sbProductCode = new StringBuilder(39); 
    int iIdx = 0; 
    while (0 == MsiEnumProducts(iIdx++, sbProductCode)) 
    { 
     Int32 productNameLen = 512; 
     StringBuilder sbProductName = new StringBuilder(productNameLen); 

     MsiGetProductInfo(sbProductCode.ToString(), "ProductName", sbProductName, ref productNameLen); 

     if (sbProductName.ToString().Contains(appName)) 
     { 
      Int32 installDirLen = 2048; 
      StringBuilder sbInstallDir = new StringBuilder(installDirLen); 
      MsiGetProductInfo(sbProductCode.ToString(),"InstallLocation", sbInstallDir, ref installDirLen); 

      string result = string.Format("ProductName {0}: {1}", sbProductName, sbInstallDir); 
      } 
     } 
} 

답변

3

나는 다음 링크를 방문했던, 그들은 오래된 것으로 나타났습니다하지 않습니다

I가 될 수 볼 수있는 유일한 키 사용되는 문자는 다음과 같습니다.

  • ARPINSTALLLOCATION
  • INSTALLDIR
  • INSTALLPROPERTY_INSTALLLOCATION
  • INSTALLLOCATION

나는 추가 출판/설치된 제품에 대한 정보를 수집하는 데 사용되어야한다 MsiGetProductInfoEx (두 번째 링크)가 나타납니다 지적한다 다른 사용자; 관리 권한이 필요합니다.

+0

이들은 제대로 작동하지 않습니다. : ( –

+1

@ Peretz 내 게시물을 업데이트했습니다. 잘하면 당신에게 더 많은 도움이됩니다. –

0

다른 해결책을 찾았지만 정상적으로 작동합니다.

string FindPathByInstalledAppEXEName(string appEXEName) 
{ 
    string path = string.Empty; 

    try 
    { 
     RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Installer\Assemblies"); 

     string regfilepath = string.Empty; 
     if (key != null) // Make sure there are Assemblies 
     { 
      foreach (string Keyname in key.GetSubKeyNames()) 
      { 
       if (Keyname.IndexOf(appEXEName) > 0) 
       { 
        regfilepath = Keyname; 
        break; 
       } 
      } 
     } 

     if (!string.IsNullOrEmpty(regfilepath)) 
     { 
      string fullpath = ""; 
      for (int a = 0; a < regfilepath.Length; a++) 
      { 
       if (regfilepath.IndexOf("|", a, 1) > 0) 
        fullpath += "\\"; 
       else 
        fullpath += regfilepath.Substring(a, 1); 
      } 
      path = fullpath.Substring(0, fullpath.LastIndexOf("\\") + 1); 
     } 
    } 
    catch // (Exception ex) 
    { 
    } 

    return path; 
} 
관련 문제