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 RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) _
As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" _
(ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, _
ByVal cbName As Long) As Long
Const ERROR_NO_MORE_ITEMS = 259&
Const ERROR_SUCCESS = 0&
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_PERFORMANCE_DATA_WIN2K_ONLY = &H80000004 '//仅Win2k
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006
'取得HKEY_USERS\S-1-5-21-XXX……的键名
Function GetUserRegKey() As String
Dim hKey As Long
Dim i
Dim Temp As String * 256
If RegOpenKey(HKEY_USERS, "", hKey) = ERROR_SUCCESS Then
While RegEnumKey(hKey, i, Temp, 256) = ERROR_SUCCESS
'因为还存在一个S-1-5-21-XXX……XXX_Classes
If InStr(UCase(Temp), "S-1-5-21-") > 0 And InStr(UCase(Temp), "CLASSES") = 0 Then GetUserRegKey = Temp
i = i + 1
Wend
RegCloseKey hKey
End If
End Function
(ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) _
As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" _
(ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, _
ByVal cbName As Long) As Long
Const ERROR_NO_MORE_ITEMS = 259&
Const ERROR_SUCCESS = 0&
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_PERFORMANCE_DATA_WIN2K_ONLY = &H80000004 '//仅Win2k
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006
'取得HKEY_USERS\S-1-5-21-XXX……的键名
Function GetUserRegKey() As String
Dim hKey As Long
Dim i
Dim Temp As String * 256
If RegOpenKey(HKEY_USERS, "", hKey) = ERROR_SUCCESS Then
While RegEnumKey(hKey, i, Temp, 256) = ERROR_SUCCESS
'因为还存在一个S-1-5-21-XXX……XXX_Classes
If InStr(UCase(Temp), "S-1-5-21-") > 0 And InStr(UCase(Temp), "CLASSES") = 0 Then GetUserRegKey = Temp
i = i + 1
Wend
RegCloseKey hKey
End If
End Function
[本日志由 田草 于 2008-02-22 03:41 PM 编辑]
|
canceri 于 2008-03-19 04:43 AM 发表评论:
强啊!!!好!支持!!!!正需要!
tiancao1001 于 2008-02-22 08:45 PM 发表评论:
@echo off
for /f %%i in ('reg query "hku"^|findstr /c:"S-1-5-21"') do set reg=%%i
set reg=%reg:~11,44%
echo %reg%
pause>nul
田草 于 2008-02-22 05:25 PM 发表评论:
'取得AutoCAD各版本的注册表HKEY_USERS路径
Function GetAutoCAD_RegPath() As String
Dim Temp As String
Temp = Left(ThisDrawing.Application.Version, 4)
Dim Temp1 As String
'路径还只能是"\"而不是"/"
Temp1 = GetUserRegKey + "\Software\Autodesk\AutoCAD\R" & Temp & "\"
Dim hKey As Long
Dim i
Dim Temp2 As String * 256
Temp2 = Space(256)
Dim Temp3 As String
If RegOpenKey(HKEY_USERS, Temp1, hKey) = ERROR_SUCCESS Then
While RegEnumKey(hKey, i, Temp2, 256) = ERROR_SUCCESS
'只有一个子键
'去掉最后一个字符,不知道是什么
Temp3 = Left(Trim(Temp2), Len(Trim(Temp2)) - 1)
GetAutoCAD_RegPath = "HKEY_USERS\" & Temp1 & Temp3 & "\"
i = i + 1
Wend
RegCloseKey hKey
End If
End Function
Function GetAutoCAD_RegPath() As String
Dim Temp As String
Temp = Left(ThisDrawing.Application.Version, 4)
Dim Temp1 As String
'路径还只能是"\"而不是"/"
Temp1 = GetUserRegKey + "\Software\Autodesk\AutoCAD\R" & Temp & "\"
Dim hKey As Long
Dim i
Dim Temp2 As String * 256
Temp2 = Space(256)
Dim Temp3 As String
If RegOpenKey(HKEY_USERS, Temp1, hKey) = ERROR_SUCCESS Then
While RegEnumKey(hKey, i, Temp2, 256) = ERROR_SUCCESS
'只有一个子键
'去掉最后一个字符,不知道是什么
Temp3 = Left(Trim(Temp2), Len(Trim(Temp2)) - 1)
GetAutoCAD_RegPath = "HKEY_USERS\" & Temp1 & Temp3 & "\"
i = i + 1
Wend
RegCloseKey hKey
End If
End Function
发表评论 - 不要忘了输入验证码哦! |