例如有一个驱动程序  aa.inf 需要安装到电脑
如何在c#代码中安装 ?
或者如何在安装部署项目中安装?
 string a="Rundll32.exe setupapi.dll";
 string b = " InstallHinfSection DefaultInstall 132 c:\\aa.inf";  第一次尝试
 System.Diagnostics.Process.Start(a,b);   提示系统找不到指定文件  第2次尝试
 System.Diagnostics.Process.Start(a+b);  提示系统找不到指定文件第三次尝试:   string installCmdLine = " rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 128  c:\\aa.inf"; System.Diagnostics.Process.Start(installCmdLine );   提示系统找不到指定文件
但是后者是可以在命令行实现的,那么到底怎么做呢?
谢谢
  

解决方案 »

  1.   

    遇到这样的我一般使用RAR压缩成EXE,在压缩的时候设置解压后或解压前执行什么文件
      

  2.   

    string a="Rundll32.exe setupapi.dll"; 
    string b = " InstallHinfSection DefaultInstall 132 c:\\aa.inf"; 不太明白  “InstallHinfSection DefaultInstall 132 “ 起什么作用。
    或者你试一下把 "Rundll32.exe" 的地址写成绝对地址试一下,比如 "c:\window\system32\Rundll32.exe setupapi.dll"
      

  3.   

    把你的驱动程序放在..\bin\Debug下,
    然后
    System.Diagnostics.Process.Start("aa.inf");或者
    System.Diagnostics.Process.Start("c:\....\aa.inf");
    其中:c:\....\aa.inf 指的是绝对路径。
      

  4.   

    你可以用cmd.exe来转一下,也可以用Rundll32.exe直接整,给你个CMD的
            string strOutput = string.Empty;
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.WorkingDirectory = "C:";
                p.Start();
                p.StandardInput.WriteLine("rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 128      C:\\aaaaaaaaaa.inf");
                p.WaitForExit(3000);
                p.StandardInput.WriteLine("exit");
                while (!p.StandardOutput.EndOfStream)
                {
                    strOutput = p.StandardOutput.ReadLine();
                    Console.WriteLine(strOutput);
                }
                p.Close();
                p.Dispose();