Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a script that modifies registry 1

Status
Not open for further replies.

raiden69

MIS
Sep 7, 2015
5
ZA
Hi, i am teaching myself vb-script using a self paced guide.
I wrote this to modify registry entries on machines listed in a text file. my problem is that it only modifies the registry of the machine i am running it from(this machine is also listed in the computers.txt file). The modification does not refelect on the other machines.Any feedback appreciated.
Script:

Const INPUT_FILE_NAME = "C:\Scripts\Computers.txt" Const FOR_READING = 1 Set objFSO = CreateObject("Scripting.FilesystemObject") Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING) Dim mykey
strComputers = objFile.ReadAll objFile.Close
arrComputers = Split(strComputers, vbCrLf)

For Each strComputer In arrComputers
Set WshShell = CreateObject("WScript.Shell")
myKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\fDenyTSConnections"
WshShell.RegWrite myKey,0,"REG_DWORD"
Set WshShell = Nothing
Next
 
You might like to note that the RegWrite method has no capability for writing to the registry of anything apart from the local computer.

What you really need to look at is the WMI-provided registry functions, which do have the capability to write to a remote registry (provided you have the correct permissions).

So, assuming that your first bit of code, getting the computernames into an array is correct:

Code:
[blue]Const HKEY_LOCAL_MACHINE = &H80000002

strKeyPath = "SYSTEM\CurrentControlSet\Control\Terminal Server\"
strValuename = "fDenyTSConnections"
lValue = 0

For Each strComputer In arrcomputers
    Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, strValuename, lValue
Next[/blue]

 
Excellent, I did not know that.
I will give it a try and let you know if it worked.
 
Excellent Advice.
Initially the script failed after i modified it. The reason for this was because of the firewall being on.
After i took it off, it executed flawlessly.

Thanks again for your advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top