我试图通过ShellExecuteEx()从c#执行notepad.exe。但是记事本没有发布。我在Windows 10 64位操作系统中运行代码。这有什么不同吗?什么可以解决。
以下是我写的代码
SHELLEXECUTEINFO SEI = SHELLEXECUTEINFO.CreateInstance();
SEI.cbSize = Marshal.SizeOf(SEI);
SEI.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI
| SEE_MASK_NOASYNC | SEE_MASK_INVOKEIDLIST;
SEI.hWnd = 0;
SEI.lpVerb = "open";
SEI.lpFile = sbResult.ToString(); //StringBuilder notepad.exe path
SEI.lpParameters = sDocName; // txt file path
SEI.lpDirectory = "";
SEI.nShow = SW_SHOWNORMAL;
SEI.hInstApp = 0;
SEI.lpIDList = 0;
lReturnedCode = ShellExecuteEx(ref SEI);
WaitForSingleObject(SEI.hProcess, INFINITE);
答案 0 :(得分:4)
无需使用ShellExecuteEx()
。您可以使用Process.Start():
Process proc = Process.Start("notepad.exe", sDocName);