Re: Modify Registry



Changes to get it working.

Add a constant. const HKEY_LOCAL_MACHINE = &H80000002
Correct the key path. Windows NT not WindowsNT
Removed redundant lines

Dim ComputerName
const HKEY_LOCAL_MACHINE = &H80000002 ' you have to set this value
'strComputer = InputBox("Please Enter a preferred computer name:")
strComputer = "x"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
strValueName = "AutoAdminLogon"
strValue = "0"

' Create key to use
Return = objReg.CreateKey(HKEY_LOCAL_MACHINE, strKeyPath)
If (Return = 0) And (Err.Number = 0) Then
Wscript.Echo "HKEY_LOCAL_MACHINE\Software\MyKey created"

' write string value to key
Return = objReg.SetStringValue( _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue)
WScript.Echo SetStringValue
If (Return = 0) And (Err.Number = 0) Then
Wscript.Echo "HKEY_LOCAL_MACHINE\Software\MyKey" & _
" contains 'string value'"
Else
Wscript.Echo "SetStringValue failed. Error = " & Err.Number
End If
Else
Wscript.Echo "CreateKey failed. Error = " & Err.Number
End If
'End

Try something like this
===============================================================
' ------ SCRIPT CONFIGURATION ------
const HKLM = &H80000002
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
strComputer = "." ' e.g. serv01 (use "." for local server)
dim a(3,2) ' use array to store data
a(0,0) = "AutoAdminLogon"
a(0,1) = "0"
a(1,0) = "DefaultUserName"
a(1,1) = "username"
a(2,0) = "DefaultPassword"
a(2,1) = "password"
' ------ END CONFIGURATION ---------

set objReg = GetObject("winmgmts:\\" & strComputer &
"\root\default:StdRegProv")


intRC = objReg.CreateKey(HKLM, strKeyPath)
if intRC <> 0 then
WScript.Echo "Error creating key: " & intRC
else
WScript.Echo "Successfully created key " & strKeyPath
end if

For i = 0 to 2
intRC = objReg.SetStringValue(HKLM, strKeyPath, a(i,0), a(i,1))
if intRC <> 0 then
WScript.Echo "Error setting value: " & intRC
else
WScript.Echo "Successfully set value: " & a(i,0)
end if
Next

======================================================


Regards
Mark Dormer



"Rick" <drummer10980@xxxxxxxxx> wrote in message
news:bf060c8a-e83f-4e98-8d8f-e578aad649e8@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Not sure if this is the right forum for my question, but here is goes.
I'm trying to remotely change a registry key. Below is my script and I
cannot get it to change

1. The AutoAdminLogon for 1 to 0.
2. Then change back the AutoAdminLogon to 1 and change the
DefaultUserName to Admin1.


thanks in advance
rick

Dim ComputerName
'====================================================================


'ComputerName = InputBox("Please Enter a preferred computer
name:")
ComputerName = "Computer1"
strComputer = ComputerName

'====================================================================


Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer
& "\root\cimv2")
'====================================================================


Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")

'==================================================

strKeyPath = "SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon"
KeyPath = "SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon"
strValueName = "AutoAdminLogon"
strValue = "0"



' Create key to use
Return = objReg.CreateKey(HKEY_LOCAL_MACHINE, KeyPath)
If (Return = 0) And (Err.Number = 0) Then
Wscript.Echo "HKEY_LOCAL_MACHINE\Software\MyKey created"

' write string value to key
Return = objReg.SetStringValue( _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue)
WScript.Echo SetStringValue
If (Return = 0) And (Err.Number = 0) Then
Wscript.Echo "HKEY_LOCAL_MACHINE\Software\MyKey" & _
" contains 'string value'"
Else
Wscript.Echo "SetStringValue failed. Error = " & Err.Number
End If
Else
Wscript.Echo "CreateKey failed. Error = " & Err.Number
End If


.



Relevant Pages

  • [NT] Norton Anti-Virus VB Scripting Vulnerability
    ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... Set objRegistry = ... objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, ...
    (Securiteam)
  • Re: Error 0x8007043B after XP SP2
    ... objReg.GetMultiStringValue HKLM, strKeyPath, strValueName, arrValues ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.windowsupdate)
  • Why GetStringValue return NULL?
    ... Here is code snippet digest from "The Portable Script Center", ... strKeyPath = "Console" ... strValueName = "HistoryBufferSize" ... it can't output string value. ...
    (microsoft.public.scripting.vbscript)
  • Why GetStringValue return NULL?
    ... Here is code snippet digest from "The Portable Script Center", ... strKeyPath = "Console" ... strValueName = "HistoryBufferSize" ... it can't output string value. ...
    (microsoft.public.scripting.wsh)
  • Re: Why GetStringValue return NULL?
    ... Here is code snippet digest from "The Portable Script Center", ... strKeyPath = "Console" ... strValueName = "HistoryBufferSize" ... it can't output string value. ...
    (microsoft.public.scripting.wsh)