您的位置:首页 > 其它

以指定用户权限运行一个进程

2013-04-19 22:39 495 查看
转自http://blog.csdn.net/panpanloveruth/article/details/5728999

//以指定用户权限运行一个进程

BOOL CRunAsDlg::RunAsEx(LPWSTR lpCommandLine)

{

BOOL bRet = FALSE;

HINSTANCE hInst;//advapi32.dll句柄

hInst = ::LoadLibrary("advapi32.dll");

if(hInst)

{

typedef BOOL(WINAPI*MyCreateProcessWithLogonW)(LPCWSTR,LPCWSTR,LPCWSTR,DWORD,LPCWSTR,LPWSTR,DWORD,LPVOID,LPCWSTR,LPSTARTUPINFO,LPPROCESS_INFORMATION);

MyCreateProcessWithLogonW pAdd=(MyCreateProcessWithLogonW)::GetProcAddress(hInst,"CreateProcessWithLogonW");

if(pAdd)

{

// TODO: Place code here.

//LPCWSTR lpUsername = L"Administrator";

LPCWSTR lpUsername = m_sreAdmin.AllocSysString();

// user's name

LPCWSTR lpDomain = L"sc.com";

// user's domain

LPCWSTR lpPassword = m_strKey.AllocSysString(); //itAdmin*cg.03

//LPCWSTR lpPassword = L"itAdmin*cg.03"; //itAdmin*cg.03

// user's password

DWORD dwLogonFlags = 0x00000001;//LOGON_NETCREDENTIALS_ONLY;LOGON_WITH_PROFILE,

// logon option

LPCWSTR lpApplicationName = NULL;

// LPWSTR lpCommandLine = L"E://DWoW//Debug//DWoW.exe";

// command-line string

DWORD dwCreationFlags = 0x00000400;//CREATE_NEW_CONSOLE;

// creation flags

LPVOID lpEnvironment = NULL;

// new environment block

LPCWSTR lpCurrentDirectory = NULL;

// current directory name

STARTUPINFO StartupInfo;

// startup information

PROCESS_INFORMATION ProcessInfo;

// process information BOOL ret;

ZeroMemory(&StartupInfo, sizeof(StartupInfo));

StartupInfo.cb = sizeof(StartupInfo);

ZeroMemory(&ProcessInfo, sizeof(ProcessInfo));

//AfxMessageBox((CString)lpPassword);

bRet = pAdd( lpUsername,

lpDomain,

lpPassword,

dwLogonFlags,

lpCommandLine,

lpCommandLine,

dwCreationFlags,

lpEnvironment,

lpCurrentDirectory,

&StartupInfo,

&ProcessInfo );

}

}

return bRet;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐