LoginOtherSystem.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // LoginOtherSystem.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "WinPadClientManager.h"
  5. #include "LoginOtherSystem.h"
  6. #include "afxdialogex.h"
  7. // LoginOtherSystem 对话框
  8. IMPLEMENT_DYNAMIC(LoginOtherSystem, CDialogEx)
  9. LoginOtherSystem::LoginOtherSystem(CWnd* pParent /*=NULL*/)
  10. : CDialogEx(LoginOtherSystem::IDD, pParent)
  11. {
  12. }
  13. LoginOtherSystem::~LoginOtherSystem()
  14. {
  15. }
  16. void LoginOtherSystem::DoDataExchange(CDataExchange* pDX)
  17. {
  18. CDialogEx::DoDataExchange(pDX);
  19. }
  20. BEGIN_MESSAGE_MAP(LoginOtherSystem, CDialogEx)
  21. ON_BN_CLICKED(IDOK, &LoginOtherSystem::OnBnClickedOk)
  22. ON_BN_CLICKED(IDCANCEL, &LoginOtherSystem::OnBnClickedCancel)
  23. END_MESSAGE_MAP()
  24. // LoginOtherSystem 消息处理程序
  25. static HANDLE CreateProcess(const char *app)
  26. {
  27. //BOOL bRet;
  28. STARTUPINFOA si = { sizeof(STARTUPINFOA) };
  29. si.wShowWindow = SW_SHOWMAXIMIZED;
  30. si.dwFlags = STARTF_USESHOWWINDOW;
  31. PROCESS_INFORMATION pi;
  32. DWORD dwSessionId;
  33. HANDLE hUserTokenDup, hThisToken;
  34. HANDLE hProcess = NULL;
  35. dwSessionId = WTSGetActiveConsoleSessionId();
  36. if (OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hThisToken)) {
  37. LUID luid;
  38. TOKEN_PRIVILEGES tp;
  39. LPVOID pEnv = NULL;
  40. LookupPrivilegeValueA(NULL, (LPCSTR)SE_DEBUG_NAME, &luid);
  41. tp.PrivilegeCount = 1;
  42. tp.Privileges[0].Luid = luid;
  43. tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  44. DuplicateTokenEx(hThisToken, MAXIMUM_ALLOWED, NULL,
  45. SecurityIdentification, TokenPrimary, &hUserTokenDup);
  46. SetTokenInformation(hUserTokenDup,
  47. TokenSessionId, (void*)dwSessionId, sizeof(DWORD));
  48. AdjustTokenPrivileges(hUserTokenDup, FALSE, &tp, sizeof(TOKEN_PRIVILEGES),
  49. (PTOKEN_PRIVILEGES)NULL, NULL);
  50. //CreateEnvironmentBlock(&pEnv,hUserTokenDup,TRUE);
  51. if (CreateProcessAsUserA(hUserTokenDup, NULL,
  52. (LPSTR)app, // "D:\\Source\\RVC\\RVCProject\\Release\\version\\1.0.0.1\\bin\\MetroWatcher64.exe 732",
  53. NULL, NULL, FALSE, 0, pEnv, NULL, &si, &pi))
  54. {
  55. CloseHandle(pi.hThread);
  56. hProcess = pi.hProcess;
  57. }
  58. else
  59. {
  60. //sp_dbg_warn("create process failed! Error : ", GetLastError());
  61. CString strErrNum;
  62. strErrNum.Format(_T("create process failed! Error:%d"), GetLastError());
  63. MessageBox(NULL, strErrNum.GetBuffer(), _T("错误提示"),0);
  64. }
  65. //if (pEnv)
  66. //DestroyEnvironmentBlock(pEnv);
  67. CloseHandle(hUserTokenDup);
  68. CloseHandle(hThisToken);
  69. }
  70. else {
  71. //sp_dbg_warn("open process token failed! Error : ", GetLastError());
  72. CString strErrNum;
  73. strErrNum.Format(_T("open process token failed! Error :%d"), GetLastError());
  74. MessageBox(NULL, strErrNum.GetBuffer(), _T("错误提示"),0);
  75. }
  76. return hProcess;
  77. }
  78. void LoginOtherSystem::OnBnClickedOk()
  79. {
  80. // TODO: 启动CmbPad.exe
  81. string strOfficeID = GetOfficeID();
  82. //HINSTANCE hNewExe = ShellExecuteA(NULL, "open", CLIENT_MANAGER_PATH, (LPCSTR)strOfficeID.c_str(), NULL, SW_SHOW);
  83. HINSTANCE hNewExe = ShellExecuteA(NULL, "runas", CLIENT_MANAGER_PATH, (LPCSTR)strOfficeID.c_str(), NULL, SW_SHOW);
  84. if ((DWORD)hNewExe <= 32)
  85. {
  86. MessageBoxA(NULL, (LPCSTR)("启动客户经理系统失败!"),NULL,0);
  87. EndDialog(IDCANCEL);
  88. }
  89. /*string strProcessName(CLIENT_MANAGER_PATH);
  90. strProcessName += " ";
  91. strProcessName += strOfficeID;
  92. CreateProcess(strProcessName.c_str());*/
  93. EndDialog(IDOK);
  94. //CDialogEx::OnOK();
  95. }
  96. void LoginOtherSystem::OnBnClickedCancel()
  97. {
  98. // TODO: 在此添加控件通知处理程序代码
  99. EndDialog(IDCANCEL);
  100. //CDialogEx::OnCancel();
  101. }
  102. void LoginOtherSystem::SetOfficeID(string strOfficeID)
  103. {
  104. m_strOfficeID = strOfficeID;
  105. }
  106. string LoginOtherSystem::GetOfficeID()
  107. {
  108. return m_strOfficeID;
  109. }