Mets ca dans un module :
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" _
(ByVal lpAppName As String, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal sResult As String) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
(ByVal nSize As Long, _
ByVal lpBuffer As String) As Long
Private Const NORMAL_PRIORITY_CLASS As Long = &H20
Private Const STARTF_USESHOWWINDOW As Long = &H1
Private Const SW_SHOWNORMAL As Long = 1
Private Const MAX_PATH As Long = 260
Private Const ERROR_FILE_SUCCESS As Long = 32 'my constant
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
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadID As Long
End Type
Public Function StartNewBrowser(sURL As String) As Boolean
Dim success As Long
Dim hProcess As Long
Dim sBrowser As String
Dim start As STARTUPINFO
Dim proc As PROCESS_INFORMATION
sBrowser = GetBrowserName(success)
If success >= ERROR_FILE_SUCCESS Then
With start
.cb = Len(start)
.dwFlags = STARTF_USESHOWWINDOW
.wShowWindow = SW_SHOWNORMAL
End With
success = CreateProcess(sBrowser, " " & sURL, 0&, 0&, 0&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
StartNewBrowser = proc.hProcess <> 0
Call CloseHandle(proc.hProcess)
Call CloseHandle(proc.hThread)
End If
End Function
Private Function GetBrowserName(dwFlagReturned As Long) As String
Dim hFile As Long
Dim sResult As String
Dim sTempFolder As String
sTempFolder = GetTempDir()
hFile = FreeFile
Open sTempFolder & "Bidon.html" For Output As #hFile
Close #hFile
sResult = Space$(MAX_PATH)
dwFlagReturned = FindExecutable("Bidon.html", sTempFolder, sResult)
Kill sTempFolder & "Bidon.html"
GetBrowserName = TrimNull(sResult)
End Function
Private Function TrimNull(Item As String)
Dim pos As Integer
pos = InStr(Item, Chr(0))
If pos Then
TrimNull = Left(Item, pos - 1)
Else
TrimNull = Item
End If
End Function
Private Function GetTempDir() As String
Dim tmp As String
tmp = Space(MAX_PATH)
Call GetTempPath(Len(tmp), tmp)
GetTempDir = TrimNull(tmp)
End Function
Et ca dans ta form
Private Sub Command1_Click()
StartNewBrowser ("http://vbfrance.com/")
End Sub