|
begin process at 2008 07 05 07:38:17
Derniers logiciels
|
Trouver une ressource (Nouvelle version du moteur, plus rapide & pertinent, essayez le !)
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
AFFICHER L'INTERFACE ODBC POUR CRÉER UNE SOURCE DE DONNÉE (DSN)
Information sur la source
Description
Permet de créer un DSN en affichant l'interface "Sources de données ODBC" des outils d'administration. Note : l'API "CreateProcess" est préférable à la fonction "Shell".
Source
- Option Explicit
-
- Private Enum udeSW
- SW_HIDE = 0
- SW_NORMAL = 1
- SW_MAXIMIZE = 3
- SW_MINIMIZE = 6
- End Enum
-
- 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 Byte
- hStdInput As Long
- hStdOutput As Long
- hStdError As Long
- End Type
-
- Private Type SECURITY_ATTRIBUTES
- nLength As Long
- lpSecurityDescriptor As Long
- bInheritHandle As Long
- End Type
-
- Private Enum udePriority_Class
- NORMAL_PRIORITY_CLASS = &H20
- IDLE_PRIORITY_CLASS = &H40
- HIGH_PRIORITY_CLASS = &H80
- End Enum
-
- Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, 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 Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
- Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
-
- Private Declare Function GetActiveWindow Lib "user32" () As Long
- Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
- Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
-
- Sub DisplayODBCManager()
- Dim SysDir As String, Ret As Long
-
- SysDir = Space(255)
- Ret = GetSystemDirectory(SysDir, 255)
- SysDir = Left$(SysDir, Ret) & "\"
-
- 'Retourne zéro en cas d'erreur
- If NewProcess(SysDir & "rundll32.exe", "shell32.dll,Control_RunDLL odbccp32.cpl", SW_NORMAL, IDLE_PRIORITY_CLASS) Then
- 'Le formulaire ODBC a été ouvert et fermé. Après vérification en base de registre
- 'de son existence, le DSN peut être utilisé pour tenter d'ouvrir une connexion.
- Else
- 'Echec de l'ouverture du formulaire ODBC
- End If
-
- End Sub
-
- Private Function NewProcess(AppPath As String, Arg As String, ByVal SW_Stat As udeSW, ByVal Priority_Class As udePriority_Class) As Long
-
- Dim PClass As Long
- Dim CmdLine As String
- Dim SInfo As STARTUPINFO
- Dim PInfo As PROCESS_INFORMATION
- Dim Sec1 As SECURITY_ATTRIBUTES
- Dim Sec2 As SECURITY_ATTRIBUTES
- Dim hDC As Long
-
- Const HORZRES = 8
- Const VERTRES = 10
- Const INFINITE = &HFFFF
- Const WAIT_TIMEOUT As Long = 258&
- Const STARTF_USESHOWWINDOW = &H1
- Const STARTF_USEPOSITION = &H4
-
- Sec1.nLength = Len(Sec1)
- Sec2.nLength = Len(Sec2)
- hDC = GetDC(GetActiveWindow())
- With SInfo
- .cb = Len(SInfo)
- .dwX = GetDeviceCaps(hDC, HORZRES) \ 2
- .dwY = GetDeviceCaps(hDC, VERTRES) \ 2
- .dwFlags = STARTF_USEPOSITION Or STARTF_USESHOWWINDOW
- .wShowWindow = SW_Stat
- End With
- PClass = Priority_Class
-
- CmdLine = AppPath
- If (Len(Trim$(Arg)) > 0) Then
- CmdLine = CmdLine & " " & Arg
- End If
-
- NewProcess = CreateProcess(AppPath, CmdLine, Sec1, Sec2, False, PClass, 0&, CurDir$(), SInfo, PInfo)
- If NewProcess Then
- 'Sans rafraîchissement du formulaire parent
- 'WaitForSingleObject pinfo.hProcess, INFINITE
-
- 'Avec rafraîchissement du formulaire parent
- Do While WaitForSingleObject(PInfo.hProcess, 10) = WAIT_TIMEOUT
- DoEvents
- Loop
-
- Call CloseHandle(PInfo.hProcess)
- Call CloseHandle(PInfo.hThread)
- End If
- End Function
Option Explicit
Private Enum udeSW
SW_HIDE = 0
SW_NORMAL = 1
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
End Enum
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 Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Enum udePriority_Class
NORMAL_PRIORITY_CLASS = &H20
IDLE_PRIORITY_CLASS = &H40
HIGH_PRIORITY_CLASS = &H80
End Enum
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, 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 Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
Sub DisplayODBCManager()
Dim SysDir As String, Ret As Long
SysDir = Space(255)
Ret = GetSystemDirectory(SysDir, 255)
SysDir = Left$(SysDir, Ret) & "\"
'Retourne zéro en cas d'erreur
If NewProcess(SysDir & "rundll32.exe", "shell32.dll,Control_RunDLL odbccp32.cpl", SW_NORMAL, IDLE_PRIORITY_CLASS) Then
'Le formulaire ODBC a été ouvert et fermé. Après vérification en base de registre
'de son existence, le DSN peut être utilisé pour tenter d'ouvrir une connexion.
Else
'Echec de l'ouverture du formulaire ODBC
End If
End Sub
Private Function NewProcess(AppPath As String, Arg As String, ByVal SW_Stat As udeSW, ByVal Priority_Class As udePriority_Class) As Long
Dim PClass As Long
Dim CmdLine As String
Dim SInfo As STARTUPINFO
Dim PInfo As PROCESS_INFORMATION
Dim Sec1 As SECURITY_ATTRIBUTES
Dim Sec2 As SECURITY_ATTRIBUTES
Dim hDC As Long
Const HORZRES = 8
Const VERTRES = 10
Const INFINITE = &HFFFF
Const WAIT_TIMEOUT As Long = 258&
Const STARTF_USESHOWWINDOW = &H1
Const STARTF_USEPOSITION = &H4
Sec1.nLength = Len(Sec1)
Sec2.nLength = Len(Sec2)
hDC = GetDC(GetActiveWindow())
With SInfo
.cb = Len(SInfo)
.dwX = GetDeviceCaps(hDC, HORZRES) \ 2
.dwY = GetDeviceCaps(hDC, VERTRES) \ 2
.dwFlags = STARTF_USEPOSITION Or STARTF_USESHOWWINDOW
.wShowWindow = SW_Stat
End With
PClass = Priority_Class
CmdLine = AppPath
If (Len(Trim$(Arg)) > 0) Then
CmdLine = CmdLine & " " & Arg
End If
NewProcess = CreateProcess(AppPath, CmdLine, Sec1, Sec2, False, PClass, 0&, CurDir$(), SInfo, PInfo)
If NewProcess Then
'Sans rafraîchissement du formulaire parent
'WaitForSingleObject pinfo.hProcess, INFINITE
'Avec rafraîchissement du formulaire parent
Do While WaitForSingleObject(PInfo.hProcess, 10) = WAIT_TIMEOUT
DoEvents
Loop
Call CloseHandle(PInfo.hProcess)
Call CloseHandle(PInfo.hThread)
End If
End Function
Conclusion
Bibliographie : http://vbfrance.com/code.aspx?ID=6839 http://windowsxp.mvps.org/rundll32.htm
Historique
- 02 août 2005 14:35:12 :
- Ajout des instructions de fermeture
- 03 août 2005 17:39:12 :
- Code exemple avec / sans rafraîchissement de la fenêtre parent
- 03 août 2005 18:02:02 :
- MAJ du code exemple
- 04 août 2005 16:31:51 :
- ajout pour centrer l'affichage
- 04 août 2005 16:41:54 :
- MAJ
- 05 août 2005 16:18:45 :
- Ajout d'une capture d'écran
Sources de la même categorie
Commentaires
Discussions en rapport avec ce code source
|
CalendriCode
| | | L | M | M | J | V | S | D |
| | 1 | 2 | 3 | 4 | 5 | 6 |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | | | |
|
Téléchargements
Logiciels à télécharger sur le même thème :
|
|