|
Trouver une ressource
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 du même auteur
Sources de la même categorie
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Acces ODBC [ par joel ]
bonjourj'ai créer un DSN pour accéder à une base oracle. Lorsque je passe parun utilitaire oracle, je peux lire, créer en passant par le DSN... mais e
probleme de creation de DSN (ODBC) [ par macflyFR ]
bonjour, jai pris sur le site support.microsoft.com, le code pour creer un dsn en vb.ca marche bien mais j'ai qd meme un parametre que je voudrai chan
Avis aux pros du MySQL [ par tbbuim1 ]
Salut à tous, J'ai la version 4.1.8 de MySQL J'ai installé l'ODBC drivers pour windows MyODBC J'ai créé un DSN et je l'ai app
DSN System ODBC [ par eldim ]
Bonjour,Comment via vb, peut on configurer un DSN system sans avoir à écrire l'ODBC.ini + le registre ?y a-t-il des API ?-- Pourquoi faire simple quan
Liste des DSN disponibles en ODBC [ par senpiet ]
Bonjour,je cherche à savoir comment on peut obtenir la liste des System DSN disponibles sur la machine, en vue de les mettre dans un combobox Visual B
help problème avec sql et vbscript [ par remy34 ]
Bonjour je voudrais en fait rajouter les champs d'un formulaire lors de la validation de celui ci mais je n'y arrive pas voici mon code: Sub Envoyer(
Création d'un DSN ODBC [ par yanthorp ]
Slt les gars, j'ai un soucis. Ben voilà je souhaite créer un DSN ODBC sur une base de donnée interbase à partir du code en Visual Basic 6.0. J'e me su
Création d'un DSN ODBC [ par yanthorp ]
Slt les gars, j'ai un soucis. Ben voilà je souhaite créer un DSN ODBC sur une base de donnée interbase à partir du code en Visual Basic 6.0. J'e me su
Interface graphique WinXP (.Net) [ par kiboumz ]
Bonjour, j'aimerais savoir s'il y a une façon d'avoir en vb.net une interface graphique qui est pareil comme celle de XP, car pour l'instant, si
odbc [ par joel599 ]
j ai prob qd je pose un data control pour excel ca me dit "couldn't installable pilote isam" je cherche donc le pilote odbc approprier au fait j ai e
|
Téléchargements
Logiciels à télécharger sur le même thème :
|