RvcInitalBase.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516
  1. #include "stdafx.h"
  2. #include "RvcInitalBase.h"
  3. #include "logfile.h"
  4. #include "EnvironmentConfig.h"
  5. CLogFile* m_log;
  6. HMODULE g_hDll = NULL;
  7. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(_T("kernel32")), "IsWow64Process");
  8. BOOL IsWow64()
  9. {
  10. BOOL bIsWow64 = FALSE;
  11. if (NULL != fnIsWow64Process)
  12. {
  13. if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
  14. {
  15. // handle error
  16. MessageBox(NULL, _T("判断当前操作系统是否是64位系统失败"), NULL, 0);
  17. }
  18. }
  19. return bIsWow64;
  20. }
  21. BOOL StrEqualNoCase(const char *s1, const char *s2, int len)
  22. {
  23. if (strlen(s1) != strlen(s2))
  24. return FALSE;
  25. for (int i = 0; i < len; ++i)
  26. {
  27. if (toupper(s1[i]) != toupper(s2[i]))
  28. return FALSE;
  29. }
  30. return TRUE;
  31. }
  32. BOOL StrEqual(const char *s1, const char *s2, int len)
  33. {
  34. for (int i = 0; i < len; ++i)
  35. {
  36. if (toupper(s1[i]) != toupper(s2[i]))
  37. return FALSE;
  38. }
  39. return TRUE;
  40. }
  41. BOOL ReadRootConfig(char** pcMachineType, char** pcSite)
  42. {
  43. if (NULL == pcMachineType
  44. || NULL == pcSite)
  45. {
  46. return FALSE;
  47. }
  48. ifstream is;
  49. string line = "";
  50. long curr = 0, end = 0;
  51. BOOL bFindSec = FALSE;
  52. BOOL bFindMachineType = FALSE;
  53. BOOL bFindSite = FALSE;
  54. char exePath[MAX_PATH];
  55. if (GetCurrentDirectoryA(MAX_PATH, exePath))
  56. strcat_s(exePath, "..\\..\\..\\hardwarecfg\\root.ini");
  57. is.open(ROOT_INI_PATH_C, ios::binary);
  58. if (!is.is_open())
  59. is.open(ROOT_INI_PATH_D, ios::binary);
  60. if (!is.is_open())
  61. is.open(exePath, ios::binary);
  62. if (!is.is_open())
  63. {
  64. MessageBoxA(NULL, (LPCSTR)("打开root.ini配置失败,请分行维护人员确认此RVC终端是否安装业务应用!"), NULL, 0);
  65. return FALSE;
  66. }
  67. is.seekg(0, ios_base::end);
  68. end = is.tellg();
  69. is.seekg(0, ios_base::beg);
  70. do
  71. {
  72. if (bFindMachineType && bFindSite)
  73. {
  74. is.close();
  75. return TRUE;
  76. }
  77. getline(is, line);
  78. cout << line << endl;
  79. if (line[0] == '[')
  80. {
  81. size_t secEnd = line.find(']', 1);
  82. if (secEnd != string::npos)
  83. {
  84. string strSec = line.substr(1, secEnd - 1);
  85. if (StrEqualNoCase(strSec.c_str(), "Terminal", strSec.length()))
  86. {
  87. bFindSec = TRUE;
  88. curr = is.tellg();
  89. continue;
  90. }
  91. }
  92. }
  93. else if (((unsigned)(line[0] + 1) > 256) || line[0] == ';')
  94. {//Chinese and other...
  95. curr = is.tellg();
  96. continue;
  97. }
  98. else if (isalpha(line[0]))
  99. {
  100. if (!bFindSec)
  101. {
  102. //没有找到section,继续查找下一行
  103. curr = is.tellg();
  104. continue;
  105. }
  106. size_t keyPos = line.find('=', 0);
  107. if (keyPos != string::npos)
  108. {
  109. string keyName = line.substr(0, keyPos);
  110. string keyValue = line.substr(keyPos + 1, line.length() - 1);
  111. if (StrEqualNoCase(keyName.c_str(), "MachineType", keyName.length()))
  112. {
  113. bFindMachineType = TRUE;
  114. //strcpy((char*)strMachineType.c_str(), keyValue.c_str());
  115. //memcpy(*pcMachineType, keyValue.c_str(), keyValue.length());
  116. memcpy(*pcMachineType, keyValue.c_str(), 24);
  117. cout << keyValue << endl;
  118. cout << *pcMachineType << endl;
  119. //cout<<
  120. curr = is.tellg();
  121. continue;
  122. }
  123. if (StrEqualNoCase(keyName.c_str(), "Site", keyName.length()))
  124. {
  125. bFindSite = TRUE;
  126. //memcpy(*pcSite, keyValue.c_str(), keyValue.length());
  127. memcpy(*pcSite, keyValue.c_str(), 24);
  128. curr = is.tellg();
  129. continue;
  130. }
  131. }
  132. }
  133. curr = is.tellg();
  134. } while (curr < end);
  135. is.close();
  136. if (!bFindMachineType)
  137. {
  138. MessageBoxA(NULL, (LPCSTR)("从root.ini读取MachineType配置项失败,请确认终端是否正确配置!"), NULL, 0);
  139. return FALSE;
  140. }
  141. if (!bFindSite)
  142. {
  143. MessageBoxA(NULL, (LPCSTR)("从root.ini读取Site配置项失败,请确认终端是否正确配置!"), NULL, 0);
  144. return FALSE;
  145. }
  146. return TRUE;
  147. }
  148. BOOL Execute(TCHAR* szExeName, TCHAR* szCommandLine)
  149. {
  150. TCHAR szModule[MAX_PATH] = { 0 };
  151. GetModuleFileName(NULL, szModule, sizeof(szModule));
  152. _tcscpy(_tcsrchr(szModule, '\\') + 1, szExeName);
  153. LPTSTR lpOp;
  154. lpOp = _T("runas");
  155. //lpOp = _T("open");
  156. //HINSTANCE hInst = ShellExecute(NULL, lpOp, szModule, szCommandLine , NULL, SW_HIDE);
  157. HINSTANCE hInst = ShellExecute(NULL, lpOp, szExeName, szCommandLine, NULL, SW_HIDE);
  158. if ((DWORD)hInst <= 32)
  159. {
  160. CString msg;
  161. msg.Format(_T("执行%s:%s失败,错误码:%d"), szExeName, szCommandLine, hInst);
  162. MessageBox(NULL, msg, NULL, 0);
  163. return FALSE;
  164. }
  165. return TRUE;
  166. }
  167. RvcInitBase::RvcInitBase()
  168. :processPath(_T(""))
  169. {
  170. m_log = new CLogFile();
  171. }
  172. RvcInitBase::RvcInitBase(char *logPath)
  173. :processPath(_T(""))
  174. {
  175. setLogPath(logPath);
  176. }
  177. void RvcInitBase::setLogPath(const char *logPath)
  178. {
  179. char dirpath[300] = "";
  180. strncpy_s(dirpath, logPath, strlen(logPath));
  181. for (int i = strlen(logPath) - 1; i > 0; i--)
  182. {
  183. if (dirpath[i] == '\\')
  184. {
  185. dirpath[i] = '\0';
  186. break;
  187. }
  188. }
  189. if (!checkDirExist(CString(dirpath)))
  190. return;
  191. if (!m_log)
  192. m_log = new CLogFile(logPath);
  193. else
  194. m_log->reset(logPath);
  195. }
  196. CString RvcInitBase::getInitError()
  197. {
  198. return lastErr;
  199. }
  200. BOOL RvcInitBase::isSystem_x64()
  201. {
  202. return m_bIsWow64;
  203. }
  204. BOOL RvcInitBase::readSysType()
  205. {
  206. TCHAR Path[1024] = _T("");
  207. if (0 == GetCurrentDirectory(1024, Path))
  208. return FALSE;
  209. else
  210. processPath = Path;
  211. char* pcMachineType, *pcSite;
  212. string strMachineType, strSite;
  213. BOOL bRet;
  214. pcMachineType = new char[24];
  215. pcSite = new char[24];
  216. memset(pcMachineType, 0, 24);
  217. memset(pcSite, 0, 24);
  218. bRet = ReadRootConfig(&pcMachineType, &pcSite);
  219. if (!bRet)
  220. {
  221. m_log->LOGERROR("从root.ini读取机型和场所失败!");
  222. delete pcMachineType;
  223. delete pcSite;
  224. return FALSE;
  225. }
  226. else
  227. {
  228. //机型判断
  229. strMachineType = pcMachineType;
  230. m_bPad = StrEqual(strMachineType.c_str(), MACHINE_TYPE_PAD, 7);
  231. //场所判断
  232. strSite = pcSite;
  233. m_bFlb = StrEqual(strSite.c_str(), SITE_FLB, 7);
  234. m_log->LOGERROR("机型:%s, 场所:%s", pcMachineType, pcSite);
  235. }
  236. delete pcMachineType;
  237. delete pcSite;
  238. return TRUE;
  239. }
  240. SYSTEM_TYPE RvcInitBase::getSysType()
  241. {
  242. if (m_bPad && m_bFlb)
  243. return PAD_FLB;
  244. else if (m_bPad && (!m_bFlb))
  245. return PAD_LIB;
  246. else if ((!m_bPad) && (!m_bFlb))
  247. return CMB_LIB;
  248. else if ((!m_bPad) && m_bFlb)
  249. return CMB_FLB;
  250. return ERROR_TYPE;
  251. }
  252. BOOL RvcInitBase::softwareInit(char *dirPath)
  253. {
  254. m_log->LOGERROR("Begin SoftwareInit");
  255. if (NULL == m_log)
  256. {
  257. lastErr = CString(_T("无法读取Log文件"));
  258. return FALSE;
  259. }
  260. if (!readSysType())
  261. {
  262. lastErr = CString(_T("读取root.ini文件失败"));
  263. return FALSE;
  264. }
  265. //创建库文件目录
  266. DWORD dwAttr = GetFileAttributes(RVC_DIR);
  267. if (dwAttr == 0xFFFFFFFF) //目录不存在则创建
  268. {
  269. if (!CreateDirectory(RVC_DIR, NULL))
  270. {
  271. lastErr = CString(_T("创建RVC目录失败!"));
  272. m_log->LOGERROR("创建RVC目录失败!");
  273. return FALSE;
  274. }
  275. }
  276. dwAttr = GetFileAttributes(_T(IINT_DIR));
  277. if (dwAttr == 0xFFFFFFFF) //目录不存在则创建
  278. {
  279. if (!CreateDirectory(_T(IINT_DIR), NULL))
  280. {
  281. lastErr = CString(_T("创建SystemInit目录失败!"));
  282. m_log->LOGERROR("创建SystemInit目录失败!");
  283. return FALSE;
  284. }
  285. }
  286. m_bIsWow64 = IsWow64();
  287. //停止系统服务
  288. KillSystemService();
  289. //拷贝库文件
  290. if (!CopyAllDll(dirPath))
  291. {
  292. lastErr = CString(_T("Dll文件拷贝失败"));
  293. m_log->LOGERROR("Dll文件拷贝失败");
  294. return FALSE;
  295. }
  296. else
  297. m_log->LOGERROR("所有Dll文件拷贝成功");
  298. //加载库文件
  299. for (int i = 0; i < 40; i++)
  300. {
  301. Sleep(100);
  302. if (NULL != (g_hDll = LoadLibrary(DLL_FILE)))
  303. break;
  304. }
  305. if (g_hDll == NULL)
  306. {
  307. lastErr = CString(_T("LoadLibrary C:\\RVC\\SystemInit\\CmbPadDll.dll 失败!"));
  308. m_log->LOGERROR("LoadLibrary C:\\RVC\\SystemInit\\CmbPadDll.dll 失败!");
  309. return FALSE;
  310. }
  311. return TRUE;
  312. }
  313. RvcInitBase::~RvcInitBase()
  314. {
  315. if (m_log)
  316. {
  317. delete m_log;
  318. m_log = NULL;
  319. }
  320. }
  321. BOOL RvcInitBase::checkSystemLogon()
  322. {
  323. LONG lRet;
  324. HKEY logonKey;
  325. TCHAR szKeyPath[MAX_PATH] = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\Credential Providers\\{75A22DF0-B81D-46ed-B119-CD30507BD615}");
  326. if (ERROR_SUCCESS != (lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, CString(szKeyPath), 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &logonKey)))
  327. {
  328. m_log->LOGERROR("打开注册表HKEY_LOCAL_MACHINE\\%s失败,错误码:%d", szKeyPath, lRet);
  329. return FALSE;
  330. }
  331. else
  332. {
  333. m_log->LOGERROR("删除祖册表HKEY_LOCAL_MACHINE\\%s成功", szKeyPath);
  334. }
  335. return TRUE;
  336. }
  337. BOOL RvcInitBase::SetSystemLogon()
  338. {
  339. HKEY hKey;
  340. LONG lRet;
  341. DWORD dwDisposition;
  342. TCHAR szKeyPath[MAX_PATH] = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\Credential Providers\\{75A22DF0-B81D-46ed-B119-CD30507BD615}");
  343. lRet = ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKeyPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS | KEY_WOW64_64KEY, NULL, &hKey, &dwDisposition);
  344. if (ERROR_SUCCESS != lRet)
  345. {
  346. m_log->LOGERROR("添加注册表HKEY_LOCAL_MACHINE\\%s失败,错误码:%d", szKeyPath, lRet);
  347. return FALSE;
  348. }
  349. else
  350. {
  351. TCHAR szKeyValue[MAX_PATH] = _T("SampleHardwareEventCredentialProvider");
  352. lRet = RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)szKeyValue, _tcslen(szKeyValue) * sizeof(TCHAR) + 1);
  353. if (ERROR_SUCCESS != lRet)
  354. {
  355. m_log->LOGERROR("添加注册表HKEY_LOCAL_MACHINE\\%s失败,错误码:%d", szKeyValue, lRet);
  356. return FALSE;
  357. }
  358. }
  359. RegCloseKey(hKey);
  360. TCHAR szKeyPath2[MAX_PATH] = _T("CLSID\\{75A22DF0-B81D-46ed-B119-CD30507BD615}");
  361. lRet = ::RegCreateKeyEx(HKEY_CLASSES_ROOT, szKeyPath2, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS | KEY_WOW64_64KEY, NULL, &hKey, &dwDisposition);
  362. if (ERROR_SUCCESS != lRet)
  363. {
  364. m_log->LOGERROR("添加注册表HKEY_CLASSES_ROOT\\%s失败,错误码:%d", szKeyPath2, lRet);
  365. return FALSE;
  366. }
  367. else
  368. {
  369. TCHAR szKeyValue[MAX_PATH] = _T("SampleHardwareEventCredentialProvider");
  370. lRet = RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)szKeyValue, _tcslen(szKeyValue) * sizeof(TCHAR) + 1);
  371. if (ERROR_SUCCESS != lRet)
  372. {
  373. m_log->LOGERROR("写注册表HKEY_CLASSES_ROOT\\%s键值失败,错误码:%d", szKeyValue, lRet);
  374. return FALSE;
  375. }
  376. }
  377. RegCloseKey(hKey);
  378. TCHAR szKeyPath3[MAX_PATH] = _T("CLSID\\{75A22DF0-B81D-46ed-B119-CD30507BD615}\\InprocServer32");
  379. lRet = ::RegCreateKeyEx(HKEY_CLASSES_ROOT, szKeyPath3, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS | KEY_WOW64_64KEY, NULL, &hKey, &dwDisposition);
  380. if (ERROR_SUCCESS != lRet)
  381. {
  382. m_log->LOGERROR("添加注册表HKEY_CLASSES_ROOT\\%s失败,错误码:%d", szKeyPath3, lRet);
  383. return FALSE;
  384. }
  385. else
  386. {
  387. TCHAR szKeyValue[MAX_PATH] = _T("SampleHardwareEventCredentialProvider.dll");
  388. //lRet = RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)szKeyValue, sizeof(szKeyValue));
  389. lRet = RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)szKeyValue, _tcslen(szKeyValue) * sizeof(TCHAR) + 1);
  390. if (ERROR_SUCCESS != lRet)
  391. {
  392. m_log->LOGERROR("写注册表HKEY_CLASSES_ROOT\\%s键值失败,错误码:%d", szKeyValue, lRet);
  393. return FALSE;
  394. }
  395. TCHAR szKeyValue2[MAX_PATH] = _T("Apartment");
  396. //lRet = RegSetValueEx(hKey, "ThreadingModel", 0, REG_SZ, (BYTE*)szKeyValue2, sizeof(szKeyValue2));
  397. lRet = RegSetValueEx(hKey, _T("ThreadingModel"), 0, REG_SZ, (BYTE*)szKeyValue2, _tcslen(szKeyValue2) * sizeof(TCHAR) + 1);
  398. if (ERROR_SUCCESS != lRet)
  399. {
  400. m_log->LOGERROR("写注册表HKEY_CLASSES_ROOT\\%s键值失败,错误码:%d", szKeyValue2, lRet);
  401. return FALSE;
  402. }
  403. }
  404. RegCloseKey(hKey);
  405. return TRUE;
  406. }
  407. BOOL RvcInitBase::DisableSystemLogon()
  408. {
  409. HKEY logonKey, startKey = NULL;
  410. LONG lRet;
  411. TCHAR szKeyPath[MAX_PATH] = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\Credential Providers\\{75A22DF0-B81D-46ed-B119-CD30507BD615}");
  412. if (ERROR_SUCCESS != (lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKeyPath, 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &startKey)))
  413. m_log->LOGERROR("打开HKEY_LOCAL_MACHINE\\%s失败,错误码:%d", szKeyPath, lRet);
  414. else
  415. {
  416. RegCloseKey(startKey);
  417. if (ERROR_SUCCESS != (lRet = ::RegDeleteKeyEx(HKEY_LOCAL_MACHINE, szKeyPath, KEY_ALL_ACCESS | KEY_WOW64_64KEY, 0)))
  418. {
  419. m_log->LOGERROR("删除注册表HKEY_LOCAL_MACHINE\\%s失败,错误码:%d", szKeyPath, lRet);
  420. return FALSE;
  421. }
  422. else
  423. {
  424. m_log->LOGERROR("删除祖册表HKEY_LOCAL_MACHINE\\%s成功", szKeyPath);
  425. }
  426. }
  427. TCHAR logonPath[MAX_PATH] = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon");
  428. TCHAR logonStr[MAX_PATH] = _T("explorer.exe");
  429. if (ERROR_SUCCESS != (lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, logonPath, 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &logonKey)))
  430. {
  431. m_log->LOGERROR("打开HKEY_LOCAL_MACHINE\\%s失败,错误码:%d", logonKey, lRet);
  432. return FALSE;
  433. }
  434. if (ERROR_SUCCESS != (lRet = ::RegSetValueEx(logonKey, _T("Shell"), 0, REG_SZ, (BYTE*)logonStr, _tcslen(logonStr) * sizeof(TCHAR) + 1)))
  435. {
  436. m_log->LOGERROR("写注册表HKEY_LOCAL_MACHINE\\%s\\%s键值失败,错误码:%d", logonKey, logonStr, lRet);
  437. return FALSE;
  438. }
  439. RegCloseKey(logonKey);
  440. return TRUE;
  441. }
  442. BOOL RvcInitBase::SetSystemStart()
  443. {
  444. CString strExePath(IINT_DIR);
  445. strExePath += CString(_T("\\InstallServer.exe"));
  446. //BOOL bRet = Execute(_T("InstallServer.exe"),NULL);
  447. BOOL bRet = Execute(strExePath.GetBuffer(), NULL);
  448. if (!bRet)
  449. {
  450. m_log->LOGERROR("安装CmbService系统服务失败.");
  451. return FALSE;
  452. }
  453. return TRUE;
  454. }
  455. BOOL RvcInitBase::DisableSystemStart()
  456. {
  457. if (isServiceExist(_T("CmbRvcInitialService")))
  458. {
  459. int iRet = system("sc delete CmbRvcInitialService");
  460. if (ERROR_SUCCESS != iRet)
  461. m_log->LOGERROR("删除CmbRvcInitialService系统服务失败");
  462. else
  463. m_log->LOGERROR("删除CmbRvcInitialService系统服务成功");
  464. }
  465. pDisableKeyboard DisableKeyboard = (pDisableKeyboard)GetProcAddress(g_hDll, "DisableKeyboard");
  466. if (NULL != DisableKeyboard)
  467. {
  468. DisableKeyboard(FALSE);
  469. m_log->LOGERROR("启用键盘成功");
  470. }
  471. else
  472. {
  473. m_log->LOGERROR("启用键盘失败");
  474. }
  475. pWlanConnect WlanConnect = (pWlanConnect)GetProcAddress(g_hDll, "WlanConnect");
  476. if (NULL != WlanConnect)
  477. {
  478. DWORD dwRet = WlanConnect(TRUE, NET_TYPE_ETHERNET);
  479. if (ERROR_SUCCESS != dwRet)
  480. {
  481. m_log->LOGERROR("启用ethernet 失败, errcode= %d", dwRet);
  482. }
  483. else
  484. {
  485. m_log->LOGERROR("启用ethernet 成功");
  486. }
  487. dwRet = WlanConnect(TRUE, NET_TYPE_WIRELESS);
  488. if (ERROR_SUCCESS != dwRet)
  489. {
  490. m_log->LOGERROR("启用wireless 失败, errcode= %d", dwRet);
  491. }
  492. else
  493. {
  494. m_log->LOGERROR("启用wireless 成功");
  495. }
  496. dwRet = WlanConnect(TRUE, NET_TYPE_3G);
  497. if (ERROR_SUCCESS != dwRet)
  498. {
  499. m_log->LOGERROR("启用3G network 失败, errcode= %d", dwRet);
  500. }
  501. else
  502. {
  503. m_log->LOGERROR("启用3G network 成功");
  504. }
  505. dwRet = WlanConnect(TRUE, NET_TYPE_4G);
  506. if (ERROR_SUCCESS != dwRet)
  507. {
  508. m_log->LOGERROR("启用4G network 失败, errcode= %d", dwRet);
  509. }
  510. else
  511. {
  512. m_log->LOGERROR("启用4G network成功");
  513. }
  514. pDisableBluetooth DisableBluetooth = (pDisableBluetooth)GetProcAddress(g_hDll, "DisableBluetooth");
  515. if (NULL == DisableBluetooth)
  516. {
  517. m_log->LOGERROR("GetProcAddress DisableBluetooth failed");
  518. }
  519. else
  520. {
  521. dwRet = DisableBluetooth(FALSE);
  522. if (ERROR_SUCCESS != dwRet)
  523. {
  524. m_log->LOGERROR("启用Bluetooth失败, errcode= %d", dwRet);
  525. }
  526. else
  527. {
  528. m_log->LOGERROR("启用Bluetooth成功");
  529. }
  530. }
  531. }
  532. else
  533. {
  534. m_log->LOGERROR("GetProcAddress WlanConnect from CmbPadDll.dll失败");
  535. }
  536. return TRUE;
  537. }
  538. BOOL RvcInitBase::KillSystemService()
  539. {
  540. int iRet = SYSTEM_ON(CString(_T("sc stop CmbRvcInitialService")));
  541. if (ERROR_SUCCESS != iRet)
  542. {
  543. m_log->LOGERROR("停止CmbRvcInitialService系统服务失败");
  544. }
  545. else
  546. {
  547. m_log->LOGERROR("停止CmbRvcInitialService系统服务成功");
  548. }
  549. return TRUE;
  550. }
  551. BOOL RvcInitBase::FileCopy(const char* pcSourceFile, const char* pcDestDir)
  552. {
  553. if (NULL == pcSourceFile || NULL == pcDestDir)
  554. return FALSE;
  555. PVOID OldValue = NULL;
  556. CString logMsg;
  557. string tempFilePath, tempFileName;
  558. CString srcFile, dstDir;
  559. MultiByteToCString(const_cast<char*>(pcSourceFile), strlen(pcSourceFile) + 1, srcFile);
  560. MultiByteToCString(const_cast<char*>(pcDestDir), strlen(pcDestDir) + 1, dstDir);
  561. if (!checkFileExist(srcFile) || !checkDirExist(dstDir))//对于源文件,只需要读权限
  562. {
  563. logMsg.Format(_T("%s文件不存在"), srcFile);
  564. char tempStr[1024];
  565. CStringToMultiByte(logMsg, tempStr, logMsg.GetLength() + 1);
  566. m_log->LOGERROR(tempStr);
  567. return FALSE;
  568. }
  569. tempFilePath = string(pcSourceFile);
  570. int pos = tempFilePath.find_last_of('\\');
  571. tempFileName = string(tempFilePath.substr(pos + 1));
  572. CString desFilePath = dstDir + CString("\\") + CString(tempFileName.data());
  573. if (checkFileExist(desFilePath) && !checkFileOcuppy(desFilePath))//对于目的文件,需要读写权限
  574. {
  575. logMsg.Format(_T("%s文件已存在,且文件被占用"), desFilePath);
  576. char tempStr[1024];
  577. CStringToMultiByte(logMsg, tempStr, logMsg.GetLength() + 1);
  578. m_log->LOGERROR(tempStr);
  579. return TRUE;
  580. }
  581. //如果是64位系统,需取消文件的重定向,并在完成指定功能后恢复程序文件重定向
  582. //否则,会被重定向到Syswow64目录下(比如想拷贝文件到system32时,会自动拷贝到Syswow64目录下)
  583. if (m_bIsWow64)
  584. {
  585. if (!Wow64DisableWow64FsRedirection(&OldValue))
  586. {
  587. m_log->LOGERROR("64位系统时,调用Wow64DisableWow64FsRedirection文件重定向失败");
  588. return FALSE;
  589. }
  590. }
  591. CString strCmd = _T("copy /y ") + CString(pcSourceFile) + CString(" ") + desFilePath;
  592. int iRet = SYSTEM_ON(strCmd);
  593. if (ERROR_SUCCESS != iRet)
  594. {
  595. m_log->LOGERROR("%s拷贝到%s失败", pcSourceFile, pcDestDir);
  596. return FALSE;
  597. }
  598. else
  599. {
  600. m_log->LOGERROR("%s拷贝到%s成功", pcSourceFile, pcDestDir);
  601. }
  602. if (m_bIsWow64)
  603. {
  604. if (FALSE == Wow64RevertWow64FsRedirection(OldValue))
  605. {
  606. m_log->LOGERROR("64位系统时,调用Wow64RevertWow64FsRedirection恢复文件重定向失败");
  607. return FALSE;
  608. }
  609. }
  610. return TRUE;
  611. }
  612. BOOL RvcInitBase::DirCopy(const char* pcSourceDir, const char* pcDestDir)
  613. {
  614. PVOID OldValue = NULL;
  615. //如果是64位系统,需取消文件的重定向,并在完成指定功能后恢复程序文件重定向
  616. //否则,会被重定向到Syswow64目录下(比如想拷贝文件到system32时,会自动拷贝到Syswow64目录下)
  617. if (m_bIsWow64)
  618. {
  619. if (!Wow64DisableWow64FsRedirection(&OldValue))
  620. {
  621. m_log->LOGERROR("64位系统时,调用Wow64DisableWow64FsRedirection文件重定向失败");
  622. return FALSE;
  623. }
  624. }
  625. CStringA strCmd("xcopy /E /I /y ");
  626. strCmd += pcSourceDir;
  627. strCmd += " ";
  628. strCmd += pcDestDir;
  629. int iRet = SYSTEM_ON(strCmd);
  630. if (ERROR_SUCCESS != iRet)
  631. {
  632. m_log->LOGERROR("%s拷贝到%s失败", pcSourceDir, pcDestDir);
  633. return FALSE;
  634. }
  635. else
  636. {
  637. m_log->LOGERROR("%s拷贝到%s成功", pcSourceDir, pcDestDir);
  638. }
  639. if (m_bIsWow64)
  640. {
  641. if (FALSE == Wow64RevertWow64FsRedirection(OldValue))
  642. {
  643. m_log->LOGERROR("64位系统时,调用Wow64RevertWow64FsRedirection恢复文件重定向失败");
  644. return FALSE;
  645. }
  646. }
  647. return TRUE;
  648. }
  649. /* 大机版接口 begin */
  650. //设置shell脚本运行权限
  651. BOOL RvcInitBase::EnableShell()
  652. {
  653. int iRet = system("powershell Set-ExecutionPolicy RemoteSigned");
  654. if (ERROR_SUCCESS != iRet)
  655. {
  656. m_log->LOGERROR("设置shell脚本运行权限失败");
  657. return FALSE;
  658. }
  659. return TRUE;
  660. }
  661. //启用/禁用F8进入安全模式
  662. BOOL RvcInitBase::EnableF8()
  663. {
  664. int iRet = system("bcdedit.exe -set {globalsettings} advancedoptions ture");
  665. if (ERROR_SUCCESS != iRet)
  666. {
  667. m_log->LOGERROR("启用F8进入安全模式失败");
  668. return FALSE;
  669. }
  670. return TRUE;
  671. }
  672. BOOL RvcInitBase::DisableF8()
  673. {
  674. int iRet = system("bcdedit.exe -set {globalsettings} advancedoptions FALSE");
  675. if (ERROR_SUCCESS != iRet)
  676. {
  677. m_log->LOGERROR("禁用F8进入安全模式失败");
  678. return FALSE;
  679. }
  680. return TRUE;
  681. }
  682. //开启/关闭EmbeddedLockdown服务
  683. BOOL RvcInitBase::EnableELM()
  684. {
  685. int iRet = system("Dism /online /Enable-Feature /FeatureName:ISKU-EmbeddedLockdown /all");
  686. if (ERROR_SUCCESS != iRet)
  687. {
  688. m_log->LOGERROR("开启EmbeddedLockdown失败");
  689. return FALSE;
  690. }
  691. return TRUE;
  692. }
  693. BOOL RvcInitBase::DisableELM()
  694. {
  695. int iRet = system("Dism /online /Disable-Feature /FeatureName:ISKU-EmbeddedLockdown");
  696. if (ERROR_SUCCESS != iRet)
  697. {
  698. m_log->LOGERROR("关闭EmbeddedLockdown失败");
  699. return FALSE;
  700. }
  701. return TRUE;
  702. }
  703. //开启/关闭键盘过滤服务
  704. BOOL RvcInitBase::EnableKeyBoardFilter()
  705. {
  706. int iRet = system("Dism /online /Enable-Feature /FeatureName:ISKU-KeyboardFilter /all");
  707. if (ERROR_SUCCESS != iRet)
  708. {
  709. m_log->LOGERROR("开启键盘过滤失败");
  710. return FALSE;
  711. }
  712. return TRUE;
  713. }
  714. BOOL RvcInitBase::DisableKeyBoardFilter()
  715. {
  716. int iRet = system("Dism /online /Disable-Feature /FeatureName:ISKU-KeyboardFilter");
  717. if (ERROR_SUCCESS != iRet)
  718. {
  719. m_log->LOGERROR("关闭键盘过滤失败");
  720. return FALSE;
  721. }
  722. return TRUE;
  723. }
  724. //启用/屏蔽特殊按键,除了数字和字母键外的其它所有按键
  725. BOOL RvcInitBase::EnableKey()
  726. {
  727. return TRUE;
  728. }
  729. BOOL RvcInitBase::DisableKey()
  730. {
  731. return TRUE;
  732. }
  733. //开启/关闭shellLauncher服务
  734. BOOL RvcInitBase::EnableShellLauncher()
  735. {
  736. int iRet = system("Dism /online /Enable-Feature /FeatureName:ISKU-Shell-Launcher /all");
  737. if (ERROR_SUCCESS != iRet)
  738. {
  739. m_log->LOGERROR("开启shellLauncher服务失败");
  740. return FALSE;
  741. }
  742. return TRUE;
  743. }
  744. BOOL RvcInitBase::DisableShellLauncher()
  745. {
  746. int iRet = system("Dism /online /Disable-Feature /FeatureName:ISKU-Shell-Launcher");
  747. if (ERROR_SUCCESS != iRet)
  748. {
  749. m_log->LOGERROR("关闭shellLauncher服务失败");
  750. return FALSE;
  751. }
  752. return TRUE;
  753. }
  754. //设置启动程序
  755. BOOL RvcInitBase::SetCustomerShell()
  756. {
  757. return TRUE;
  758. }
  759. //开启/关闭磁盘保护服务
  760. BOOL RvcInitBase::EnableUWF()
  761. {
  762. int iRet = system("Dism /online /Enable-Feature /FeatureName:ISKU-UnifiedWriteFilter /all");
  763. if (ERROR_SUCCESS != iRet)
  764. {
  765. m_log->LOGERROR("开启磁盘保护服务失败");
  766. return FALSE;
  767. }
  768. return TRUE;
  769. }
  770. BOOL RvcInitBase::DisableUWF()
  771. {
  772. int iRet = system("Dism /online /Disable-Feature /FeatureName:ISKU-UnifiedWriteFilter");
  773. if (ERROR_SUCCESS != iRet)
  774. {
  775. m_log->LOGERROR("关闭磁盘保护服务失败");
  776. return FALSE;
  777. }
  778. return TRUE;
  779. }
  780. //开启/关闭C盘保护
  781. BOOL RvcInitBase::EnableProtectC()
  782. {
  783. int iRet = system("uwfmgr.exe filter enable");
  784. if (ERROR_SUCCESS != iRet)
  785. {
  786. m_log->LOGERROR("开启硬盘保护失败");
  787. return FALSE;
  788. }
  789. iRet = system("uwfmgr.exe volume protect c:");
  790. if (ERROR_SUCCESS != iRet)
  791. {
  792. m_log->LOGERROR("开启C盘保护失败");
  793. return FALSE;
  794. }
  795. return TRUE;
  796. }
  797. BOOL RvcInitBase::DisableProtectC()
  798. {
  799. int iRet = system("uwfmgr.exe volume Unprotect c:");
  800. if (ERROR_SUCCESS != iRet)
  801. {
  802. m_log->LOGERROR("关闭C盘保护失败");
  803. return FALSE;
  804. }
  805. iRet = system("uwfmgr.exe filter disable");
  806. if (ERROR_SUCCESS != iRet)
  807. {
  808. m_log->LOGERROR("关闭硬盘保护失败");
  809. return FALSE;
  810. }
  811. return TRUE;
  812. }
  813. BOOL RvcInitBase::SetEvn()
  814. {
  815. return DisableF8() && EnableELM() && EnableKeyBoardFilter() && EnableShellLauncher();
  816. }
  817. //设置组策略
  818. BOOL RvcInitBase::EnablePolicy()
  819. {
  820. PVOID OldValue = NULL;
  821. if (m_bIsWow64)
  822. {
  823. if (!Wow64DisableWow64FsRedirection(&OldValue))
  824. {
  825. m_log->LOGERROR("64位系统时,调用Wow64DisableWow64FsRedirection文件重定向失败");
  826. return FALSE;
  827. }
  828. }
  829. //调用设置组策略脚本
  830. HINSTANCE hNewExe = ShellExecuteA(NULL, "runas", "C:\\RVC\\SystemInit\\EnablePolicy.bat", NULL, NULL, SW_SHOW);
  831. if ((DWORD)hNewExe <= 32)
  832. {
  833. m_log->LOGERROR("组策略设置失败");
  834. return FALSE;
  835. }
  836. if (m_bIsWow64)
  837. {
  838. if (FALSE == Wow64RevertWow64FsRedirection(OldValue))
  839. {
  840. m_log->LOGERROR("64位系统时,调用Wow64RevertWow64FsRedirection恢复文件重定向失败");
  841. return FALSE;
  842. }
  843. }
  844. return TRUE;
  845. }
  846. BOOL RvcInitBase::DisblePolicy()
  847. {
  848. PVOID OldValue = NULL;
  849. if (m_bIsWow64)
  850. {
  851. if (!Wow64DisableWow64FsRedirection(&OldValue))
  852. {
  853. m_log->LOGERROR("64位系统时,调用Wow64DisableWow64FsRedirection文件重定向失败");
  854. return FALSE;
  855. }
  856. }
  857. //调用删除组策略脚本
  858. HINSTANCE hNewExe = ShellExecuteA(NULL, "runas", "C:\\RVC\\SystemInit\\DisablePolicy.bat", NULL, NULL, SW_SHOW);
  859. if ((DWORD)hNewExe <= 32)
  860. {
  861. m_log->LOGERROR("取消组策略失败");
  862. return FALSE;
  863. }
  864. if (m_bIsWow64)
  865. {
  866. if (FALSE == Wow64RevertWow64FsRedirection(OldValue))
  867. {
  868. m_log->LOGERROR("64位系统时,调用Wow64RevertWow64FsRedirection恢复文件重定向失败");
  869. return FALSE;
  870. }
  871. }
  872. return TRUE;
  873. }
  874. BOOL RvcInitBase::CopyAllDll(char *dirPath)
  875. {
  876. PVOID OldValue = NULL;
  877. BOOL bRet = FALSE;
  878. char pcExePath[2000];
  879. //如果是64位系统,需取消文件的重定向,并在完成指定功能后恢复程序文件重定向
  880. //否则,会被重定向到Syswow64目录下(比如_access检测文件是否存在,会检测到Syswow64目录,拷贝文件也如此)
  881. if (m_bIsWow64)
  882. {
  883. if (!Wow64DisableWow64FsRedirection(&OldValue))
  884. {
  885. m_log->LOGERROR("64位系统时,调用Wow64DisableWow64FsRedirection文件重定向失败");
  886. return FALSE;
  887. }
  888. }
  889. //得到当前的工作路径
  890. if (NULL == dirPath)
  891. {
  892. if (0 == GetCurrentDirectoryA(2000, pcExePath))
  893. {
  894. m_log->LOGERROR("_getcwderror");
  895. return FALSE;
  896. }
  897. }
  898. else
  899. memcpy(pcExePath, dirPath, strlen(dirPath) + 1);
  900. CStringA strExePath(pcExePath);
  901. CStringA strFilePath(strExePath);
  902. checkDirExist(CString(_T("C:\\RVC")));
  903. //拷贝系统登陆模块相关库文件,需要区分32/64位
  904. CStringA headDir = "RvcInit";
  905. if (!m_bIsWow64)
  906. {
  907. //32位系统
  908. strFilePath += "\\" + headDir + "\\32\\msvcr100.dll";
  909. bRet = FileCopy(strFilePath.GetBuffer(), DLL_PATH);
  910. if (!bRet)
  911. return FALSE;
  912. strFilePath = strExePath;
  913. strFilePath += "\\" + headDir + "\\32\\msvcr100d.dll";
  914. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  915. if (!bRet)
  916. return FALSE;
  917. strFilePath = strExePath;
  918. strFilePath += "\\" + headDir + "\\32\\msvcp100d.dll";
  919. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  920. if (!bRet)
  921. return FALSE;
  922. strFilePath = strExePath;
  923. strFilePath += "\\" + headDir + "\\32\\libeay32.dll";
  924. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  925. if (!bRet)
  926. return FALSE;
  927. strFilePath = strExePath;
  928. strFilePath += "\\" + headDir + "\\32\\VerifyCertificate.dll";
  929. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  930. if (!bRet)
  931. return FALSE;
  932. strFilePath = strExePath;
  933. strFilePath += "\\" + headDir + "\\32\\USBKeyAPI.dll";
  934. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  935. if (!bRet)
  936. return FALSE;
  937. strFilePath = strExePath;
  938. strFilePath += "\\" + headDir + "\\32\\WinSystemLogon.dll";
  939. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  940. if (!bRet)
  941. return FALSE;
  942. strFilePath = strExePath;
  943. strFilePath += "\\" + headDir + "\\32\\SampleHardwareEventCredentialProvider.dll";
  944. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  945. if (!bRet)
  946. return FALSE;
  947. strFilePath = strExePath;
  948. strFilePath += "\\" + headDir + "\\32\\lsrunas.exe";
  949. bRet = FileCopy(strFilePath.GetBuffer(0), EXE_PATH);
  950. if (!bRet)
  951. return FALSE;
  952. strFilePath = strExePath;
  953. strFilePath += "\\" + headDir + "\\32\\devcon.exe";
  954. bRet = FileCopy(strFilePath.GetBuffer(0), strExePath.GetBuffer(0));
  955. if (!bRet)
  956. return FALSE;
  957. bRet = FileCopy(strFilePath.GetBuffer(0), IINT_DIR);
  958. if (!bRet)
  959. return FALSE;
  960. }
  961. else
  962. {
  963. //64位系统
  964. strFilePath += "\\" + headDir + "\\64\\msvcr100.dll";
  965. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  966. if (!bRet)
  967. return FALSE;
  968. strFilePath = strExePath;
  969. strFilePath += "\\" + headDir + "\\64\\msvcr100d.dll";
  970. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  971. if (!bRet)
  972. return FALSE;
  973. strFilePath = strExePath;
  974. strFilePath += "\\" + headDir + "\\64\\msvcp100d.dll";
  975. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  976. if (!bRet)
  977. return FALSE;
  978. strFilePath = strExePath;
  979. strFilePath += "\\" + headDir + "\\64\\libeay32.dll";
  980. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  981. if (!bRet)
  982. return FALSE;
  983. strFilePath = strExePath;
  984. strFilePath += "\\" + headDir + "\\64\\VerifyCertificate.dll";
  985. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  986. if (!bRet)
  987. return FALSE;
  988. strFilePath = strExePath;
  989. strFilePath += "\\" + headDir + "\\64\\USBKeyAPI.dll";
  990. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  991. if (!bRet)
  992. return FALSE;
  993. strFilePath = strExePath;
  994. strFilePath += "\\" + headDir + "\\64\\WinSystemLogon.dll";
  995. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  996. if (!bRet)
  997. return FALSE;
  998. strFilePath = strExePath;
  999. strFilePath += "\\" + headDir + "\\64\\SampleHardwareEventCredentialProvider.dll";
  1000. bRet = FileCopy(strFilePath.GetBuffer(0), DLL_PATH);
  1001. if (!bRet)
  1002. return FALSE;
  1003. strFilePath = strExePath;
  1004. strFilePath += "\\" + headDir + "\\64\\lsrunas.exe";
  1005. bRet = FileCopy(strFilePath.GetBuffer(0), EXE_PATH);
  1006. if (!bRet)
  1007. return FALSE;
  1008. strFilePath = strExePath;
  1009. strFilePath += "\\" + headDir + "\\64\\devcon.exe";
  1010. bRet = FileCopy(strFilePath.GetBuffer(0), IINT_DIR);
  1011. if (!bRet)
  1012. return FALSE;
  1013. bRet = FileCopy(strFilePath.GetBuffer(0), strExePath.GetBuffer(0));
  1014. if (!bRet)
  1015. return FALSE;
  1016. }
  1017. //拷贝系统服务相关库文件和配置文件
  1018. strFilePath = strExePath;
  1019. strFilePath += "\\" + headDir + "\\InstallServer.exe";
  1020. bRet = FileCopy(strFilePath.GetBuffer(0), IINT_DIR);
  1021. if (!bRet)
  1022. return FALSE;
  1023. strFilePath = strExePath;
  1024. strFilePath += "\\" + headDir + "\\WinServer.exe";
  1025. bRet = FileCopy(strFilePath.GetBuffer(0), IINT_DIR);
  1026. if (!bRet)
  1027. return FALSE;
  1028. strFilePath = strExePath;
  1029. strFilePath += "\\" + headDir + "\\CmbPadDll.dll";
  1030. bRet = FileCopy(strFilePath.GetBuffer(0), IINT_DIR);
  1031. if (!bRet)
  1032. return FALSE;
  1033. strFilePath = strExePath;
  1034. strFilePath += "\\" + headDir + "\\Register.reg";
  1035. bRet = FileCopy(strFilePath.GetBuffer(0), IINT_DIR);
  1036. if (!bRet)
  1037. return FALSE;
  1038. strFilePath = strExePath;
  1039. strFilePath += "\\" + headDir + "\\Unregister.reg";
  1040. bRet = FileCopy(strFilePath.GetBuffer(0), IINT_DIR);
  1041. if (!bRet)
  1042. return FALSE;
  1043. strFilePath = strExePath;
  1044. strFilePath += "\\" + headDir + "\\AutoStartSpshell.exe";
  1045. bRet = FileCopy(strFilePath.GetBuffer(0), IINT_DIR);
  1046. if (!bRet)
  1047. return FALSE;
  1048. strFilePath = strExePath;
  1049. strFilePath += "\\" + headDir + "\\version.txt";
  1050. bRet = FileCopy(strFilePath.GetBuffer(0), IINT_DIR);
  1051. if (!bRet)
  1052. return FALSE;
  1053. strFilePath = strExePath;
  1054. strFilePath += "\\" + headDir + "\\EnablePolicy.bat";
  1055. bRet = FileCopy(strFilePath.GetBuffer(0), IINT_DIR);
  1056. if (!bRet)
  1057. return FALSE;
  1058. strFilePath = strExePath;
  1059. strFilePath += "\\" + headDir + "\\DisablePolicy.bat";
  1060. bRet = FileCopy(strFilePath.GetBuffer(0), IINT_DIR);
  1061. if (!bRet)
  1062. return FALSE;
  1063. strFilePath = strExePath;
  1064. strFilePath += "\\" + headDir + "\\UserPolicy";
  1065. bRet = DirCopy(strFilePath.GetBuffer(0), IINT_DIR);
  1066. if (!bRet)
  1067. return FALSE;
  1068. if (m_bIsWow64)
  1069. {
  1070. if (FALSE == Wow64RevertWow64FsRedirection(OldValue))
  1071. {
  1072. m_log->LOGERROR("64位系统时,调用Wow64RevertWow64FsRedirection恢复文件重定向失败");
  1073. return FALSE;
  1074. }
  1075. }
  1076. return TRUE;
  1077. }
  1078. BOOL RvcInitBase::Initial_RVC(CString &lastErr)
  1079. {
  1080. //设置组策略
  1081. BOOL bRet = EnablePolicy();
  1082. if (!bRet)
  1083. {
  1084. lastErr = CString(_T("组策略设置失败"));
  1085. m_log->LOGERROR("组策略设置失败");
  1086. return FALSE;
  1087. }
  1088. else
  1089. m_log->LOGERROR("设置组策略成功");
  1090. if (g_hDll != NULL)
  1091. {
  1092. //禁用休眠
  1093. pSetSleep SetSleep = (pSetSleep)GetProcAddress(g_hDll, "SetSleep");
  1094. if (NULL != SetSleep)
  1095. {
  1096. SetSleep(0);
  1097. m_log->LOGERROR("禁用休眠成功");
  1098. }
  1099. //禁用屏保
  1100. pSetScrnsaver SetScrnsaver = (pSetScrnsaver)GetProcAddress(g_hDll, "SetScrnsaver");
  1101. if (NULL != SetScrnsaver)
  1102. {
  1103. SetScrnsaver(9999999);
  1104. m_log->LOGERROR("禁用屏保成功");
  1105. }
  1106. //IE缓存清理
  1107. pIEDeleteHistory IEDeleteHistory = (pIEDeleteHistory)GetProcAddress(g_hDll, "IEDeleteHistory");
  1108. if (NULL != IEDeleteHistory)
  1109. {
  1110. IEDeleteHistory(TRUE);
  1111. m_log->LOGERROR("IE缓存自动清理成功");
  1112. }
  1113. //开机启动设置
  1114. bRet = SetSystemStart();
  1115. if (!bRet)
  1116. {
  1117. lastErr = CString(_T("开机以超级用户启动spshell设置失败"));
  1118. m_log->LOGERROR("开机以超级用户启动spshell设置失败");
  1119. return FALSE;
  1120. }
  1121. else
  1122. m_log->LOGERROR("开机以超级用户启动spshell设置成功");
  1123. //系统登陆设置
  1124. bRet = SetSystemLogon();
  1125. if (!bRet)
  1126. {
  1127. lastErr = CString(_T("系统登陆设置失败"));
  1128. m_log->LOGERROR("系统登陆设置失败");
  1129. return FALSE;
  1130. }
  1131. else
  1132. m_log->LOGERROR("系统登陆设置成功");
  1133. }
  1134. else
  1135. {
  1136. lastErr = CString(_T("加载CmbPadDll.dll失败"));
  1137. m_log->LOGERROR("加载CmbPadDll.dll失败");
  1138. return FALSE;
  1139. }
  1140. return TRUE;
  1141. }
  1142. //行内大机
  1143. BOOL RvcInitBase::InitialBig_Lib(CString &lastErr)
  1144. {
  1145. m_log->LOGERROR("开始系统初始化. 机型:大机, 使用场所:LIB(行内)");
  1146. return Initial_RVC(lastErr);
  1147. }
  1148. BOOL RvcInitBase::DisableInitialBig_Lib()
  1149. {
  1150. BOOL bRet = FALSE;
  1151. if (g_hDll != NULL)
  1152. {
  1153. //禁用休眠
  1154. pSetSleep SetSleep = (pSetSleep)GetProcAddress(g_hDll, "SetSleep");
  1155. if (NULL != SetSleep)
  1156. SetSleep(0);
  1157. else
  1158. return FALSE;
  1159. //禁用屏保
  1160. pSetScrnsaver SetScrnsaver = (pSetScrnsaver)GetProcAddress(g_hDll, "SetScrnsaver");
  1161. if (NULL != SetScrnsaver)
  1162. SetScrnsaver(9999999);
  1163. else
  1164. return FALSE;
  1165. //IE缓存清理
  1166. pIEDeleteHistory IEDeleteHistory = (pIEDeleteHistory)GetProcAddress(g_hDll, "IEDeleteHistory");
  1167. if (NULL != IEDeleteHistory)
  1168. IEDeleteHistory(FALSE);
  1169. else
  1170. return FALSE;
  1171. }
  1172. //取消开机启动
  1173. if (!DisableSystemStart())
  1174. return FALSE;
  1175. //取消系统登陆
  1176. if (!DisableSystemLogon())
  1177. return FALSE;
  1178. return TRUE;
  1179. }
  1180. BOOL RvcInitBase::testFun()
  1181. {
  1182. return SetSystemLogon();
  1183. }
  1184. //行内PAD
  1185. BOOL RvcInitBase::InitialPad_Lib(CString &lastErr)
  1186. {
  1187. m_log->LOGERROR("开始系统初始化. 机型:Pad, 使用场所:LIB(行内)");
  1188. return Initial_RVC(lastErr);
  1189. }
  1190. BOOL RvcInitBase::DisableInitialPad_Lib()
  1191. {
  1192. BOOL bRet = FALSE;
  1193. if (g_hDll != NULL)
  1194. {
  1195. //禁用休眠
  1196. pSetSleep SetSleep = (pSetSleep)GetProcAddress(g_hDll, "SetSleep");
  1197. if (NULL != SetSleep)
  1198. SetSleep(0);
  1199. else
  1200. return FALSE;
  1201. //禁用屏保
  1202. pSetScrnsaver SetScrnsaver = (pSetScrnsaver)GetProcAddress(g_hDll, "SetScrnsaver");
  1203. if (NULL != SetScrnsaver)
  1204. SetScrnsaver(9999999);
  1205. else
  1206. return FALSE;
  1207. //IE缓存清理
  1208. pIEDeleteHistory IEDeleteHistory = (pIEDeleteHistory)GetProcAddress(g_hDll, "IEDeleteHistory");
  1209. if (NULL != IEDeleteHistory)
  1210. IEDeleteHistory(FALSE);
  1211. else
  1212. return FALSE;
  1213. }
  1214. //取消开机启动
  1215. if (!DisableSystemStart())
  1216. return FALSE;
  1217. //取消系统登陆
  1218. if (!DisableSystemLogon())
  1219. return FALSE;
  1220. return TRUE;
  1221. }
  1222. //外携PAD
  1223. BOOL RvcInitBase::InitialPad_Flb(CString &lastErr)
  1224. {
  1225. m_log->LOGERROR("开始系统初始化. 机型:Pad, 使用场所:FLB(行外)");
  1226. return Initial_RVC(lastErr);
  1227. }
  1228. BOOL RvcInitBase::DisableInitialPad_Flb()
  1229. {
  1230. BOOL bRet = FALSE;
  1231. if (g_hDll != NULL)
  1232. {
  1233. //取消休眠
  1234. pSetSleep SetSleep = (pSetSleep)GetProcAddress(g_hDll, "SetSleep");
  1235. if (NULL != SetSleep)
  1236. {
  1237. SetSleep(0);
  1238. m_log->LOGERROR("取消自动休眠成功");
  1239. }
  1240. else
  1241. m_log->LOGERROR("取消自动休眠失败");
  1242. //禁用屏保
  1243. pSetScrnsaver SetScrnsaver = (pSetScrnsaver)GetProcAddress(g_hDll, "SetScrnsaver");
  1244. if (NULL != SetScrnsaver)
  1245. {
  1246. SetScrnsaver(9999999);
  1247. m_log->LOGERROR("取消自动屏保成功");
  1248. }
  1249. else
  1250. m_log->LOGERROR("取消自动屏保失败");
  1251. //IE缓存清理
  1252. pIEDeleteHistory IEDeleteHistory = (pIEDeleteHistory)GetProcAddress(g_hDll, "IEDeleteHistory");
  1253. if (NULL != IEDeleteHistory)
  1254. {
  1255. IEDeleteHistory(FALSE);
  1256. m_log->LOGERROR("取消IE缓存清理成功");
  1257. }
  1258. else
  1259. m_log->LOGERROR("取消IE缓存清理失败");
  1260. }
  1261. //取消开机启动
  1262. if (!DisableSystemStart())
  1263. return FALSE;
  1264. //取消系统登陆
  1265. if (!DisableSystemLogon())
  1266. return FALSE;
  1267. return TRUE;
  1268. }
  1269. BOOL RvcInitBase::checkInitByType(TCHAR *lastErr)
  1270. {
  1271. BOOL result = FALSE;
  1272. switch (getSysType())
  1273. {
  1274. case PAD_FLB:
  1275. case PAD_LIB:
  1276. case CMB_LIB:
  1277. result = checkSystemLogon();
  1278. if (!result) _tcscpy(lastErr, _T("系统未进行主框架初始化"));
  1279. return result;
  1280. case CMB_FLB:
  1281. _tcscpy(lastErr, _T("当前版本不支持主框架初始化"));
  1282. return FALSE;
  1283. default:
  1284. _tcscpy(lastErr, _T("未知终端类型"));
  1285. return FALSE;
  1286. }
  1287. }
  1288. void getVersionPath(TCHAR *versionPath)
  1289. {
  1290. TCHAR pathbuf[1024] = _T("");
  1291. int pathlen = ::GetModuleFileName(NULL, pathbuf, 1024);//获得GuiConsole路径
  1292. // 替换掉单杠
  1293. int times = 0;
  1294. while (pathlen > 0 && times != 2)
  1295. {
  1296. if (pathbuf[--pathlen] == '\\')
  1297. times++;
  1298. }
  1299. pathbuf[++pathlen] = '\0';
  1300. if (NULL == versionPath)
  1301. return;
  1302. else
  1303. memcpy(versionPath, pathbuf, (pathlen + 1) * sizeof(TCHAR));
  1304. }
  1305. BOOL getLogPath(char *generatePath, const TCHAR *dirName, const TCHAR *fileName)
  1306. {
  1307. TCHAR pathBuf[1024];
  1308. getVersionPath(pathBuf);
  1309. CString dirPath = CString(pathBuf) + CString(dirName);
  1310. if (!checkDirExist(dirPath))
  1311. return FALSE;
  1312. CString logName = dirPath + CString(fileName);
  1313. CStringToMultiByte(logName, generatePath, logName.GetLength() + 1);
  1314. return TRUE;
  1315. }