在大家的启示下做了一个查找acad安装路径的程序(不启动acad)
‘在大家的启示下做了一个查找acad安装路径的程序(不启动acad)'vb5.0,需要用到一个类:clsreg,附后(用于对注册表进行操作)
’*************************************
'得到autocad的路径
'AcadMainVer: R14.0,R15.0(2002),R16.0(2004)
‘****************************************
Function getAcadLocation(ByVal AcadMainVer As String) As String
Dim reg As New clsReg
Dim CurVer As String
CurVer = reg.GetString(&H80000002, "SOFTWARE\AUTODESK\AUTOCAD\" & AcadMainVer, "CurVer")
If CurVer <> "" Then
getAcadLocation = reg.GetString(&H80000002, "SOFTWARE\AUTODESK\AUTOCAD\" & AcadMainVer & "\" & CurVer, "AcadLocation")
End If
End Function
'clsreg类:用于对注册表进行操作
' -----------------
' ADVAPI32
' -----------------
' function prototypes, constants, and type definitions
' for Windows 32-bit Registry API
'Private Const HKEY_CLASSES_ROOT = &H80000000
'Private Const HKEY_CURRENT_USER = &H80000001
'Private Const HKEY_LOCAL_MACHINE = &H80000002
'Private Const HKEY_USERS = &H80000003
'Private Const HKEY_PERFORMANCE_DATA = &H80000004
Private Const ERROR_SUCCESS = 0&
' Registry API prototypes
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Const REG_SZ = 1 ' Unicode nul terminated string
Private Const REG_DWORD = 4 ' 32-bit number
Public Sub SaveKey(Hkey As Long, strPath As String)
Dim keyhand&
R = RegCreateKey(Hkey, strPath, keyhand&)
R = RegCloseKey(keyhand&)
End Sub
Public Function GetString(Hkey As Long, strPath As String, strValue As String)
Dim keyhand As Long
Dim lValueType As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
R = RegOpenKey(Hkey, strPath, keyhand)
lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
GetString = Left$(strBuf, intZeroPos - 1)
Else
GetString = strBuf
End If
End If
End If
End Function
Public Sub SaveString(Hkey As Long, strPath As String, strValue As String, strdata As String)
Dim keyhand As Long
Dim R As Long
R = RegCreateKey(Hkey, strPath, keyhand)
R = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
R = RegCloseKey(keyhand)
End Sub
Public Function GetDword(ByVal Hkey As Long, ByVal strPath As String, ByVal strValueName As String) As Long
Dim lResult As Long
Dim lValueType As Long
Dim lBufAs Long
Dim lDataBufSize As Long
Dim R As Long
Dim keyhand As Long
R = RegOpenKey(Hkey, strPath, keyhand)
' Get length/data type
lDataBufSize = 4
lResult = RegQueryValueEx(keyhand, strValueName, 0&, lValueType, lBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
If lValueType = REG_DWORD Then
'If lBuf < 0 Then '变成正数
' GetDword = lBuf + 4294967296#
'Else
GetDword = lBuf
'End If
End If
'Else
' Call errlog("GetDWORD-" & strPath, False)
End If
R = RegCloseKey(keyhand)
End Function
Public Sub SaveDword(ByVal Hkey As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
Dim lResult As Long
Dim keyhand As Long
Dim R As Long
R = RegCreateKey(Hkey, strPath, keyhand)
lResult = RegSetValueEx(keyhand, strValueName, 0&, REG_DWORD, lData, 4)
'If lResult <> error_success Then Call errlog("SetDWORD", False)
R = RegCloseKey(keyhand)
End Sub
Public Sub DeleteKey(ByVal Hkey As Long, ByVal strKey As String)
Dim R As Long
R = RegDeleteKey(Hkey, strKey)
End Sub
Public Sub DeleteValue(ByVal Hkey As Long, ByVal strPath As String, ByVal strValue As String)
Dim keyhand As Long
R = RegOpenKey(Hkey, strPath, keyhand)
R = RegDeleteValue(keyhand, strValue)
R = RegCloseKey(keyhand)
End Sub
页:
[1]