#include <iostream> #include <cstdio> #include <stdlib.h> #include <conio.h> #include <string> #define _AFXDLL #include <afxwin.h> #include <tchar.h> #include <afx.h> #include <afxpriv.h> using namespace std ; void main(void) { char plusPath[] = ";C:\\software\\develop\\eclipse49\\plus\\jdk1.8.0_191\\bin"; HKEY hKey; char data[1024] = {}; DWORD dwSize = sizeof(data); DWORD dwType = REG_EXPAND_SZ; // HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment const char *key = "System\\CurrentControlSet\\Control\\Session Manager\\Environment"; RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_READ|KEY_WRITE, &hKey); RegQueryValueExA(hKey, "Path", NULL, &dwType, (LPBYTE)data, &dwSize); int length=strlen(plusPath) + strlen(data); char *environment = new char[length]; environment=strcat(data,plusPath); RegSetValueExA(hKey, "Path", NULL, REG_EXPAND_SZ, (const unsigned char *)environment, strlen(environment)); DWORD dwResult; SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE , 0,LPARAM(_T("Environment")), SMTO_ABORTIFHUNG, 5000, &dwResult); RegCloseKey(hKey); }
C++ 设置Java 环境变量
猜你喜欢
转载自www.cnblogs.com/1886vip/p/10666451.html
今日推荐
周排行