Add account to TS (VBScript)

This code can be found in Chapter 17 of Windows Server 2003 Security Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' This code adds a user, group, or computer to Terminal Services
' ------ SCRIPT CONFIGURATION ------
Const WINSTATION_GUEST_ACCESS = 0
Const WINSTATION_USER_ACCESS  = 1
Const WINSTATION_ALL_ACCESS   = 2  

strComputer = "."
strAccount = "srv01\rallen"
intPerm = WINSTATION_USER_ACCESS
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colItems = objWMI.ExecQuery("Select * from Win32_TSPermissionsSetting")
for each objItem in colItems
   intRC = objItem.AddAccount(strAccount, intPerm)
   if intRC then
      WScript.Echo "Error adding " & strAccount & " to " & _
                   objItem.TerminalName
   else
      WScript.Echo "Successfully added " & strAccount & " to " & _
                   objItem.TerminalName
   end if 
next

This code has been viewed 960 times.

New from the creators of TechTasks.com: StatSheet.com