Status of a process

Started by seckner, April 16, 2018, 11:21:01 AM

Previous topic - Next topic

seckner

I have a program that runs on a server and it has a habit of pausing itself. I'm lost trying to find the "status" of it. When it runs normally it looks like the first picture, everything normal. When it pauses the phrase ***REPORT SERVER PAUSED*** shows up. If I can find it, I can restart the darn thing. Please feel free to beat me as severely as needed. 

td

Assuming you are referring to a regular Windows service, check out the Network Extender's "wntSvcStatus" function.  You might have to do a little trial and error to get the parameters right.  If you are attempting to query the service remotely, you may need to use the wntRunAsUser with login type 6.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

If you are not referring to a service managed by the Windows Service Control Manager, you may simply need to look for a window with the title in the posted image.  See WinItemize and WinItemizeEx in the Consolidated WIL Help file.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

seckner

Thank you kind sir, I should have been clearer - this is a process. Service would be fairly easy but this is a exe that runs on the server.

td

Not to put to fine a point on it but Windows services are processes too.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

seckner

True. Let's try this - the process does not show up in the services window as a traditional Windows service. The only place I can find it is in the Task Manager. Are you saying that the services functions will work on processes? I'll try that in the morning.

td

The service functions only work on processes that are under the control of the Service Control Manager (SCM.)   You will need to use the previously mentioned  Win* functions and/or possibly the AppExist and the TerminateApp functions because your process is not under the control of the SCM.  Alternatively, you could use the FCL's "System.Diagnostics.Process" class which has some convenient features.    There is a simple example here:

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/dotNet/System_Diagnostics+Kill~a~Process.txt

MSFT's documentation can be found here:

https://msdn.microsoft.com/en-us/library/system.diagnostics.process(v=vs.110).aspx

You might be able to use the "MainWindowTitle" property of the class to determine the state of your targetted app.  It all depends on the text in the title changing when your app is paused which seems to be the case based on your graphic.

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

ChuckC

If the process isn't a native NT service running under control of the SCM, then by definition it must be running in a user session, either on the "console" [console session definition varies with the version of Windows] or in a terminal services session.

In this situation, how is the process started?  Does somebody logon to the server via RDP or the console, double click a shortcut and then leave the session running [possibly in a locked state]?  Is the an entry under the "Run" key in the user's registry hive that automatically starts the process at logon time, again, with the session being left running?  Is the Windows Task Scheduler involved and configured to run the task as a specific user but not within a specific desktop session [e.g. within session #0]?  If so, remember that the task schedule in that case *is* a service process, and it would simply be starting this other process as a child process in session #0.

One thing that you can be certain of is that the process doesn't just automatically start up and run when the server boots up and the process isn't a service process.

td

WinBatch is certainly capable of working with the Windows Task Scheduler using the "Schedule.Service" COM Automation object.  There are multiple examples in the Tech Database.   

Some WIL functions are also capable of working with processes in session 0.  The "TerminateApp" function being a case in point.   The "System.Diagnostics.Process" class should also work across sessions but I haven't tried it to confirm this. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Wrote a quick test script that confirms that the FCL's "System.Diagnostics.Process" class can easily access session 0 processes. 

The best way to explore the exact nature of a process is probably System Internal's  Process Explorer.   It will tell you just about everything you could ever want to know about a process. The System Internals toolset is maintained by MSFT and updated frequently so make sure you have the latest version by checking MSFT's site.

https://docs.microsoft.com/en-us/sysinternals/downloads/sysinternals-suite
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade