解决了立即给分

解决方案 »

  1.   

    看看这个,你试试吧,我是没成功:
    http://expert.csdn.net/Expert/topic/2374/2374876.xml?temp=.7962
      

  2.   

    Const REG_SZ = 1
    Const REG_BINARY = 3
    Const REG_DWORD = 4Const HKEY_CURRENT_USER = &H80000001
    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 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 LongFunction RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String
        Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
        
        lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
        If lResult = 0 Then
            If lValueType = REG_SZ Then
        
                strBuf = String(lDataBufSize, Chr$(0))
                'retrieve the key's value
                lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
                If lResult = 0 Then
        
                    RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
                End If
            ElseIf lValueType = REG_BINARY Then
                Dim strData As Integer
                'retrieve the key's value
                lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
                If lResult = 0 Then
                    RegQueryStringValue = strData
                End If
             ElseIf lValueType = REG_DWORD Then
                lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
                If lResult = 0 Then
                    RegQueryStringValue = strData
                End If
                
            End If
        End If
    End FunctionFunction GetString(hKey As Long, strPath As String, strValue As String)
        Dim Ret
        RegOpenKey hKey, strPath, Ret
        GetString = RegQueryStringValue(Ret, strValue)
        RegCloseKey Ret
    End FunctionSub SaveStringWORD(hKey As Long, strPath As String, strValue As String, strData As String)
        Dim Ret
        RegCreateKey hKey, strPath, Ret
        RegSetValueEx Ret, strValue, 0, REG_DWORD, CLng(strData), 4
        RegCloseKey Ret
    End Sub
    Sub DelSetting(hKey As Long, strPath As String, strValue As String)
        Dim Ret
        RegCreateKey hKey, strPath, Ret
        RegDeleteValue Ret, strValue
        RegCloseKey Ret
    End SubPrivate Sub Check1_Click()
        SaveStringWORD HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableTaskMgr", Val(Check1.Value)
    End SubPrivate Sub Check2_Click()
        SaveStringWORD HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\Explorer", "NoLogoff", Val(Check2.Value)
    End Sub
    Private Sub Check3_Click()
         SaveStringWORD HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\Explorer", "NoClose", Val(Check3.Value)
    End Sub
    Private Sub Check4_Click()
        SaveStringWORD HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableLockWorkstation", Val(Check4.Value)
    End SubPrivate Sub Check5_Click()
        SaveStringWORD HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableChangePassword", Val(Check5.Value)
    End SubPrivate Sub Command1_Click()
        Unload Me
        Set Form1 = Nothing
    End SubPrivate Sub Form_Load()
        
        On Error Resume Next ' Coz the following Code will generate Error if the Entries are not found in registry  Run time error '13' type mismatch
        Check1.Value = GetString(HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableTaskMgr")
        Check2.Value = GetString(HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\Explorer", "NoLogoff")
        Check3.Value = GetString(HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\Explorer", "NoClose")
        Check4.Value = GetString(HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableLockWorkstation")
        Check5.Value = GetString(HKEY_CURRENT_USER, "software\microsoft\windows\currentversion\policies\system", "DisableChangePassword")
    End Sub