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
Open the Start Menu.
Browse to the application you want to open.
For Windows 2000, press the Shift key and right-click on the application.
For Windows Server 2003, right-click on the application.
Select Run As.
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 ...
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.