Jump to content

ProcessExists - How does one get the PID through 'Return Value' ? How do I print 'Sucess' ?


Go to solution Solved by jchd,

Recommended Posts

I'm trying to get the PID of a process called "c:\PROGRA~2\G.SKILL\Trident Z Lighting Control\hid.exe". It controls the RGB (Krap) on the RAM modules. In case you don't know what RGB RAM isrgb ram - Search (bing.com)

Absolutely loathe that RGB Krap :)

Long story short. I wrote two scripts, and both work (for the most part.

KillGskillRGB()
Func KillGskillRGB()
        ; Run Notepad
        Local $iPID = Run("c:\PROGRA~2\G.SKILL\Trident Z Lighting Control\hid.exe")

        ; Wait 5 seconds for the G.SKILL window to appear.
        ;WinWait("[CLASS:CabinetWClass]", "", 5)
        ;Local $hWnd01 = WinWait("[CLASS:CabinetWClass]", "", 5)
        ;Error Check - If 'true' script runs next command, if 'false' exits script.
        ;If NOT $hWnd01 then Exit

Local $hWnd01 = WinWait("[CLASS:CabinetWClass]", "", 5)

        ; Wait for 2 seconds.
        Sleep(2000)

        ; Close the G.SKILL process using the PID returned by Run.
        ProcessClose($iPID)
EndFunc   ;==>KillGskillRGB
If ProcessExists("hid.exe") Then
   ProcessClose ("hid.exe")
EndIf

The first gives me the PID by running it, the second kills by the Process name. 

I was poking through the help files to do this. I found this example.

#include <MsgBoxConstants.au3>

If ProcessExists("notepad.exe") Then ; Check if the Notepad process is running.
        MsgBox($MB_SYSTEMMODAL, "", "Notepad is running")
Else
        MsgBox($MB_SYSTEMMODAL, "", "Notepad is not running")
EndIf

Then I saw this.

Return Value
Success:    the PID of the process.
Failure:    0 if process does not exist.

How does one get the PID through 'Return Value' ? How do I print 'Sucess' ?

 

Link to comment
Share on other sites

  • Solution
Run("notepad.exe")
Sleep(5000)
Local $pid = ProcessExists("notepad.exe")
ConsoleWrite("PID of Notepad.exe is " & $pid & @LF)
ProcessClose($pid)

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

@jchd

Thank you - that script works perfectly. 

I see the PID In the console now :) 

I also see if an error occurs, I get a 'zero' in the console.

How would I go about using that zero for error checking?

Success is always a non-zero number (the PID), while any error is a 'zero.'

I would think a 'If/Then' to error check. I'm not sure how to go about that :)

If error is > than zero - then do something

If error is = to zero - then do something.

Thank you for any insight. I see writing a script can be easy, the troubleshooting/debugging it is a lot more difficult :D

Updated code.

KillGskillRGB()
Func KillGskillRGB()
Run("C:\Progra~2\G.SKILL\Trident Z Lighting Control\hid.exe")
Sleep(5000)
Local $pid = ProcessExists("hid.exe")
ConsoleWrite("PID of 'hid.exe' is " & $pid & @LF)
ProcessClose($pid)
EndFunc   ;==>KillGskillRGB

 

Edited by Puts-The-New-In-Noobie
Posted the wrong script. Was Missing an 'e' in exe :)
Link to comment
Share on other sites

  • 3 weeks later...
On 4/28/2022 at 4:07 AM, Puts-The-New-In-Noobie said:

I'm trying to get the PID of a process called "c:\PROGRA~2\G.SKILL\Trident Z Lighting Control\hid.exe". It controls the RGB (Krap) on the RAM modules. In case you don't know what RGB RAM isrgb ram - Search (bing.com)

Absolutely loathe that RGB Krap :)

Long story short. I wrote two scripts, and both work (for the most part.

KillGskillRGB()
Func KillGskillRGB()
        ; Run Notepad
        Local $iPID = Run("c:\PROGRA~2\G.SKILL\Trident Z Lighting Control\hid.exe")

        ; Wait 5 seconds for the G.SKILL window to appear.
        ;WinWait("[CLASS:CabinetWClass]", "", 5)
        ;Local $hWnd01 = WinWait("[CLASS:CabinetWClass]", "", 5)
        ;Error Check - If 'true' script runs next command, if 'false' exits script.
        ;If NOT $hWnd01 then Exit

Local $hWnd01 = WinWait("[CLASS:CabinetWClass]", "", 5)

        ; Wait for 2 seconds.
        Sleep(2000)

        ; Close the G.SKILL process using the PID returned by Run.
        ProcessClose($iPID)
EndFunc   ;==>KillGskillRGB
If ProcessExists("hid.exe") Then
   ProcessClose ("hid.exe")
EndIf

The first gives me the PID by running it, the second kills by the Process name. 

I was poking through the help files to do this. I found this example.

#include <MsgBoxConstants.au3>

If ProcessExists("notepad.exe") Then ; Check if the Notepad process is running.
        MsgBox($MB_SYSTEMMODAL, "", "Notepad is running")
Else
        MsgBox($MB_SYSTEMMODAL, "", "Notepad is not running")
EndIf

Then I saw this.

Return Value
Success:    the PID of the process.
Failure:    0 if process does not exist.

How does one get the PID through 'Return Value' ? How do I print 'Sucess' ?

 

Can't we do the same process using task manager or command prompt? 
 

  1. Press Ctrl+Shift+Esc on the keyboard.
  2. Go to the Processes tab.
  3. Right-click the header of the table and select PID in the context menu.

The context menu in the processes window

  1. Find the process for which you need to find the PID.

Find the PID of the process in the corresponding column.

The PID column in the processes window

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...