Like Tree3Likes
  • 1 Post By CommonTater
  • 2 Post By AndrewHunter

Getting pathname from program in execution

This is a discussion on Getting pathname from program in execution within the C Programming forums, part of the General Programming Boards category; I have written a program that must copy himself in a directory, but i can't know the path in which ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    12

    Getting pathname from program in execution

    I have written a program that must copy himself in a directory, but i can't know the path in which it will be executed, so i need to know this. How can i do??

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Programs that copy themselves are usually suspect... There's no reason to do that except to prevent deletion.

    In any case, look at how main() works in your C textbooks...

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    I need that the program starts when windows starts, so i need that the program is in the correct position, else it couldn't be executed. It's not a suspicios thing. But I'll try to find something.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by nicauron View Post
    I need that the program starts when windows starts, so i need that the program is in the correct position, else it couldn't be executed. It's not a suspicios thing. But I'll try to find something.
    By Windows standards ALL programs reside in c:\program files on 32 bit systems, or in either c:\program files or c:\program files (x86) for 64 bit systems.

    To make a program start with windows you make a shortcut to the program in the user's start menu\programs\startup...

    You don't make copies of your programs in different places on the system.

    If you want to do this correctly use an install builder such as Inno Setup (yes that's a link, click on it!) which provides full installation and uninstall capability as well as many features for initial setup.

    The one thing you never NEVER do is install anything on a user's system they don't know about.
    Last edited by CommonTater; 08-11-2011 at 06:06 AM.
    Salem likes this.

  5. #5
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    OK, so first you ask about keeping track of keystrokes and now this. May I suggest you explain yourself a lot more clearly about what it is you are trying to accomplish if you want to get help. If English is a barrier, post your code and just try to explain that. We all speak "C" here, and for some *cough*quzah*cough* it was their first language.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by nicauron View Post
    I have written a program that must copy himself in a directory, but i can't know the path in which it will be executed, so i need to know this. How can i do??
    It's called your current or present working directory, abbr. PWD or CWD, and there are OS specific routines to get it.

    Of course, you can't be sure the directory it is executed in is also the directory where the executable is stored on disk. In that case, you can use argv[0] to determine the path it was called with, and if that is a relative path combine it with the PWD.

    If it was executed with no path, then it is in the "executable path" of the OS, and you will have to search for it there. At the very least, arg[0] will give you the executable name to work with.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by AndrewHunter View Post
    OK, so first you ask about keeping track of keystrokes and now this. May I suggest you explain yourself a lot more clearly about what it is you are trying to accomplish if you want to get help. If English is a barrier, post your code and just try to explain that. We all speak "C" here, and for some *cough*quzah*cough* it was their first language.
    Oh come on Andrew... you know you can't condemn the guy until next week when he asks about sending files over the internet....

  8. #8
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by CommonTater View Post
    Oh come on Andrew... you know you can't condemn the guy until next week when he asks about sending files over the internet....
    Haha....you mean like his ftp thread?
    stahta01 and Salem like this.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by AndrewHunter View Post
    Haha....you mean like his ftp thread?
    The term "Oh Crap" comes immediately to mind....

  10. #10
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Usually my interest gets peaked when I see:

    (1) Low post count
    (2) Lack of a concise question
    (3) No code provided

    Now where is V when we need him to post his 8-bit com hackery?
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by AndrewHunter View Post
    Usually my interest gets peaked when I see:

    (1) Low post count
    (2) Lack of a concise question
    (3) No code provided
    It certainly does look suspicious...

  12. #12
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    It's not a malicious thing. The topics that i made are all for different aims. I'm not trying to create a keylogger, there are too many of them on the net. The FTP post was to upload files immediately without installing a client, and also to learn something about FTP, the topic about GetAsyncKeyState was to create a menu that receives controls from the keyboard, and this topic is to install a simple program, and CommonTater is right, i can use InnoSetup.

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Be honest now... if the situation was reversed... If I had a posting history that might tell a story and I offered you that line of BS....

    Would you believe me?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program execution
    By kris.c in forum Tech Board
    Replies: 14
    Last Post: 05-16-2007, 01:54 PM
  2. execution of a C program
    By kris.c in forum C Programming
    Replies: 7
    Last Post: 07-27-2006, 11:14 AM
  3. Unix pathname to Windows pathname
    By Nolens in forum Windows Programming
    Replies: 1
    Last Post: 11-30-2005, 12:20 PM
  4. program execution
    By xlordt in forum C Programming
    Replies: 4
    Last Post: 04-11-2003, 05:47 AM
  5. Program Execution
    By UnclePunker in forum C++ Programming
    Replies: 1
    Last Post: 03-27-2003, 09:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21