CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2006
    Posts
    329

    Get program name

    Hi all. Is there some API or standard function to call to retrive the current name of the program running? Something like GetCurrentProcessId(), maybe something like GetCurrentProgramName() or something of the sort. Google and Yahoo dont seem to help and i dont know where to begin this sort of search. Any suggestions? Thanx in advance.

  2. #2
    Join Date
    Aug 2005
    Posts
    133

    Re: Get program name

    Hi,
    did you try :
    Process::GetCurrentProcess()->get_ProcessName();
    Louis-Philippe Frenette
    Arobas Informatique Granby
    http://www.arobasinformatique.com

  3. #3
    Join Date
    Nov 2006
    Posts
    329

    Re: Get program name

    Quote Originally Posted by shootrz
    Hi,
    did you try :
    Process::GetCurrentProcess()->get_ProcessName();


    That doesnt give you the program name nor PID. GetCurrentProcessId() does. Besides i found out what it is.

    Code:
    include <iostream>
    using namespace std;
    
    int main(int argc, char* argv[])
    {
       cout << argv[0] << endl;
       return 0;
    }

  4. #4
    Ejaz's Avatar
    Ejaz is offline Elite Member Power Poster
    Join Date
    Jul 2002
    Location
    Lahore, Pakistan
    Posts
    4,211

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Get program name

    You can do it like this:
    Code:
    TCHAR szpath[MAX_PATH+1] = {0};
    ::GetModuleFileName(NULL, szpath, MAX_PATH);
    
    std::string nume = szpath;
    nume = nume.substr(nume.rfind("\\") + 1);
    or, with CString:
    Code:
    TCHAR szpath[MAX_PATH+1] = {0};
    ::GetModuleFileName(NULL, szpath, MAX_PATH);
    
    CString nume = szpath;
    nume = nume.Right(nume.ReverseFind('\\') + 1);
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Get program name

    AfxGetAppName/CWinApp::m_pszAppName if using within an MFC application

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured