Jump to content

Function ProcessGetStats Failure


 Share

Recommended Posts

Hi,

I'm trying to get  IO infos from an active service that is recognized with its PID.

On Windows XP I get the IO infos, But on Window 7 And Windows 10 I get a failure with @error=1

What is wrong ?

 
Link to comment
Share on other sites

It's basic:
    $SrvMemArray = ProcessGetStats($SRVPID, 0)
   If Not $SrvMemArray Then
        WriteToLog($LogFileHandle, $SrvName & " Error, PID " & $SRVPID & " Not Found - Macro terminated", $Append)
   EndIf

On Windows Xp $SrvMemArray  is not empty, the code passes the if statement

On Windows7/10 it fails with @error = 1

Thank you

 

BTW: I run this code as administartor

 

 

Edited by Chaym
Link to comment
Share on other sites

The existence of the process is checked with $SRVPID = ProcessExists($SrvName)

I get the Service PID Number ($SRVPID) then I use it in:

$SrvMemArray = ProcessGetStats($SRVPID, 0)

Edited by Chaym
Link to comment
Share on other sites

Do you see the pid in task manager ?  What version of autoit are you running ?  What is the value of $SrvName ?

You should have posted a runable script so we don't have to guess what could be the error...

Edited by Nine
Link to comment
Share on other sites

ProcessGetStats returns an array, this code won't work.

If Not $SrvMemArray Then

You can't do a boolean check like that on an array. It's always going to bypass that check and go right into the If statement.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Of course I see the Service And it's PID on task manager.

It's an internal private service I use at work.

"The existence of the process is checked with $SRVPID = ProcessExists($SrvName) "

I do an boolean check  on  @error flag.

ProcessGetStats() function sets non zero value on Failure (Array is empty)

Auto version in 3.3.14.2

Thank you...

 

 

 

Edited by Chaym
Link to comment
Share on other sites

9 minutes ago, Chaym said:

I do an boolean check  on  @error flag.

You are using $SrvMemArray, which, in case of success, will be an array, which you can't do a boolean comparsion as @BrewManNH said, and, in case of failure, the @error code is set to a non-zero value.

Better check the success/failure as mentioned in the example about ProcessGetStats():

Global $SrvMemArray = ProcessGetStats($SRVPID)
If IsArray($SrvMemArray) Then
    ; Do something
Else
    ; Error
EndIf

 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

  • Developers

The checked process is running at the same level, not admin?
Post some code that is runnable and actually shows what you are doing so we can check for issues. 

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Here is the code (very simple)

Local $ProcessName = "sqlservr.exe"
Local $SQLPID = ProcessExists($ProcessName)
WriteToLog($LogFileHandle, $ProcessName & ": $SQLPID = "&$SQLPID, $Append)

Local $SqlMemArray = ProcessGetStats($SQLPID, 0) ;Memory Info's
Local $ProcessStatusErr = @error
WriteToLog($LogFileHandle, $ProcessName&" PID: "&$SQLPID&" / @error: "&$ProcessStatusErr, $Append)

If Not IsArray($SqlMemArray) Then
    WriteToLog($LogFileHandle, $ProcessName&" Error: "&$ProcessStatusErr&" - PID: "&$SQLPID&" Not Found - Program terminated", $Append)
    ShowMess($HebStop, $ProcessName&" Error", $ProcessName&" Not found", -1)
Else

EndIf

In WindowsXP OS it passes the If Not IsArray($SqlMemArray)

In Widows 7 And  Windows 10 it not passes, I Get @error=1

Thank you

Chaim

Edited by Chaym
Link to comment
Share on other sites

  • Developers
7 minutes ago, Chaym said:

Here is the code (very simple)

Ok, but what about the answer to my first question?
Under which credentials is the sqlservr.exe running?
Have you tried your script with #RequireAdmin at the top of the script?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I tried now (again) with #RequireAdmin , it won't work.

What do you mean "Under which credentials "?

Can you explain please, from where can I see the credentials?

I added print screen of task manger, in case it helps...

I checked some processes.

It seems that process where the user name in task manager is the login user name to windows (pos) are recognized.

and the rest user names like SYSTEM and else are failing.

What cad I do about that ?

TM.thumb.png.ed01ad6001b25e785fbaa8428fabea9e.png

Edited by Chaym
Link to comment
Share on other sites

  • Developers
1 minute ago, Chaym said:

Can you explain please, from where can I see the credentials?

The Username column! ;)

2 minutes ago, Chaym said:

It seems that process where the user name is login user name to windows (pos) are recognized.

That makes sense as Win10 is much safer and processes can't just be access anymore like the good old win95/winXP days.

So you do get the appropriate PID but can't get the process information... not even when elevated to Admin.... right?
In that case you really need to check the security settings for the current account and the accounts used to run the services.

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Yes, I get the PID but no information.

I need to check the amount of memory  the process uses (not the one in this example), IO info, etc...

to see if there are memory or resource leaks.

What should I do to get access to this services?

Thank you...

 

Edited by Chaym
Link to comment
Share on other sites

  • Developers
16 hours ago, Jos said:

In that case you really need to check the security settings for the current account and the accounts used to run the services.

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Well, I changed in Log On tab to the check box to This account and entered the login account.

It works for windows 7, But not work for windows 10.

Any idea?

Thank you.

Edited by Chaym
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...