Jump to content
Fórum Script Brasil
  • 0

Comparar diretório de um processo


apvsalvado

Question

Sou totalmente novato no C++, estou fazendo uma DLL usando o visual studio. Estou tentando comparar o diretório do processo com um nome que eu dou, segue o exemplo abaixo:

unsigned int ipath = 0;

    ipath = game.GetProcessPathByName("Dell");

    if ( ipath )
    {
        // Acho que vai fechar kkkkk
        MessageBox(0, L"Ok", L"Encontrado", MB_OK);
    }
Simplesmente se eu tiver o processo com o diretório "C:\Dell\Updater.exe" essa função não consegue encontra-lo, agradeço a ajuda.
unsigned long CProject::GetProcessPathByName(char *pathanme)
{
        HANDLE hProcSnapshot = ::CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
        if( INVALID_HANDLE_VALUE != hProcSnapshot )
        {
            PROCESSENTRY32 procEntry = {0};
            procEntry.dwSize = sizeof(PROCESSENTRY32);
            if( ::Process32First( hProcSnapshot, &procEntry ) )
            {
                do
                {
                    HANDLE hModSnapshot = ::CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, procEntry.th32ProcessID );
                    if( INVALID_HANDLE_VALUE != hModSnapshot )
                    {
                        MODULEENTRY32 modEntry = {0};
                        modEntry.dwSize = sizeof( MODULEENTRY32 );
                        if( Module32First( hModSnapshot, &modEntry ) )
                        {
                char* converted = new char[wcslen(modEntry.szExePath) + 1];
                wcstombs( converted, modEntry.szExePath, wcslen(modEntry.szExePath) );

                            if( _stricmp(pathanme, converted) )
                            {
                                ::CloseHandle( hModSnapshot );
                                return 1;
                            }
                        }
                        ::CloseHandle( hModSnapshot );
                    }
                }
                while( ::Process32Next( hProcSnapshot, &procEntry ) );
            }
            ::CloseHandle( hProcSnapshot );
        }
    
        return 0;
}

Edited by apvsalvado
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152k
    • Total Posts
      651.6k
×
×
  • Create New...