我想出了这个代码。它将正确执行并返回 true。但它不会改变 Path 变量的值。当我在 cmd 中这样输入 --> setx Path "C:\Program Files\Java\jdk1.7.0_02\bin\" 时,它可以工作并更改路径值
这是代码
// Prepare shellExecutInfo
SHELLEXECUTEINFO ShRun = {0};
ShRun.cbSize = sizeof(SHELLEXECUTEINFO);
ShRun.fMask = SEE_MASK_NOCLOSEPROCESS;
ShRun.hwnd = NULL;
ShRun.lpVerb =NULL;
ShRun.lpFile = "C:\\Windows\\System32\\setx.exe";
ShRun.lpParameters = "Path \"\"\"C:\\Program Files\\Java\\jdk1.7.0_02\\bin\\\"\"\"";
ShRun.lpDirectory =NULL;
ShRun.nShow = SW_SHOWNORMAL;
ShRun.hInstApp = NULL;
// Execute the file with the parameters
if(ShellExecuteEx(&ShRun))
printf("done");
else
printf("no");
这里会有什么问题?