Recipe 5.4. Running a Task via a Login ScriptProblemYou want to set the login script for a local or domain user account. SolutionThe following solutions describe how to set the login script for a local user account on a system. Using a graphical user interface
Using a command-line interfaceThe following command sets the login script for a local user: > net user <UserName> /scriptpath:<ScriptName> <ScriptName> should be the relative path of the script from the NETLOGON share. Using VBScript' This code sets the login script for a local user ' ------ SCRIPT CONFIGURATION ------ strComputer = "<ServerName>" strUser = "<UserName>" ' e.g., administrator strLoginScript = "<ScriptName>" ' e.g., login.vbs ' ------ END CONFIGURATION --------- set objUser = GetObject("WinNT://" & strComputer & "/" & strUser & ",user") objUser.LoginScript = strLoginScript objUser.SetInfo WScript.Echo "Set login script for " & objuser.Name The following solutions describe how to set the login script for a domain user account. Using a graphical user interface
Using a command-line interfaceThe following command sets the login script for a domain user: > net user <UserName> /domain /scriptpath:<ScriptName> The following command also sets the login script for a domain user (not available on Windows 2000): > dsmod user "<UserDN>" -loscr <ScriptName> <ScriptName> should be the relative path of the script from the NETLOGON share on the DCs. Using VBScript' This code sets the login script for a local user ' ------ SCRIPT CONFIGURATION ------ strUserDN = "<UserDN>" ' e.g., cn=administrator,cn=users,dc=rallencorp,dc=com strScriptPath = "<ScriptName>" ' e.g., login.vbs ' ------ END CONFIGURATION --------- set objUser = GetObject("LDAP://" & strUserDN) objUser.Put "scriptPath", strScriptPath objUser.SetInfo WScript.Echo "Login script set for " & objUser.Name DiscussionA login script can be a Windows batch file (.bat extension) or anything supported by Windows Scripting Host on the system that runs the script. By default, this includes VBScript and JScript. The login script setting you configure in a user's profile must contain the name of the script and the relative path from the NETLOGON share. When a user (with a local user account) logs into a system, a check is done to see if there is a login script defined for that userlet's say that login.vbs has been configured. The system then attempts to run \\localhost\NETLOGON\login.vbs using the credentials of the user. The default location for the NETLOGON share is %Systemroot%\System32\Repl\Imports\Scripts, but this path doesn't exist on member or workgroup servers. You can either create that directory structure and a NETLOGON share pointing to it, or you can use another directory. In fact, if you have your scripts in a directory called c:\Scripts, you can create the NETLOGON share pointing to that and forgo creating the Repl\Imports\Scripts directory. You can also create subdirectories under your main NETLOGON folder. If the NETLOGON share is pointing to c:\Scripts and I created a subdirectory under that called Local, then I'd need to configure my local user's login script setting to be Local\login.vbs. The same logic applies to domain controllers; except that by default, the NETLOGON share already exists and points to %SystemRoot%\sysvol\<DomainName>\Scripts. When you add scripts to that directory, they replicate out to all domain controllers in the domain <DomainName> using the File Replication Service (FRS). See AlsoMS KB 258286 (HOW TO: Assign a Logon Script to a Profile for a Local User in Windows 2000) and MS KB 315245 (How to Assign a Logon Script to a Profile for a Local User) |