2

現在、setup.dll を使用して、フィルター ドライバーをプログラムでインストールしています。以下は私のコードです:

    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#コードを持っていれば素晴らしいでしょうか? ありがとうヘンリー

4

1 に答える 1

0

rundllコマンド ラインが示唆するようにInstallHinfSection、SETUPAPI.DLL からもエクスポートされるため、p/invokable です。MSFT bod がここに ap/invoke 署名を投稿しました:

using System.Runtime.InteropServices; 


[DllImport("Setupapi.dll", EntryPoint="InstallHinfSection", CallingConvention=CallingConvention.StdCall)] 
public static extern void InstallHinfSection( 
    [In] IntPtr hwnd, 
    [In] IntPtr ModuleHandle, 
    [In, MarshalAs(UnmanagedType.LPWStr)] string CmdLineBuffer, 
    int nCmdShow); 

InstallHinfSection(IntPtr.Zero, IntPtr.Zero, "my path", 0);
于 2013-11-05T10:30:10.313 に答える