O'Reilly logo

Windows Server Cookbook by Robbie Allen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.1. Running a Task with Alternate Credentials

Problem

You want to run a task using a username and password other than the one you are currently logged in with.

Solution

Using a graphical user interface

  1. Open the Start Menu.

  2. Browse to the application you want to open.

  3. For Windows 2000, press the Shift key and right-click on the application.

  4. For Windows Server 2003, right-click on the application.

  5. Select Run As.

  6. You will be prompted to enter the username, password, and domain of the user whose credentials you want use for running the task.

Using a command-line interface

The runas.exe command allows you to run a command with alternate credentials:

> runas /user:<User> "<ExectuablePath>"

Here is an example:

> runas /user:AMER\rallen.adm "mmc.exe"

If you want to authenticate using credentials of a user that does not have logon privileges to the local machine, you'll need to specify the /netonly option to the runas command.

Using VBScript

' This code shows how to use alternate credentials using WMI
' ------ SCRIPT CONFIGURATION ------
strServer = "<ServerName>"  ' e.g., fs01
strUser = "<User>"      ' e.g., AMER\rallen.adm
strPasswd = "<Password>" ' ------ END CONFIGURATION --------- on error resume next set objLocator = CreateObject("WbemScripting.SWbemLocator") set objWMI = objLocator.ConnectServer(strServer, "root\cimv2", _ strUser, strPasswd) if Err.Number <> 0 then WScript.Echo "Authentication failed: " & Err.Description end if ' Now you can use the objWMI object to get an instance of a class ' or ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required