我无法使用变量构建完整路径。 这怎么样? 根据要求提供更多代码:
#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;
}
我唯一需要的是Buildpath,目前在字符串中用PS构建,我不希望这会起作用。 但我甚至无法将其转换为LPWSTR,所以我完全被困在这里。