乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 19|回复: 0

在大家的启示下做了一个查找acad安装路径的程序(不启动acad)

[复制链接]

12

主题

31

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
79
发表于 2003-7-24 08:51:00 | 显示全部楼层 |阅读模式
‘在大家的启示下做了一个查找acad安装路径的程序(不启动acad)
'vb5.0,需要用到一个类:clsreg,附后(用于对注册表进行操作)
’*************************************
'得到的路径
'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 lBuf  As 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  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
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 20:03 , Processed in 0.529341 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表