System.Diagnostic.Process and disfunctional process

  • Thread starter Michael Johnson Sr.
  • Start date
M

Michael Johnson Sr.

I am starting and stopping a process using System.Diagnostic.Process.

aspnet_wp is running as system rather than machine (as per machine.config
modification). When the process gets started, it will not respond to tcp
connections. The process is a service that accepts incoming tcp
connections.

Any ideas will be great.
 
M

Martin Dechev

Hi, Michael Johnson Sr.,

I think you will still need to impersonate a user that has rights to
start/stop services on the machine (I'm afraid I can't give you the list of
these rights)

Have a look at the following article (the last section in it):
[ Implementing Impersonation in an ASP.NET Application ]
http://support.microsoft.com/default.aspx?kbid=306158

After doing so, you have 2 ways
- using the System.Diagnostics.Process to call "net.exe" and passing it the
appropriate parameters. It's simpler, but not the better way for sure.
- using platform-invoke - you will have to call the following functions:
http://msdn.microsoft.com/library/en-us/dllproc/base/openscmanager.asp
http://msdn.microsoft.com/library/en-us/dllproc/base/openservice.asp
http://msdn.microsoft.com/library/en-us/dllproc/base/startservice.asp
(optionally, if you need to further control the service, i.e. stop it:)
http://msdn.microsoft.com/library/en-us/dllproc/base/controlservice.asp
http://msdn.microsoft.com/library/en-us/dllproc/base/closeservicehandle.asp

Hope this helps
Martin
 
M

Michael Johnson Sr.

Well if I watch task manager, I see the task start/stop.
But it won't respond to connections, it acts like it isn't even running.


Martin Dechev said:
Hi, Michael Johnson Sr.,

I think you will still need to impersonate a user that has rights to
start/stop services on the machine (I'm afraid I can't give you the list of
these rights)

Have a look at the following article (the last section in it):
[ Implementing Impersonation in an ASP.NET Application ]
http://support.microsoft.com/default.aspx?kbid=306158

After doing so, you have 2 ways
- using the System.Diagnostics.Process to call "net.exe" and passing it the
appropriate parameters. It's simpler, but not the better way for sure.
- using platform-invoke - you will have to call the following functions:
http://msdn.microsoft.com/library/en-us/dllproc/base/openscmanager.asp
http://msdn.microsoft.com/library/en-us/dllproc/base/openservice.asp
http://msdn.microsoft.com/library/en-us/dllproc/base/startservice.asp
(optionally, if you need to further control the service, i.e. stop it:)
http://msdn.microsoft.com/library/en-us/dllproc/base/controlservice.asp
http://msdn.microsoft.com/library/en-us/dllproc/base/closeservicehandle.asp

Hope this helps
Martin
Michael Johnson Sr. said:
I am starting and stopping a process using System.Diagnostic.Process.

aspnet_wp is running as system rather than machine (as per machine.config
modification). When the process gets started, it will not respond to tcp
connections. The process is a service that accepts incoming tcp
connections.

Any ideas will be great.
 
M

Martin Dechev

Michael Johnson Sr. said:
Well if I watch task manager, I see the task start/stop.
But it won't respond to connections, it acts like it isn't even running.

This means that if it runs as SYSTEM it doesn't behave as expected. And on
behalf of which user it runs normally? Can you try to impersonate this user
and then start it?

Apart from that, are you sure that it doesn't expect some user's
interaction? i.e. it might well be "showing" some dialog box which you can't
see, and so the application stays blocked.

Greetings
Martin
 
M

Michael Johnson Sr.

I was impersonating an admin (which from what i understand is required for
using system.diagnostics.process.getprocesses().

But I couldn't get it to work on Win2000, although it worked on WinXP. I
could stop the process as the admin but starting it still seemd like it was
system user. On WinXP i didn't even have to set aspnet_wp to be system.
 
M

Michael Johnson Sr.

When I use identity impersonate username (administrator account)

I can't stop the service created by SYSTEM (aspnet_wp)

When I start the service, it gets started as SYSTEM despite who I
impersonate
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top