明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1817|回复: 0

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

[复制链接]
发表于 2003-7-24 08:51:00 | 显示全部楼层 |阅读模式
‘在大家的启示下做了一个查找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 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 < 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威望 +1 金钱 +10 贡献 +5 激情 +5 收起 理由
mccad + 1 + 10 + 5 + 5 【好评】好函数

查看全部评分

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-28 14:35 , Processed in 0.260213 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表