CreateProcessWithLogonW 创建 IE 进程有些问题没能解决
用CreateProcessWithLogonW在winXP下以一个user权限运行IE,发现没有对收藏夹、“我的文档”等项目的访问权限,
但是以同样方式运行 Total Commander 时,不存在上述问题。这究竟是什么原因?
VC6+WinXP
//CreateProcessWithLogonW需要Platform SDK的库,只有UNICODE版本
//vc6在工程中在Project Setting-> C/C++ -> Preprocessor definition
//中必须添加 UNICODE, _UNICODE
#include "stdafx.h"
#include "stdio.h"
#include "wchar.h"
#include "Userenv.h"
#pragma comment(lib, "Userenv.lib")
int APIENTRY wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
DWORD dwSize;
HANDLE hToken;
LPVOID lpvEnv;
PROCESS_INFORMATION pi = {0};
STARTUPINFO si = {0};
WCHAR szUserProfile[256] = L"";
si.cb = sizeof(STARTUPINFO);
if (!LogonUserW(Username, Domain, PassWord,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, &hToken))
{
MessageBox(NULL, L"错误的用户名或密码!",
L"Error", MB_OK | MB_ICONWARNING | MB_APPLMODAL );
}
CreateEnvironmentBlock(&lpvEnv, hToken, TRUE);
dwSize = sizeof(szUserProfile)/sizeof(WCHAR);
GetUserProfileDirectory(hToken, szUserProfile, &dwSize);
CreateProcessWithLogonW(
Username, // user's name
Domain, // user's domain
PassWord, // user's password
LOGON_WITH_PROFILE, // logon option
Program, // executable module name
Parameter, // command-line string
CREATE_UNICODE_ENVIRONMENT, // creation flags
lpvEnv, // new environment block
szUserProfile, // current directory name
&si, // startup information
&pi // process information
);
return 0;
}