在做软件维护时遇到一个问题:在某个用户xp系统中Process.Start启动外部程序时导致报错,使用administrator账户运行才能正常运行,后来经过调试采用api函数WinExec和ShellExecute,无论什么用户都能运行正常。其中ShellExecute功能更强除了执行exe文件还可以执行等其它只要在系统中注册关联的程序,如word,excel文件等。

 [DllImport("kernel32.dll")]
  public static extern uint WinExec(string lpCmdLine,uint uCmdShow);
  public const int SW_SHOW=5;

  [DllImport("SHELL32.dll")]
  public static extern int ShellExecute(int hwnd,
   string lpOperation,
   string lpFile,
   string lpParameters,
   string lpDirectory,
   int nShowCmd
   );
  public const int SW_SHOWNORMAL=11;

执行时写法

WinExec(fileName,SW_SHOW);

ShellExecute(0,"open",fileName,null,null,SW_SHOWNORMAL);
    

相关文章:

  • 2021-12-08
  • 2022-12-23
  • 2021-08-11
  • 2021-11-20
  • 2022-02-13
  • 2021-04-27
  • 2021-10-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
  • 2022-02-18
相关资源
相似解决方案