Skip to content

Instantly share code, notes, and snippets.

@Sohamkadam333
Created December 12, 2023 18:34
Show Gist options
  • Save Sohamkadam333/cf171c695802edee96110aedecd3c617 to your computer and use it in GitHub Desktop.
Save Sohamkadam333/cf171c695802edee96110aedecd3c617 to your computer and use it in GitHub Desktop.
Retrieves the path of the Windows directory.
// GetWindowsDirectory function is a part of the Windows API and is used to retrieve the path of the Windows directory. The Windows directory is where the core operating system files are stored.
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
TCHAR windowsDirectory[MAX_PATH];
int result = GetWindowsDirectory(windowsDirectory,MAX_PATH);
if(result > 0 && result < MAX_PATH)
{
wcout<<"Windows Directory = "<<windowsDirectory<<endl;
}
else
{
wcout<<"Error getting windows directory, Error No : "<<GetLastError()<<endl;
}
system("PAUSE");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment