2015-12-03 58 views
1

我已经完成了这段代码,但它似乎并不奏效。我不知道为什么。我在谷歌搜索,但没有运气。 :(试图在注册表数据库中创建一个密钥

Set objREG = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") 
Const HKEY_LOCAL_MACHINE = &H80000002 
Dim lstrKeyPath, lstrValueName, lstrValue 
lstrKeyPath = "SOFTWARE\Canon\GARO1\" 
lstrValueName = "LocaleInfo" 
objReg.GetStringValue HKEY_LOCAL_MACHINE,lstrKeyPath,lstrValueName,lstrValue 
msgbox lstrValue <--- This works. 
if IsNull(lstrValue) then 
    lstrKeyPath = lstrKeyPath & lstrValueName 
else 
    lstrValueName = "LocaleTest" 
    lstrKeyPath = "Software\Test\" 
    Return = objReg.CreateKey(HKEY_LOCAL_MACHINE,lstrKeyPath) 
    if Return = 0 Then 
    msgbox "Yes" 
    else 
    msgbox "No" 
    end if 
end if 
Set OBJREG = Nothing 

我看不到我的“测试”键

回答

0

我已经使用了以下检查,并插入注册表项,如果它们不存在注册表:

Dim WshShell, Test, blExists, DQ 
Set WshShell = CreateObject("WScript.Shell") 
DQ = chr(34) 

RegKeyPath = "HKEY_CLASSES_ROOT\LFS\" 
RegValueName = "URL:LFS Protocol" 
Test = RegKeyExists(RegKeyPath,RegValueName) 

If Test = False Then 
    WshShell.RegWrite RegKeyPath, "URL:LFS Protocol" ,"REG_SZ" 
End If 

'Function Returns False if the regkey isnt found otherwise it returns 
'The registry key value specified 
Function RegKeyExists(sRegKey,sRegValueName) 

    On Error Resume Next  

    Dim WSHShellRegTest, Test, blExists 
    Set WSHShellRegTest = CreateObject("WScript.Shell") 

    blTrueFalse = True 

    Test = WSHShellRegTest.RegRead (sregkey + sRegValueName) 

    If Err Then 
     RegKeyExists = False 
     Err.clear 
     Exit Function 
    End if 

    Set WSHShellRegTest = Nothing 

    RegKeyExists = Test 

End Function 
相关问题