Accueil > > > AFFICHER L'INTERFACE ODBC POUR CRÉER UNE SOURCE DE DONNÉE (DSN)
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://win dowsxp.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
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
|
Derniers Blogs
CSDL FUNCTIONCSDL FUNCTION par Matthieu MEZIL
Dans mon post précédent , j'ai utilisé une CSDL Function afin de générer une requête SQL avec un DateDiff utilisant la date courante sur la BD à partir d'une requête LINQ. Dans le cadre de ce post , vous avez probablement remarqué que dans le cadre de plu...
Cliquez pour lire la suite de l'article par Matthieu MEZIL LINQ TO ENTITIESLINQ TO ENTITIES par Matthieu MEZIL
Cette semaine je suis à Montréal en tant que speaker sur Entity Framework pour l'évènement confoo . J'en profite pour remercier les organisateurs de cet évènement de m'avoir fait confiance et Access-IT de m'avoir permis d'y participer. En parallèle, j'ai ...
Cliquez pour lire la suite de l'article par Matthieu MEZIL FAIRE APPARAITRE L'ONGLET 'DéVELOPPEUR' DANS OFFICE 2010FAIRE APPARAITRE L'ONGLET 'DéVELOPPEUR' DANS OFFICE 2010 par neodante
La nouvelle interface d'Office 2010 à amener quelques modifications par rapport à celle de 2007. Certes mineures, ces modifications ont fait disparaître la case à cocher de l'onglet 'Développeur' en première page du panneau du 'bouton Office' (dans Office...
Cliquez pour lire la suite de l'article par neodante [ASTUCE] PATCH POUR MICROSOFT FORUMS NNTP BRIDGE V1[ASTUCE] PATCH POUR MICROSOFT FORUMS NNTP BRIDGE V1 par pierre
Si vous avez téléchargé comme moi Microsoft Forums NNTP Bridge V1 avant le 11 mars 2010 (voir [Astuce] Disponibilité de Microsoft Forum NNTP Bridge Version 1.0), un problème de date localisée pour les non anglais était présent. Un patch est disponibl...
Cliquez pour lire la suite de l'article par pierre PB LORS DE L'INSTALLATION SHAREPOINT 2010.PB LORS DE L'INSTALLATION SHAREPOINT 2010. par Patrick Guimonet
Lors de l'installation de SharePoint 2010, j'ai rencontré un problème de plantage à l'étape 5 du configuration Wizard. Ca se termine sur cet écran : Et en analysant le fichier de journalisation, on remarque vers la fin des 15000 et quelques lign...
Cliquez pour lire la suite de l'article par Patrick Guimonet
Logiciels
Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods Konvertor (4.00)KONVERTOR (4.00)Le logiciel est un gestionnaire multimedia affichant, jouant et convertissant plus de 2000 format... Cliquez pour télécharger Konvertor
|