【发布时间】:2018-06-22 18:24:18
【问题描述】:
我们有一个旧版 Delphi 7 应用程序,它启动 Windows Defrag 和屏幕键盘应用程序,如下所示:
// Defragmentation application
ShellExecute(0, 'open', PChar('C:\Windows\System32\dfrg.msc'), nil, nil, SW_SHOWNORMAL);
// On-screen keyboard
ShellExecute(0, 'open', PChar('C:\Windows\System32\osk.exe'), nil, nil, SW_SHOWNORMAL);
两者都可以在 Windows XP 上运行,但在 Windows 10 上失败。我发现碎片整理应用程序的名称已更改为 dfrgui.exe,但更新代码并没有帮助。在 Windows 10 上,屏幕键盘仍称为 osk.exe。
这两个应用程序都可以手动/直接从命令行启动,或者在 Windows 资源管理器中双击它们。
我怀疑 Windows 安全性阻止我的应用程序从 C:\Windows\System32 启动任何东西,因为我可以从 Program Files 和 C:\Windows 启动其他几个应用程序。
谁能帮忙?
【问题讨论】:
-
您应该使用
ShellExecuteEx()而不是ShellExecute(),Ex版本提供了更好的错误报告。特别是在运行 EXE 文件时,您应该使用CreateProcess()而不是ShellExecute/Ex()。这些都不能解决您的问题,这只是一般遵循的良好编程实践。 -
嗯,不过是你can't use
CreateProcess()to runosk.exe。它必须使用ShellExecute/Ex()运行。