par oguruma » 26 Déc 2004 à 01:16
Glaner sur le net...
- Code : Tout sélectionner
' ShellCommand.lss
'
' Time-stamp: <2002-05-02 21:19:01 Administrator>
'
' Date Author Changes
' ---------- --------------- ------------------------------------
' 2002-02-03 Daniel Eriksson Created
' 2002-05-02 Daniel Eriksson Added parameter for visibility
'
Option Explicit
'/* STARTUPINFO structure */
' Use this flag if you want to be able to control window apperance.
Private Const STARTF_USESHOWWINDOW = 1
'#define STARTF_USEPOSITION (4)
'#define STARTF_USESIZE (2)
'#define STARTF_USECOUNTCHARS (8)
'#define STARTF_USEFILLATTRIBUTE (16)
'#define STARTF_RUNFULLSCREEN (32)
'#define STARTF_FORCEONFEEDBACK (64)
'#define STARTF_FORCEOFFFEEDBACK (128)
'#define STARTF_USESTDHANDLES (256)
'#define STARTF_USEHOTKEY (512)
'/* ShowWindow */
Private Const SW_HIDE = 0
'#define SW_MAXIMIZE (3)
'#define SW_MINIMIZE (6)
'#define SW_NORMAL (1)
'#define SW_RESTORE (9)
'#define SW_SHOW (5)
'#define SW_SHOWDEFAULT (10)
'#define SW_SHOWMAXIMIZED (3)
'#define SW_SHOWMINIMIZED (2)
'#define SW_SHOWMINNOACTIVE (7)
'#define SW_SHOWNA (8)
'#define SW_SHOWNOACTIVATE (4)
'#define SW_SHOWNORMAL (1)
'#define WPF_RESTORETOMAXIMIZED (2)
'#define WPF_SETMINPOSITION (1)
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
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
Declare Private Function WaitForSingleObject Lib "kernel32" (Byval _
hHandle As Long, Byval dwMilliseconds As Long) As Long
Declare Private Function CreateProcessA Lib "kernel32" (Byval _
lpApplicationName As Long, 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
Declare Private Function CloseHandle Lib "kernel32" (Byval _
hObject As Long) As Long
Public Class ShellCommand
' This class is used to execute external applications. As opposed to
' the Shell function, this class waits for execution to finish before it
' returns. It also (optionally) completely hides the external application
' from the user.
'
' Usage:
' Dim hidden As Variant
' hidden = False
' Dim cmd As New ShellCommand("notepad.exe", hidden)
' cmd.execute("")
'
Private m_executable As String
Private m_hidden As Variant
Sub New(Byval executable As String, hidden As Variant)
m_executable = executable
m_hidden = hidden
End Sub
Sub execute(Byval parameters As String)
Dim RetVal As Long
Dim proc As PROCESS_INFORMATION
Dim StartInf As STARTUPINFO
If (m_hidden) Then
StartInf.dwFlags = STARTF_USESHOWWINDOW
StartInf.wShowWindow = SW_HIDE
StartInf.cb = Len(StartInf)
End If
Dim cmd_line As String
cmd_line = m_executable & " " & parameters
RetVal = CreateProcessA(0&, cmd_line, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, StartInf, proc)
RetVal = WaitForSingleObject(proc.hProcess, INFINITE)
RetVal = CloseHandle(proc.hProcess)
End Sub
End Class
Bien à vous
http://www.dominoarea.org/oguruma/
Les téléphones PORTABLES dans les TGV y en a MARRRE de ces voyageurs qui ne respectent pas les autres ! ARRET DES PORTABLES SVP - Merci
Fumeurs ! respectez les non fumeurs !!!
Fumeurs ! respectez la loi de février 2007 et les lieux publics !!! (ie. hall de gares)