Vista不允许一个.exe调用另一个.exe
时间:2020-03-06 14:34:49 来源:igfitidea点击:
我有一个在Vista上运行的旧版VB6可执行文件。此可执行文件包含另一个旧版MFC C ++可执行文件。
在我们早期的Vista测试中,此调用将显示典型的UAC消息,以在运行第二个可执行文件之前获得用户的许可。这不是完美的,但是可以接受的。但是,现在看来该调用已被OS完全忽略。
我该怎么做才能使此通话正常工作?
解决方案
如果在计算机上禁用了UAC,并且该调用将需要提升的特权,则对CreateProcess的调用将失败。确保已启用UAC。
此外,请按照此处的指南向程序添加UAC清单。
这里也对问题和源示例进行了很好的讨论。
在Vista下对我们来说效果很好
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessId As Long dwThreadId As Long End Type Private Type STARTUPINFO cb As Long lpReserved As String lpDesktop As String lpTitle As String dwX As Long dwY As Long dwXSize As Long dwYSize As Long dwXCountChars As Long dwYCountChars As Long dwFillAttribute As Long dwFlags As Long wShowWindow As Integer cbReserved2 As Integer lpReserved2 As Long hStdInput As Long hStdOutput As Long hStdError As Long End Type Dim ProcessInformation As PROCESS_INFORMATION Dim StartupInformation As STARTUPINFO Dim ReturnValue As Long Dim NullString As String Dim AppPathString As String StartupInformation.cb = Len(StartupInformation) ReturnValue = CreateProcess(NullString, AppPathString, ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, NullString, StartupInformation, ProcessInformation) ' 'If you need to wait for the exe to finish ' Do While WaitForSingleObject(ProcessInformation.hProcess, 0) <> 0 DoEvents Loop