| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- // LoginOtherSystem.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "WinPadClientManager.h"
- #include "LoginOtherSystem.h"
- #include "afxdialogex.h"
- // LoginOtherSystem 对话框
- IMPLEMENT_DYNAMIC(LoginOtherSystem, CDialogEx)
- LoginOtherSystem::LoginOtherSystem(CWnd* pParent /*=NULL*/)
- : CDialogEx(LoginOtherSystem::IDD, pParent)
- {
- }
- LoginOtherSystem::~LoginOtherSystem()
- {
- }
- void LoginOtherSystem::DoDataExchange(CDataExchange* pDX)
- {
- CDialogEx::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(LoginOtherSystem, CDialogEx)
- ON_BN_CLICKED(IDOK, &LoginOtherSystem::OnBnClickedOk)
- ON_BN_CLICKED(IDCANCEL, &LoginOtherSystem::OnBnClickedCancel)
- END_MESSAGE_MAP()
- // LoginOtherSystem 消息处理程序
- static HANDLE CreateProcess(const char *app)
- {
- //BOOL bRet;
- STARTUPINFOA si = { sizeof(STARTUPINFOA) };
- si.wShowWindow = SW_SHOWMAXIMIZED;
- si.dwFlags = STARTF_USESHOWWINDOW;
- PROCESS_INFORMATION pi;
- DWORD dwSessionId;
- HANDLE hUserTokenDup, hThisToken;
- HANDLE hProcess = NULL;
- dwSessionId = WTSGetActiveConsoleSessionId();
- if (OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hThisToken)) {
- LUID luid;
- TOKEN_PRIVILEGES tp;
- LPVOID pEnv = NULL;
- LookupPrivilegeValueA(NULL, (LPCSTR)SE_DEBUG_NAME, &luid);
- tp.PrivilegeCount = 1;
- tp.Privileges[0].Luid = luid;
- tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- DuplicateTokenEx(hThisToken, MAXIMUM_ALLOWED, NULL,
- SecurityIdentification, TokenPrimary, &hUserTokenDup);
- SetTokenInformation(hUserTokenDup,
- TokenSessionId, (void*)dwSessionId, sizeof(DWORD));
- AdjustTokenPrivileges(hUserTokenDup, FALSE, &tp, sizeof(TOKEN_PRIVILEGES),
- (PTOKEN_PRIVILEGES)NULL, NULL);
- //CreateEnvironmentBlock(&pEnv,hUserTokenDup,TRUE);
- if (CreateProcessAsUserA(hUserTokenDup, NULL,
- (LPSTR)app, // "D:\\Source\\RVC\\RVCProject\\Release\\version\\1.0.0.1\\bin\\MetroWatcher64.exe 732",
- NULL, NULL, FALSE, 0, pEnv, NULL, &si, &pi))
- {
- CloseHandle(pi.hThread);
- hProcess = pi.hProcess;
- }
- else
- {
- //sp_dbg_warn("create process failed! Error : ", GetLastError());
- CString strErrNum;
- strErrNum.Format(_T("create process failed! Error:%d"), GetLastError());
- MessageBox(NULL, strErrNum.GetBuffer(), _T("错误提示"),0);
- }
-
- //if (pEnv)
- //DestroyEnvironmentBlock(pEnv);
- CloseHandle(hUserTokenDup);
- CloseHandle(hThisToken);
- }
- else {
- //sp_dbg_warn("open process token failed! Error : ", GetLastError());
- CString strErrNum;
- strErrNum.Format(_T("open process token failed! Error :%d"), GetLastError());
- MessageBox(NULL, strErrNum.GetBuffer(), _T("错误提示"),0);
- }
- return hProcess;
- }
- void LoginOtherSystem::OnBnClickedOk()
- {
- // TODO: 启动CmbPad.exe
- string strOfficeID = GetOfficeID();
-
- //HINSTANCE hNewExe = ShellExecuteA(NULL, "open", CLIENT_MANAGER_PATH, (LPCSTR)strOfficeID.c_str(), NULL, SW_SHOW);
- HINSTANCE hNewExe = ShellExecuteA(NULL, "runas", CLIENT_MANAGER_PATH, (LPCSTR)strOfficeID.c_str(), NULL, SW_SHOW);
- if ((DWORD)hNewExe <= 32)
- {
- MessageBoxA(NULL, (LPCSTR)("启动客户经理系统失败!"),NULL,0);
- EndDialog(IDCANCEL);
- }
- /*string strProcessName(CLIENT_MANAGER_PATH);
- strProcessName += " ";
- strProcessName += strOfficeID;
- CreateProcess(strProcessName.c_str());*/
- EndDialog(IDOK);
- //CDialogEx::OnOK();
- }
- void LoginOtherSystem::OnBnClickedCancel()
- {
- // TODO: 在此添加控件通知处理程序代码
- EndDialog(IDCANCEL);
- //CDialogEx::OnCancel();
- }
- void LoginOtherSystem::SetOfficeID(string strOfficeID)
- {
- m_strOfficeID = strOfficeID;
- }
- string LoginOtherSystem::GetOfficeID()
- {
- return m_strOfficeID;
- }
|