Created
January 27, 2016 05:04
-
-
Save nathan-osman/785152e6452559852fc8 to your computer and use it in GitHub Desktop.
Add to %PATH% before starting another process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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