Re: Modify Registry
- From: "Mark Dormer" <markd@xxxxxxxxx>
- Date: Sat, 2 Feb 2008 03:20:46 +1100
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
.
- Prev by Date: Re: To drag a file as parameter to script
- Next by Date: Re: To drag a file as parameter to script
- Previous by thread: Re: behaviour of AddWindowsPrinterConenction method
- Next by thread: Passing variables to command
- Index(es):
Relevant Pages
|
|