Eil*_*lon 25
尝试这样的事情:
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);
Run Code Online (Sandbox Code Playgroud)
然后叫它:
InstallHinfSection(IntPtr.Zero, IntPtr.Zero, "my path", 0);
Run Code Online (Sandbox Code Playgroud)
我使用P/Invoke签名生成器生成了大部分签名.
该方法及其参数的完整细节在MSDN上.根据MSDN,第一个参数可以为null,第二个参数必须为null,最后一个参数必须为0.您只需要传入string参数.
小智 5
这个简单的代码对我有用
private void driverInstall()
{
var process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/c C:\\Windows\\System32\\InfDefaultInstall.exe " + driverPath; // where driverPath is path of .inf file
process.Start();
process.WaitForExit();
process.Dispose();
MessageBox.Show(@"Driver has been installed");
}
Run Code Online (Sandbox Code Playgroud)