ProcessStartInfo.UserName Property
Assembly: System (in system.dll)
Important: |
|---|
| The WorkingDirectory property must be set if UserName and Password are provided. If the property is not set, the default working directory is %SYSTEMROOT%\system32. |
If the UserName property is not a null reference (Nothing in Visual Basic) or an empty string, the UseShellExecute property must be false, or an InvalidOperationException will be thrown when the Process.Start(ProcessStartInfo) method is called.
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
When you specify a UserName and Password properties of StartInfo then you will need to impersonate another user (besides LocalSystem) when calling Process.Start (typically the same user) or use the unmanaged CreateProcessAsUser method.
Without impersonation Process.Start called from a Service running as "Local System account" throws an "Access Denied" exception.
From Process.StartInfo Property help:
"If you call the Start(ProcessStartInfo) method with the ProcessStartInfo.UserName and ProcessStartInfo.Password properties set, the unmanaged CreateProcessWithLogonW function is called"...
From CreateProcessWithLogonW help:
"Windows XP SP2 and Windows Server 2003: You cannot call CreateProcessWithLogonW from a process that is running under the LocalSystem account, because the function uses the logon SID in the caller token, and the token for the LocalSystem account does not contain this SID. As an alternative, use the CreateProcessAsUser and LogonUser functions."
- 6/13/2006
- Nick Ericson - MSFT
- 6/13/2006
- stephenbutler
Important: