Scripting Question

VBscript to list all Remote Desktop User in Registry

04/15/2020 295 views

I am new to VBscript and trying to create a script to  list all Remote Desktop User in Registry...

The below script works but it overwrites each Remote Desktop User and shows only last user in the registry...

Could you please help to get all users in one key (separated by , ,)

For e.g

HKEY_CURRENT_USER\MFS\RDUsers\LocalAdmin = User1,User2,User3.....


Dim wshShell, LogPath1, objFSO, objFile, TextFile

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set wshShell = CreateObject( "WScript.Shell" )

Set objNetwork = CreateObject("WScript.Network")

strComputer = objNetwork.ComputerName

strUser = objNetwork.UserName

strGroup = "Remote Desktop Users"

Set objFile = objFSO.CreateTextFile(TextFile,True)

Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")

for each objMember In objGroup.Members

Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")

wshShell.RegWrite "HKEY_CURRENT_USER\MFS\RDUsers\LocalAdmin", objMember.Name , "REG_SZ"


0 Comments   [ + ] Show comments


All Answers


I'm not going to do the work for you but I will prompt your thought process.

Delete the second 'Set  objGroup...' line, it's just repeating the one 2 lines above it.

Then think about what's happening in the 'For Each...' loop., when the .RegWrite executes.

Next, use either an array or a dictionary - whch ever you're more comfortable with - to hold the results as the loop runs and THEN do the .RegWrite.

Lastly, I appreciate this is only a shell but you must, must, MUST error-trap EVERYTHING! Assume that NOTHING will work. For example, did the objFSO object get created? Having said that, endless pages of "if Err.Number <> 0 Then..." gets very tedious so have a search for the excellent BugAssert code and add that to your scriots.

Answered 04/16/2020 by: VBScab
Red Belt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ