Assigning a user ID to a Console app

mmcclendon

New member
Joined
Mar 14, 2006
Messages
3
Location
Birmingham, Alabama
Programming Experience
10+
I need to run a console application using a specific User account. In ASP.Net, you can run an application using the "Impersonation" settings in the web.config file. I have not been able to find anything similar in the windows environment.

The application is started from a command file, and is executed unattended. I tried using the RUNAS command, but I can't find a way to enter the password for the user account in the command file.

Any help would be greatly appreciated. I know I am missing something and this may be simple. I just can't seem to find an answer.

Thanks.
 
Process/ProcessStartInfo classes can be used to run a process as user with given credentials.
VB.NET:
Dim psi As New ProcessStartInfo
psi.FileName = "calc.exe"
psi.UseShellExecute = False
psi.UserName = "username"
Dim sec As New Security.SecureString
Dim unsec As String = "password"
For Each c As Char In unsec
    sec.AppendChar(c)
Next
psi.Password = sec
Process.Start(psi)
 
Back
Top