C++ C++;构建完整路径
我无法使用变量构建完整路径。 这是怎么回事? 根据要求提供更多代码:C++ C++;构建完整路径,c++,windows,path,environment,C++,Windows,Path,Environment,我无法使用变量构建完整路径。 这是怎么回事? 根据要求提供更多代码: #include "stdafx.h" #include <Windows.h> #include <string> #include <stdio.h> #include <string.h> #include <tchar.h> #include <Shellapi.h> #include <urlmon.h> #pragma commen
#include "stdafx.h"
#include <Windows.h>
#include <string>
#include <stdio.h>
#include <string.h>
#include <tchar.h>
#include <Shellapi.h>
#include <urlmon.h>
#pragma comment(lib, "urlmon.lib")
#include <iostream>
#include <sstream>
wchar_t* env(wchar_t* environmentVariable)
{
wchar_t* buffer;
size_t bufferSize;
errno_t errorCode;
errorCode = _wdupenv_s(&buffer, &bufferSize, environmentVariable);
return buffer;
}
int WINAPI WinMain(HINSTANCE instanceHandle, HINSTANCE, char*, int)
{
LPWSTR PSPath = env(_TEXT("SystemRoot"));
LPWSTR TEMP2 = env(_TEXT("TEMP"));
LPWSTR HOMEDRIVE = env(_TEXT("HOMEDRIVE"));
LPWSTR PSPathexe = (_TEXT("powershell.exe"));
std::stringstream BuildPath;
BuildPath << "-noexit -Executionpolicy bypass -File (($env:temp) + '\\psscript.ps1') -Filename psscript -Folderpath (($env:systemdrive)+ '\\deployment')";
std::string s = BuildPath.str();
LPWSTR PSPathexe = s.c_str();
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
ShellExecute(NULL, NULL, PSPathexe, s, NULL, SW_SHOW);
return 0;
}
#包括“stdafx.h”
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#pragma注释(lib,“urlmon.lib”)
#包括
#包括
wchar_t*env(wchar_t*environmentVariable)
{
wchar_t*缓冲区;
大小缓冲区大小;
错误代码;
errorCode=_wdupenv_s(&buffer,&bufferSize,environmentVariable);
返回缓冲区;
}
int WINAPI WinMain(HINSTANCE instanceHandle,HINSTANCE,char*,int)
{
LPWSTR PSPath=env(_TEXT(“SystemRoot”);
LPWSTR TEMP2=环境(文本(“TEMP”);
LPWSTR HOMEDRIVE=env(_TEXT(“HOMEDRIVE”);
LPWSTR PSPathexe=(_TEXT(“powershell.exe”);
std::stringstream构建路径;
BuildPath什么是env()
实际上?可以使用函数访问环境变量。要替换PSARG的完整路径,这里必须使用temp和Homedrive。请发布did,您能提供帮助吗?