Skip to content

Instantly share code, notes, and snippets.

@nathan-osman
Created January 27, 2016 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathan-osman/785152e6452559852fc8 to your computer and use it in GitHub Desktop.
Save nathan-osman/785152e6452559852fc8 to your computer and use it in GitHub Desktop.
Add to %PATH% before starting another process
cmake_minimum_required(VERSION 2.8.9)
project(printpath)
add_executable(printpath path.cpp)
set(ENV{PATH} "C:/Some/Path;$ENV{PATH}")
add_custom_target(show "$<TARGET_FILE:printpath>")
add_dependencies(show printpath)
#include <stdio.h>
#include <wchar.h>
#include <windows.h>
int wmain(int argc, wchar_t *argv[])
{
LPWSTR szValue;
DWORD size;
if(!(size = GetEnvironmentVariableW(L"PATH", NULL, 0))) {
wprintf(L"Unable to determine size to allocate\n");
return 1;
}
szValue = new WCHAR[size];
if(!GetEnvironmentVariableW(L"PATH", szValue, size)) {
wprintf(L"Unable to allocate memory\n");
return 1;
}
wprintf(L"Value: %s\n", szValue);
delete [] szValue;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment