在一次执行OfficeXPPIA 的注册文件中,发现我用
System.Diagnostics.Process.Start和ShellExecute执行出来,竟然没有效果,后来发现在窗口中击却没有问题:代码如下:
System.Diagnostics.Process.Start(fApplicationPath + @"/Drv/OFFICEXP/OfficeXPPIA/register.bat");
ShellExecute(this.Handle, "Open", fApplicationPath + @"/Drv/OFFICEXP/OfficeXPPIA/register.bat", String.Empty, String.Empty, SW_HIDE);
百思不得其解。
后来发现ShellExecute这个api比较有意思,看其声名如下
[DllImport("shell32.dll")]
public static extern int ShellExecute(
IntPtr hwnd,
string lpszOp,
string lpszFile,
string lpszParams,
string lpszDir,
int FsShowCmd);
lpszDir还有路径,结果把代码改成如下:
ShellExecute(this.Handle, "Open", "register.bat", String.Empty, fApplicationPath + @"/Drv/OFFICEXP/OfficeXPPIA", SW_HIDE);
功能实现,故名思义 lpszDir 默认搜索路径 ,这个bat要找文件时候,自然要找这个路径下的了,呵呵所以问题解决了。