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 ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.