Quantcast

Jump to content

» «
Photo

[SRC|REL] C++ code to check if SA's running

No replies to this topic
JGuntherS@NL
  • JGuntherS@NL

    Being a being

  • Members
  • Joined: 15 Nov 2005

#1

Posted 29 January 2007 - 08:52 PM

Hey all, I've made a few little C++ functions to check if SA's process is running, this does not only do a check on its window, but it also does a check if the program "gta_sa.exe" is running, by using Wbem/WMI. I don't know for which versions of Windows it works, it works for Window XP, I think it will work Windows 2000 as well, and maybe it works for Windows 98/Me, but I can't check that.

By the way, with a few modification, this can be made to work for VC and III!

findsa.cpp
findsa.h

How to use it:

First, call InitializeWbem to initialize all the COM-objects (this takes quite long, 1 or 2 seconds). After that, you can call getGTASAPID and findGTASAProcess as often as you want. After you're finished, call UninitializeWbem to release the COM-objects.

Here's a simple program demonstrating its usage:
CODE
#include "findsa.h"
#include <stdio.h>

int main()
{
if(InitializeWbem())
{
 printf("Wbem succesfully initialized\n");
}
else
{
 printf("Wbem could not be initialized\n");
}

for (;;)
{
 HANDLE hProc = findGTASAProcess();
 printf("Result of findGTASAProcess call: %u\n", hProc);
 CloseHandle(hProc);
 if(getchar() == 'x') break;
}

UninitializeWbem();

return 0;
}

(Press x and then Enter to quit)

You may use it freely in all of your programs, and if you'd credit me, that'd be great!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users