我有一个在 Vista 上运行的旧版 VB6 可执行文件。此可执行文件将另一个旧版 MFC C++ 可执行文件脱壳。
在我们早期的 Vista 测试中,此调用将显示典型的 UAC 消息,以在运行第二个可执行文件之前获得用户的许可。这并不完美,但可以接受。但是,现在看起来这个调用被操作系统完全忽略了。
我该怎么做才能使这个电话正常工作?
我有一个在 Vista 上运行的旧版 VB6 可执行文件。此可执行文件将另一个旧版 MFC C++ 可执行文件脱壳。
在我们早期的 Vista 测试中,此调用将显示典型的 UAC 消息,以在运行第二个可执行文件之前获得用户的许可。这并不完美,但可以接受。但是,现在看起来这个调用被操作系统完全忽略了。
我该怎么做才能使这个电话正常工作?
如果在计算机上禁用了 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