本文整理汇总了C++中Environment::CreateEnvironment方法的典型用法代码示例。如果您正苦于以下问题:C++ Environment::CreateEnvironment方法的具体用法?C++ Environment::CreateEnvironment怎么用?C++ Environment::CreateEnvironment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Environment
的用法示例。
在下文中一共展示了Environment::CreateEnvironment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: userName
Result<ExitCode> ProcessWithLogon::RunInternal(Trace& trace, const Settings& settings, ProcessTracker& processTracker, Environment& environment, bool changeIntegrityLevel) const
{
SECURITY_ATTRIBUTES securityAttributes = {};
securityAttributes.nLength = sizeof(SECURITY_DESCRIPTOR);
securityAttributes.bInheritHandle = true;
STARTUPINFO startupInfo = {};
startupInfo.dwFlags = STARTF_USESHOWWINDOW;
startupInfo.wShowWindow = ShowModeConverter::ToShowWindowFlag(settings.GetShowMode());
PROCESS_INFORMATION processInformation = {};
trace < L"ProcessTracker::InitializeConsoleRedirection";
processTracker.InitializeConsoleRedirection(securityAttributes, startupInfo);
StringBuffer userName(settings.GetUserName());
StringBuffer domain(settings.GetDomain());
StringBuffer password(settings.GetPassword());
StringBuffer workingDirectory(settings.GetWorkingDirectory());
StringBuffer commandLine(settings.GetCommandLine());
if (changeIntegrityLevel)
{
trace < L"::LogonUser";
auto newUserSecurityTokenHandle = Handle(L"New user security token");
if (!LogonUser(
userName.GetPointer(),
domain.GetPointer(),
password.GetPointer(),
LOGON32_LOGON_BATCH,
LOGON32_PROVIDER_DEFAULT,
&newUserSecurityTokenHandle))
{
return Error(L"LogonUser");
}
trace < L"::LoadUserProfile";
PROFILEINFO profileInfo = {};
profileInfo.dwSize = sizeof(PROFILEINFO);
profileInfo.lpUserName = userName.GetPointer();
if (!LoadUserProfile(newUserSecurityTokenHandle, &profileInfo))
{
return Error(L"LoadUserProfile");
}
SecurityManager securityManager;
auto setIntegrityLevelResult = securityManager.SetIntegrityLevel(settings.GetIntegrityLevel(), newUserSecurityTokenHandle, trace);
if (setIntegrityLevelResult.HasError())
{
return Result<ExitCode>(setIntegrityLevelResult.GetError());
}
trace < L"::CreateProcessWithTokenW";
if (!CreateProcessWithTokenW(
newUserSecurityTokenHandle,
LOGON_WITH_PROFILE,
nullptr,
commandLine.GetPointer(),
CREATE_UNICODE_ENVIRONMENT,
environment.CreateEnvironment(),
workingDirectory.GetPointer(),
&startupInfo,
&processInformation))
{
return Error(L"CreateProcessWithLogonW");
}
}
else
{
trace < L"::CreateProcessWithLogonW";
if (!CreateProcessWithLogonW(
userName.GetPointer(),
domain.GetPointer(),
password.GetPointer(),
LOGON_WITH_PROFILE,
nullptr,
commandLine.GetPointer(),
CREATE_UNICODE_ENVIRONMENT,
environment.CreateEnvironment(),
workingDirectory.GetPointer(),
&startupInfo,
&processInformation))
{
return Error(L"CreateProcessWithLogonW");
}
}
// ReSharper disable once CppInitializedValueIsAlwaysRewritten
auto processHandle = Handle(L"Process");
processHandle = processInformation.hProcess;
// ReSharper disable once CppInitializedValueIsAlwaysRewritten
auto threadHandle = Handle(L"Thread");
threadHandle = processInformation.hThread;
return processTracker.WaiteForExit(processInformation.hProcess, trace);
}