Hi !!!
How can i get the path of specific program using C ?
I need to get the path of x program in order to copy files.... in reality i'm trying to make a autocrack.exe file.
The all i need to known is the above command
Thanks
Hi !!!
How can i get the path of specific program using C ?
I need to get the path of x program in order to copy files.... in reality i'm trying to make a autocrack.exe file.
The all i need to known is the above command
Thanks
Do you mean this?
--Code:dir /s/b progname.exe
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Assuming that you do not know the location of X program, then you would use FindFirstfile and FindNextfile and recursivley call the file finding function to search for X program.I need to get the path of x program in order to copy files
szFileName being the char array to copy the file name to, you can replace MAX_PATH with whatever no. you want, or you could probably use a string (such as str1.c_str()) in place of a char. But that will return the path to the executable file (C:\test.exe), so you'll have to change that to C:\ or whatever.Code:char szFileName[MAX_PATH]; HINSTANCE hInstance = GetModuleHandle(NULL); GetModuleFileName(hInstance, szFileName, MAX_PATH);
I'm not good at writing snippets of code like that, but I think you get the idea, getcwd() takes two parameters, the first is a cstring that will hold the directory in it and the second is how much space you are giving it.Code:#include <direct.h> ... void Foo() { ... char *tempPath = new char[512]; // Create a cstring to store the path in getcwd(tempPath, 511); // tempPath now stores the path of the directory // of the *.exe file. ... cout << "This program has been executed from the directory: " << tempPath; ... delete [] tempPath; }
Thanks for your answers, were really helpful !
Matsp i really mean this dir /s/b progname.exe
I want to get the dir of a program like patches do, and copy/paste crack to the folder of x program but using C.
Well, you can either execute "dir /s/b somename.exe" from inside a C program, using a pipe to read the output, or redirect the output to a file, then read the file. Just remember that not everyone has one big disk, there may be several physical or logicial disks, so you need to get a list of those [there was a post on how to do that in Windows just a few days ago].
Or, if you really want to do it in your application, use the method described by mikeman118. There will be little difference in performance, since the speed of finding a file is mainly dependant on the time it takes to get the relevant data off the disk, rather than how you get to the final data.
But really, it's probably much easier to just write a little batch-file to do the same thing, rather than C.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thank you for the advice.
I will try both and choose the best.