Problem med en ShellAndWait ting
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal hProcess As Long, ByVal lType As Long) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = -1&
Private Sub Form_Load()
If Dir("c:\Program Files\EA GAMES\Battlefield 1942\Mods\bf1942\Settings\*.*") <> "" Then
DelDir ("c:\Program Files\EA GAMES\Battlefield 1942\Mods\bf1942\Settings")
End If
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFolder "\\iso\public\launching\bf1942\Settings", "c:\Program Files\EA GAMES\Battlefield 1942\Mods\bf1942\Settings"
Set fso = Nothing
MsgBox "debug: Kopiering færdig"
Shell "c:\Program Files\d-tools\daemon.exe -mount 1,""\\iso\public\iso2\bf1942-cd1.ccd"""
ShellAndWait "c:\Program Files\EA GAMES\Battlefield 1942\BF1942.exe", "C:\Program Files\EA GAMES\Battlefield 1942", "", vbMaximizedFocus
Unload battlefield
End Sub
Private Sub ShellAndWait(ByVal program_name As String, ByVal program_dir As String, ByVal program_parametres As String, _
ByVal window_style As VbAppWinStyle)
Dim process_id As Long
Dim process_handle As Long
' Start the program.
On Error GoTo ShellError
process_id = ShellExecute(Me.hwnd, "open", program_name, program_parametres, program_dir, SW_SHOWNORMAL)
On Error GoTo 0
' Hide.
Me.Visible = False
DoEvents
' Wait for the program to finish.
' Get the process handle.
process_handle = OpenProcess(SYNCHRONIZE, 0, process_id)
If process_handle <> 0 Then
WaitForSingleObject process_handle, INFINITE
CloseHandle process_handle
End If
' Reappear.
Me.Visible = True
Exit Sub
ShellError:
MsgBox "Error: Couldn't Start - " & _
txtProgram.Text & vbCrLf & _
Err.Description, vbOKOnly Or vbExclamation, _
"Error"
End Sub
Public Function DelDir(Path As String) As Boolean
Dim FileName As String
Dim Files As Collection
Dim I As Integer
Set Files = New Collection
If Right(Path, 1) = "\" Then
Path = Left(Path, Len(Path) - 1)
End If
FileName = Dir(Path & "\*.*", vbNormal Or vbReadOnly Or vbHidden Or _
vbSystem Or vbArchive Or vbDirectory)
Do While Len(FileName) > 0
If (FileName <> "..") And (FileName <> ".") Then
Files.Add Path & "\" & FileName
End If
FileName = Dir()
DoEvents
If Canceled Then
DelDir = False
Exit Function
End If
Loop
For I = 1 To Files.Count
FileName = Files(I)
If GetAttr(FileName) And vbDirectory Then
DelDir FileName
Else
SetAttr FileName, vbNormal
Kill FileName
End If
DoEvents
If Canceled Then
DelDir = False
Exit Function
End If
Next
If Len(Path) > 2 Then
RmDir Path
End If
DelDir = True
End Function