Recipe 10.9. Running a Task Automatically via Login Scripts


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 you want to set the login script for.

  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 = "<HostName>" 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 can also set the login script for a domain user:

> 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 domain 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 user let's say that login.vbs has been configured. The system then attempts to run \\localhost\NETLOGON\login.vbs. By default, the NETLOGON share does not exist on Windows XP systems. See Recipe 8.23 for more on how to create a share. You can point the NETLOGON share to any directory on the system.

You can also use subdirectories under the NETLOGON share. If the NETLOGON share is pointing to c:\Scripts and we created a subdirectory under that called Local, then we'd need to configure my local user's login script setting to Local\login.vbs.

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 XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

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