Thread: EXE recognizing location

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937

    EXE recognizing location

    is there a way to get a running exe to find out where it is in the file system?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    no as far as far is normalality goes. but u can probally find a way using 8 million lines of code for it to do that. well not 8 million but you get the point. something like this isnt usualy done. because where the exe is in is like its root directory and it cant put files in directories under its location unless u do something special. you can do almost anything in programming of most languages. its just some things arent normaly done. for instance cout is known worlwide to c++ programmers and used a lot. but its not very ocasanial that the program has to know its location
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297

    Re: EXE recognizing location

    Originally posted by CodeMonkey
    is there a way to get a running exe to find out where it is in the file system?
    in windows it's GetModuleFileName(). This gives you the full path to the module. on other systems I can't help you

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    .... and a Unix way

    [edit] Nope that's not what you asked for, I don't think. This will get you the current working directory, not the location of the program itself. Which is it you want?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    are you talking in a console app or windows?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  6. #6
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719

    Well...

    To get the working directory of the Current Process you can use GetCurrentDirectory API from Kernel32, or if you wish to enumerate the working directories of other processes you can use GetModuleFileName API(like FillYourBrain said). PSAPI can be found in psapi.h and you'll probably have to link psapi.lib, if you are missing those dependencies then you can find them from the Platform SDK: Performance Monitoring section. Microsoft has well written samples on how to enumerate running processes and their directories so MSDN should be beneficial, so give that a try and if you require further help on an API from psapi then just post your question. Good luck.

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    getcwd(buffer, max_bufflen);
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finding EXE Location
    By Trent_Easton in forum C Programming
    Replies: 2
    Last Post: 06-18-2005, 08:01 AM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  3. I need help with templates!
    By advocation in forum C++ Programming
    Replies: 6
    Last Post: 03-26-2005, 09:27 PM
  4. Make an exe copy itself to another location
    By Machewy in forum C++ Programming
    Replies: 24
    Last Post: 06-16-2003, 09:17 PM
  5. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 01:26 AM