Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

C++: System Path


ghost's Avatar
0 0

Well I was reading a thread earlier where someone was trying many different ways to open a command prompt, but couldn't. People suggested to just make your own, which is actually a good idea. Took Uberon's code from one of the posts and made it into a .exe and ran it. Almost passed for a command prompt except it didn't visibly show the file path! This got me wondering….

How can I do this?

Any ideas? I've tried a few and talked to a few other people (system_meltdown and Uber0n) and we just don't know the answer. If anyone knows anything that actually works please post away!

[edit] Basically I just want to get the current path to the directory where the .exe is running from and store the path to a string. [/edit]


ghost's Avatar
0 0
#include <iostream>
#include <windows.h>

int main ()
{
	char PathToExe[256];
	GetModuleFileName(NULL, PathToExe, sizeof(PathToExe));

	std::cout << PathToExe << std::endl;

	return 0;
}

Piece of cake. :p


ghost's Avatar
0 0

Thx T-Metal :DB)