|
7#
楼主 |
发表于 2004-7-15 18:41:00
|
只看该作者
模块 modGetSQLInstances- Option Compare Database
- '此模块提供的函数共同执行
- '查找现有的 SQL Server 和计算机名称的任务。
- Private Declare Function OSRegOpenKey Lib "advapi32" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpszSubKey As String, phkResult As Long) As Long
- Private Declare Function OSRegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpszValueName As String, ByVal dwReserved As Long, lpdwType As Long, lpbData As Any, cbData As Long) As Long
- Private Declare Function OSRegCloseKey Lib "advapi32" Alias "RegCloseKey" (ByVal hKey As Long) As Long
- Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" ( _
- ByVal lpBuffer As String, nSize As Long) As Long
- Public Const HKEY_CLASSES_ROOT = &H80000000
- Public Const HKEY_CURRENT_USER = &H80000001
- Public Const HKEY_LOCAL_MACHINE = &H80000002
- Public Const HKEY_USERS = &H80000003
- Private Const ERROR_SUCCESS = 0&
- Private Const REG_SZ = 1
- Private Const REG_BINARY = 3
- Private Const REG_DWORD = 4
- Private Const REG_MULTI_SZ = 7
- '-----------------------------------------------------------
- ' SUB: GetValidSQLInstances
- '
- ' 返回有效的 SQL 实例个数和表示实例列表的字符串
- ' (以空格分隔)。
- '-----------------------------------------------------------
- '
- Public Function GetValidSQLInstances(ByRef sSQLInstances As String, ByRef fIsDefaultSQL7 As Boolean) As Integer
- Dim hKey As Long
- Dim sValue As String
- 'Dim sVerInfo As VERINFO
- Dim i As Integer
- fIsDefaultSQL7 = False
- sSQLInstances = ""
- GetValidSQLInstances = 0
- If RegOpenKey(HKEY_LOCAL_MACHINE, "Software\Microsoft\Microsoft SQL Server", hKey) Then
- RegQueryStringValue hKey, "InstalledInstances", sSQLInstances
- RegCloseKey hKey
- StrConv sSQLInstances, vbUpperCase
- If InStr(1, sSQLInstances, "MSSQLSERVER") Then
- If RegOpenKey(HKEY_LOCAL_MACHINE, "Software\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion", hKey) Then
- RegQueryStringValue hKey, "CurrentVersion", sValue
- RegCloseKey hKey
- 'PackVerInfo sValue, sVerInfo
- 'If sVerInfo.FileVerPart1 = 7 Then
- 'fIsDefaultSQL7 = True
- 'End If
- End If
- End If
- For i = 1 To Len(sSQLInstances)
- If Mid$(sSQLInstances, i, 1) = " " Then
- GetValidSQLInstances = GetValidSQLInstances + 1
- End If
- Next i
- End If
- End Function
- '-----------------------------------------------------------
- ' 函数:RegOpenKey
- '
- ' 打开系统注册表中现有的键。
- '
- ' 返回:如果成功打开该键,则为 True,否则为 False
- ' 如果成功打开,将把 phkResult 设置为该键的句柄。
- '-----------------------------------------------------------
- '
- Public Function RegOpenKey(ByVal hKey As Long, ByVal lpszSubKey As String, phkResult As Long) As Boolean
- Dim lResult As Long
- Dim strHkey As String
- strHkey = strGetHKEYString(hKey)
- lResult = OSRegOpenKey(hKey, lpszSubKey, phkResult)
- If lResult = ERROR_SUCCESS Then
- RegOpenKey = True
- End If
- End Function
- '-----------------------------------------------------------
- ' 函数:RegCloseKey
- '
- ' 关闭打开的注册表键。
- '
- ' 返回:成功完成为 True,否则为 False。
- '-----------------------------------------------------------
- '
- Public Function RegCloseKey(ByVal hKey As Long) As Boolean
- Dim lResult As Long
- lResult = OSRegCloseKey(hKey)
- RegCloseKey = (lResult = ERROR_SUCCESS)
- End Function
- '-----------------------------------------------------------
- '如果是 HKEY,将返回表示该键的
- '文本字符串。
- '-----------------------------------------------------------
- Private Function strGetHKEYString(ByVal hKey As Long) As String
- Dim s
复制代码 |
|