English 中文(简体)
Prevent windows from queuing shellexecute requests
原标题:
  • 时间:2009-11-18 19:45:47
  •  标签:
  • winapi
  • vb6
Win.ShellExecute 0, "open", "C:dirprogram.exe", "arguments", vbNullString, SW_SHOWNORMAL
Win.ShellExecute 0, "open", "http://www.google.com", vbNullString, vbNullString, SW_SHOWNORMAL

I want google.com to open regardless of whether or not program.exe is still running. How do I fix this? I would rather avoid things like calling "start."

Both of these calls happen pretty much instantly, and the VB program continues running. However, on both Vista and XP, google.com does not open until program.exe closes. If the application which called shellexecute closes before program.exe closes, google.com will still open once program.exe is closed.

Note:

I have found that having program.exe call doevents every 100ms or so fixes the problem, but obviously this is somewhat of a hack.

Note2: Below is an example implementation of program.exe. Yes, I realize that changing program.exe will fix this (i.e. adding a doevents call).

Option Explicit    
Public Sub Main()
    Do Until False
        Sleep 100
    Loop
End Sub
问题回答

I think you might have to use CreateProcess instead?

You may want to use the Process API rather than ShellExecute

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 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

If you need to halt until it is done you this

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

The code to use look something like this

ReturnValue = CreateProcess(NullString, AppPathString, ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, NullString, StartupInformation, ProcessInformation)
Do While WaitForSingleObject(ProcessInformation.hProcess, 0) <> 0
    DoEvents
Loop

Have you tried using the intrinsic Shell to launch Program.exe, rather than ShellExecute? (I m assuming Win.ShellExecute is the API call of the same name - you could include the declaration in your question.)

Also, tyranid is right that giving your application a form may solve the problem. I ve had odd behaviour from VB6 apps with no forms.





相关问题
Prevent windows from queuing shellexecute requests

Win.ShellExecute 0, "open", "C:dirprogram.exe", "arguments", vbNullString, SW_SHOWNORMAL Win.ShellExecute 0, "open", "http://www.google.com", vbNullString, vbNullString, SW_SHOWNORMAL I want google....

Why is My Loop Only Deleting One File?

Using VB6 In a folder, i have n number of files, i want to delete a 0 kb files code Dim filename5 As String filename5 = Dir$(txtsourcedatabasefile & "*_*", vbDirectory) MsgBox filename5 Do ...

How to check the filesize?

Using VB6 I have the text file with different sizes, so i want to delete the file where filesize = 0 kb. How to make a vb6 code for deleting the 0 kb files. Need vb6 code Help

File Rename problem?

I m using VB6 and I have a folder where I have n number of files. I want to change the file extension to .txt. I used the code below to change the extension of all .fin files to .txt. Dim filename1 ...

Error 20728-F while in using Crystal Reports in VB6

I m using Crystal Reports in my VB6 project, but I m facing error while loading the report in crystalreport1.action=1; Please give me some solution for this problem. It is showing the error as Error ...

DllRegisterServer entry point was not found

When running my vb6 application I am getting error like, runtime error 53 : file not found: rscomclNoMsg.dll then i tried to register that dll from cmd line using regsvr32. Then I am getting ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签