2013-11-04 83 views
1

我正在使用setup.dll以編程方式安裝過濾器驅動程序。 下面是我的代碼:C#編程安裝過濾器驅動程序?

protected bool INFSetup(string path_to_inf, bool Install) 
    { 
     string exe = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "rundll32.exe"); 
     if (File.Exists(exe) && File.Exists(path_to_inf)) 
     { 
      try 
      { 
       Process proc = new Process(); 
       proc.EnableRaisingEvents = true; 
       string FileName = exe; 
       string Arguments = @"SETUPAPI.DLL,InstallHinfSection " + (Install ? "DefaultInstall" : "DefaultUninstall") + " 128 " + path_to_inf; 
       Debug.Writeline("Executing: '" + FileName + "' with arguments: " + Arguments); 
       ProcessStartInfo StartInfo = new ProcessStartInfo(FileName, Arguments); 
       StartInfo.CreateNoWindow = true; 
       StartInfo.UseShellExecute = false; 
       proc.StartInfo = StartInfo; 
       if (proc.Start()) 
       { 
        if (proc.WaitForExit(10000)) 
        { 
         return (proc.ExitCode == 0); 
        } 
        else 
        { 
         Debug.Writeline("INFSetup: proc.WaitForExit() returned false"); 
        } 
       } 
       else 
       { 
        Debug.Writeline("INFSetup: proc.Start() returned false"); 
       } 
      } 
      catch (Exception e) 
      { 
       Debug.Writeline("Caught Execption while installing INF: " + e.ToString()); 
       return false; 
      } 
     } 
     return false; 
    } 

雖然代碼工作正常,我想知道是否有一種方法可以做到與原生Win32調用一樣嗎? 這將是偉大的,如果任何人有一個示例C#代碼? 由於 亨利

回答

0

作爲rundll命令行提示InstallHinfSection也從SETUPAPI.DLL出口並且因此P /可調用。 MSFT bod發佈了一個p/invoke簽名here

+0

謝謝,我會在我的更新後的代碼發佈後 – ehenry7

相關問題