Recipe5.4.Running a Task via a Login Script


Recipe 5.4. Running a Task via a Login Script

Problem

You want to set the login script for a local or domain user account.

Solution

The following solutions describe how to set the login script for a local user account on a system.

Using a graphical user interface

  1. Open the Computer Management snap-in (compmgmt.msc).

  2. In the left pane under System Tools, expand Local Users and Groups.

  3. Click the Users folder.

  4. In the right pane, double-click the user for which you want to set the login script.

  5. Select the Profile tab.

  6. Beside Logon script, enter the relative path (from the NETLOGON share) of the login script (e.g., myscript.vbs).

  7. Click OK.

Using a command-line interface

The 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

  1. Open the Active Directory Users and Computers snap-in (dsa.msc).

  2. In the left pane, connect to the domain that contains the user you want to set the login script for.

  3. Browse to the container the user account is located in.

  4. In the right pane, right-click the user and select Properties.

  5. Select the Profile tab.

  6. Beside Logon script, enter the relative path (from the NETLOGON share on the DCs) of the login script.

  7. Click OK.

Using a command-line interface

The 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

Discussion

A 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 Also

MS 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)



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net