Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Ben..
This stuff is so sweet..
I have a pretty good vested interst in this too.
I want to do the following..
When creating or updating a user when the WTS properties are added/changed, it adds in:
- The User info
- Checks for the profile and homedir
- If the homedir does not exist, add the appropriate security to it.
- The security perms for a folder is something that Shawn, Ceej, and I bounced around about year ago.
![[Big Grin]](images/icons/grin.gif) Anyway, here is the code that I have modified.. What I intend to do is to either read in an excel spreadsheet or have it look for a specific domain user group and apply the perms to it. Additionally, we are migrating users (again).. So, these shares will need to be updated with the users on the new domain.
'Nuff rambling, here goes (yes, it is vb code) and we have a port-over to KiX too.
code:
'Use the wtsapi32.dll from VBS
' VB Constant declarations for WTS_CONFIG_CLASS Const WTSUserConfigInitialProgram = &H0 ' string Const WTSUserConfigWorkingDirectory = &H1 ' string Const WTSUserConfigfInheritInitialProgram = &H2 ' DWORD Const WTSUserConfigfAllowLogonTerminalServer = &H3 ' DWORD
' Timeout settings Const WTSUserConfigTimeoutSettingsConnections = &H4 ' DWORD Const WTSUserConfigTimeoutSettingsDisconnections = &H5 ' DWORD Const WTSUserConfigTimeoutSettingsIdle = &H6 ' DWORD
' Client device settings Const WTSUserConfigfDeviceClientDrives = &H7 ' DWORD Const WTSUserConfigfDeviceClientPrinters = &H8 ' DWORD Const WTSUserConfigfDeviceClientDefaultPrinter = &H9 ' DWORD
' Connection settings Const WTSUserConfigBrokenTimeoutSettings = &HA ' DWORD Const WTSUserConfigReconnectSettings = &HB ' DWORD
' Modem settings Const WTSUserConfigModemCallbackSettings = &HC ' DWORD Const WTSUserConfigModemCallbackPhoneNumber = &HD ' string
' Shadow settings Const WTSUserConfigShadowingSettings = &HE ' DWORD
' User Profile settings Const WTSUserConfigTerminalServerProfilePath = &HF ' string
' Terminal Server home directory Const WTSUserConfigTerminalServerHomeDir = &H10 ' string Const WTSUserConfigTerminalServerHomeDirDrive = &H11 ' string Const WTSUserConfigfTerminalServerRemoteHomeDir = &H12 ' DWORD
'************************************************************************* '************************************************************************* Dim TSCFG
Set TSCFG= CreateObject("UserConfig.TSUserConfig") Set oFs = CreateObject("Scripting.FileSystemObject")
' -- Grab the current domain you are running this script from Set WshNetwork = WScript.CreateObject("WScript.Network") TSCFG.Domain = WshNetwork.UserDomain ' -- If you want to manually set this, uncomment the next line and comment the previous two 'TSCFG.Domain = "MYDOMAIN" 'TSCFG.Domain = InputBox("Type The Domain name")
' -- Set the server where the shares reside ShareServer = "SHARESERVER"
Debugger = "_No" 'If you want to see visual results, set this to be "_Yes"
TSCFG.UserName = InputBox("Type a User Name")
If TSCFG.UserName = "" Then WScript.Echo "No UserID input provided. Stopping script now." WScript.Quit (1) End If
'We need to check and if need be create some folders for this user.. ' Capture the name of the server are you adding the share to TextShare = "\\" & ShareServer & "\D" & Chr(36)
' Setting the user$ variable - jdoe$ - Hidden shares don't show when browsing to a server TextUserN = TSCFG.UserName & Chr(36)
' Setting the user1$ variable - jdoe1$ - Hidden shares don't show when browsing to a server ' Why are we using a jdoe1$ ?? This server has other shared drives for local Corporate User too. TextUserNM = TSCFG.UserName & "1" & Chr(36) ' Created for home_dir
' Path for user folders Homedir = TextShare & "\Citrix_Homedir" Profiles = TextShare & "\Citrix_Profiles"
' Now let's create a variable to work with - \\SERVER\users\jdoe ' Directory to save UserProfileDir = Profiles & "\" & TSCFG.UserName
' Check existence for folder If Debugger = "_Yes" Then If oFs.FolderExists(UserProfileDir) Then WScript.Echo "The citrix profiles folder " & UserProfileDir & " already exists." end if end if
UserHomeDir = Homedir & "\" & TSCFG.UserName
' Check existence for folder If Debugger = "_Yes" Then If oFs.FolderExists(UserHomeDir) Then WScript.Echo "The citrix Home_dir folder " & UserHomeDir & vbcrlf & " already exists and we are continuing." end if end if
' Create folder Profiles If Not oFs.FolderExists(UserHomeDir) Then oFs.CreateFolder UserHomeDir
If Not oFs.FolderExists(UserProfileDir) Then oFs.CreateFolder UserProfileDir
' Create share Set FservObj = GetObject("WinNT://" & ShareServer & "/lanmanserver")
If oFs.FolderExists("\\" & ShareServer & "\" & TextUserNM) Then If Debugger = "_Yes" Then WScript.Echo "The share \\" & ShareServer & "\" & TextUserNM & " already exists." & vbcrlf & " Continuing..." end if else ' Create the share for the server jdoe1$ set newshare = FservObj.create("fileshare",TextUserNM) ' Set the path for the share on the server - D:\Users newshare.path = "D:\Citrix_Homedir\" & TSCFG.UserName newshare.setinfo WScript.Echo "The folders for " & TSCFG.UserName & " and share have been created." end if
'-- Query the information for debugging - uncomment the next three lines to see this 'MsgBox TSCFG.QueryUserConfig(WTSUserConfigTerminalServerProfilePath) 'MsgBox TSCFG.QueryUserConfig(WTSUserConfigTerminalServerHomeDir) 'MsgBox TSCFG.QueryUserConfig(WTSUserConfigTerminalServerHomeDirDrive)
'-- Set some information TSCFG.SetUserConfig WTSUserConfigfAllowLogonTerminalServer, 1 TSCFG.SetUserConfig WTSUserConfigTerminalServerProfilePath , "\\" & ShareServer & "\CITRIX_PROFILES\" & TSCFG.UserName TSCFG.SetUserConfig WTSUserConfigTerminalServerHomeDirDrive , "H:" TSCFG.SetUserConfig WTSUserConfigTerminalServerHomeDir , "\\" & ShareServer & "\" & TSCFG.UserName & "1" & chr(36)
WScript.Echo "The User Profile and Home Drive Server have been set for " & vbcrlf & TSCFG.UserName & vbcrlf & " and may take up to an hour to show up."
l = 0 '*** show all settings - documentation; see below! 'For x = 0 To 18 ' MsgBox "setting " & x & " = " & TSCFG.QueryUserConfig(x) 'Next
''' --- Example Code and settings you can use..
'*** change a few settings: 'TSCFG.SetUserConfig WTSUserConfigWorkingDirectory , "c:\workdir" 'TSCFG.SetUserConfig WTSUserConfigInitialProgram , "startup.exe"
'************************************************************************* '*************************************************************************
'*** http://msdn.microsoft.com/library/default.asp?url=/library/en-us/termserv/tsref_9z76.asp
'WTSUserConfigInitialProgram 'A null-terminated string containing the path of the initial program that Terminal Services 'runs when the user logs on. 'If the WTSUserConfigfInheritInitialProgram value is 1, the initial program can be any 'program specified by the client. 'WTSUserConfigfInheritInitialProgram 'WTSUserConfigfInheritInitialProgram value is 1, the initial program can be any program 'specified by the client. 'WTSUserConfigWorkingDirectory 'A null-terminated string containing the path of the working directory for the initial 'program. 'WTSUserConfigfInheritInitialProgram 'A value that indicates whether the client can specify the initial program. Value Meaning '0 The client cannot specify the initial program. The WTSUserConfigInitialProgram string 'indicates the initial program. If you specify a user's initial program, that's the only 'program they can run; terminal server logs off the user when the user exits that program. '1 The client can specify the initial program. 'WTSUserConfigfAllowLogonTerminalServer 'A value that indicates whether the user account is permitted to log on to a terminal server. 'Value Meaning '0 The user cannot logon. '1 The user can logon. 'WTSUserConfigTimeoutSettingsConnections 'A DWORD value that specifies the maximum connection duration, in milliseconds. One minute 'before the connection timeout interval expires, the user is notified of the pending 'disconnection. The user's session is disconnected or terminated depending on the 'WTSUserConfigBrokenTimeoutSettings value. Every time the user logs on, the timer is reset. 'A value of zero indicates the connection timer is disabled. 'WTSUserConfigTimeoutSettingsDisconnections 'A DWORD value that specifies the maximum duration, in milliseconds, that a terminal 'server retains a disconnected session before the logon is terminated. A value of zero 'indicates the disconnection timer is disabled. 'WTSUserConfigTimeoutSettingsIdle 'A DWORD value that specifies the maximum idle time, in milliseconds. If there is no 'keyboard or mouse activity for the specified interval, the user's session is disconnected 'or terminated depending on the WTSUserConfigBrokenTimeoutSettings value. A value of zero 'indicates the idle timer is disabled. 'WTSUserConfigfDeviceClientDrives 'Citrix ICA clients: A value that indicates whether the terminal server automatically 'reestablishes client drive mappings at logon. Value Meaning '0 The server does not automatically connect to previously mapped client drives. '1 The server automatically connects to previously mapped client drives at logon. 'WTSUserConfigfDeviceClientPrinters 'RDP 5.0 clients and Citrix ICA clients: A value that indicates whether the terminal server 'automatically reestablishes client printer mappings at logon. Value Meaning '0 The server does not automatically connect to previously mapped client printers. '1 The server automatically connects to previously mapped client printers at logon. 'WTSUserConfigfDeviceClientDefaultPrinter 'RDP 5.0 clients and Citrix ICA clients: A value that indicates whether the client printer 'is the default printer. Value Meaning '0 The client printer is not the default printer. '1 The client printer is the default printer. 'WTSUserConfigBrokenTimeoutSettings 'A value that indicates what happens when the connection or idle timers expire or when a 'connection is lost due to a connection error. Value Meaning '0 The session is disconnected. '1 The session is terminated. 'WTSUserConfigReconnectSettings 'A value that indicates how a disconnected session for this user can be reconnected. 'Value Meaning '0 The user can log on to any client computer to reconnect to a disconnected session. 'Note that sessions started at clients other than the system console cannot be connected 'to the system console, and sessions started at the system console cannot be disconnected. '1 The user can reconnect to a disconnected session by logging on to the client computer 'used to establish the disconnected session. If the user logs on from a different client 'computer, the user gets a new logon session. 'WTSUserConfigModemCallbackSettings 'Citrix ICA clients: A value that indicates the configuration for dialup connections in which 'the terminal server hangs up and then calls back the client to establish the connection. 'Value Meaning '0 Callback connections are disabled. '1 The server prompts the user to enter a phone number and calls the user back at that phone 'number. You can use the WTSUserConfigModemCallbackPhoneNumber value to specify a default 'phone number. '2 The server automatically calls the user back at the phone number specified by the 'WTSUserConfigModemCallbackPhoneNumber value. 'WTSUserConfigModemCallbackPhoneNumber 'Citrix ICA clients: A null-terminated string containing the phone number to use for callback 'connections. 'WTSUserConfigShadowingSettings 'RDP 5.0 clients and Citrix ICA clients: A value that indicates whether the user session can 'be shadowed. Shadowing allows a user to remotely monitor the on-screen operations of another user. 'Value Meaning '0 Disable '1 Enable input, notify '2 Enable input, no notify '3 Enable no input, notify '4 Enable no input, no notify 'WTSUserConfigTerminalServerProfilePath 'A null-terminated string containing the path of the user's profile for terminal server logon. 'The directory the path identifies must be created manually, and must exist prior to the logon. 'WTSSetUserConfig will not create the directory if it does not already exist. 'WTSUserConfigTerminalServerHomeDir 'A null-terminated string containing the path of the user's home directory for terminal server 'logon. This string can specify a local path or a UNC path (\\machine\share\path). See 'WTSUserConfigfTerminalServerRemoteHomeDir. 'WTSUserConfigTerminalServerHomeDirDrive 'A null-terminated string containing a drive specification (a drive letter followed by a colon) 'to which the UNC path specified in the WTSUserConfigTerminalServerHomeDir string is mapped. 'See WTSUserConfigfTerminalServerRemoteHomeDir. 'WTSUserConfigfTerminalServerRemoteHomeDir 'A value that indicates whether the user's home directory for terminal server logon is a local 'path or a mapped drive letter. Note that this value cannot be used with WTSSetUserConfig. 'Value Meaning '0 The WTSUserConfigTerminalServerHomeDir string contains the local path of the user's terminal 'server logon home directory. '1 The WTSUserConfigTerminalServerHomeDir string contains the UNC path of the user's terminal 'server logon home directory, and the WTSUserConfigTerminalServerHomeDirDrive string contains 'a drive letter to which the UNC path is mapped.
|