Link to home
Start Free TrialLog in
Avatar of DFPITC
DFPITCFlag for Australia

asked on

Process.Start not working correctly

I'm trying to start a process under ASP.Net (VB)
(in this case whoami.exe)

If I do not specify the username/password/domain then the process starts fine and it returns the output
(nt authority\network service)

If I do specify the username/password/domain, the process starts (I can see it in task manager running under the correct account) however, it doesn't return, and doesn't output any data.

I've tried adjusting all the parameters and I've also tried multiple usernames/passwords with no luck.

Below is the current code:
(GetServerConfig retrieves user credentials from database, and i've tried just using strings too)


'Build Secure String from Password
	Dim sp As New System.Security.SecureString()
	Dim c As Char
	For Each c In GetServerConfig("default", "adminpass")
		sp.AppendChar(c)
	Next c
'Process Start Info
	Dim psi As New ProcessStartInfo
	psi.FileName = "C:\\windows\\system32\\whoami.exe"
	psi.Arguments = ""
	psi.WorkingDirectory = Environment.GetEnvironmentVariable("TEMP")
	psi.UseShellExecute = False
	psi.LoadUserProfile = False
	psi.CreateNoWindow = True
	psi.ErrorDialog = False
	psi.RedirectStandardOutput = True
	psi.RedirectStandardInput = True
	psi.RedirectStandardError = True
	psi.Domain = GetServerConfig("default", "admindomain")
	psi.UserName = GetServerConfig("default", "adminuser")
	psi.Password = sp
'Start Process
	Dim p As Process = Process.Start(psi)
	Dim o As StreamReader = p.StandardOutput
	Dim oStr = o.ReadToEnd()
'Return
	Response.Write(oStr)
	Response.End()

Open in new window

SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What are you trying to accomplish by running whoami?  It is not that Network Service has no console window, but rather that the IIS Worker Process (which is used run your ASP.NET programs application pool) is running in a service session which is loaded by the World Wide Web Publishing service.  

Service sessions have no user interface.  Network service comes into play because the application pool is set to use that user as it's means to authenticate with the system.User generated image-saige-
Why are you doubling-up the backslashes in your filename? This isn't C#   ; )
Avatar of DFPITC

ASKER

i'm not trying to run a UI from asp.net, i merely used whoami as a test/debug program as it is informative what it outputs for this.

I'm aware that the worker process runs as "nt authority\network service", what I'm trying to do, is run a program on the server side as a set user, and pass the return output back as a response.

This is why i'm passing parameters to the process.start (eg: redirect the output, and setting a user/pass/domain)

The issue is, it all works fine when I run it without specifying a user/password/domain and the server process (whoami) returns the output "nt authority\network service" back, however, if I start the process specifying the user/pass/domain, it still runs (as I can see the login in event logs and the "whoami" process under task manager on the web server, however, it never returns any output back to the process.start function, and it just sits there until process.start times out.

The process on the web server ("whoami") actually stays running forever, until i manually kill it.

Again, I'm not trying to run a UI program like notepad, as that would be mostly pointless on a web server.
I'm trying to run a program with standard output and capture that back to the web server for processing.

As for the double backslashes, you're right, I don't need it, I thought I did. Either way, that doesn't seem to be the problem.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DFPITC

ASKER

Thanks.