Bläddra i källkod

#IQRV #comment 添加对现有新安装的自启动场景

80374374 1 år sedan
förälder
incheckning
258afaf19b

+ 60 - 10
Module/mod_ResourceWatcher/ResourceWatcherFSM.cpp

@@ -1649,6 +1649,7 @@ void ResourceWatcherFSM::DetectAutoStartupCover()
     ErrorCodeEnum rc = Error_InvalidState;
     const int setType = InitialAutoStartupSetType();
     bool toCheckAndDelteAutostartFile(false);
+    DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("current startup type:%d, aim start type:%d", nStartupType, setType);
     switch (setType)
     {
     case 1://将VBS改成EXE,前提是VBS必须已在注册表
@@ -1668,25 +1669,31 @@ void ResourceWatcherFSM::DetectAutoStartupCover()
 		if (nStartupType == 1 || nStartupType == 2) {
 			rc = ChangeAutoStartupWithExe(false, true);
         }
-        else if (nStartupType == 3) {
+        else if (nStartupType == 3 || nStartupType == 4) {
             toCheckAndDelteAutostartFile = true;
         }
         break;
     case 4: //恢复VBS启动(防止EXE启动失败)
-		if (nStartupType == 2 || nStartupType == 0 || nStartupType == 3) {
+		if (nStartupType == 2 || nStartupType == 0) {
 			rc = ChangeAutoStartupWithExe(true);
-            if (rc == Error_Succeed && nStartupType == 3) {
-                toCheckAndDelteAutostartFile = true;
-            }
 		}
         break;
+	case 5: //设置使用EXE自启动(涵盖所有类型)
+		if (nStartupType == 1 || nStartupType == 0 || nStartupType == 3 || nStartupType == 4) {
+			rc = ChangeAutoStartupWithExe();
+			if (rc == Error_Succeed && (nStartupType == 3 || nStartupType == 4)) {
+				toCheckAndDelteAutostartFile = true;
+			}
+		}
+		break;
     default:
         break;
     }
 
     if (toCheckAndDelteAutostartFile) {
 		CSimpleStringA strLnkPath(true);
-		if (IsHasSetAutoStartupByFolder(strLnkPath) && !strLnkPath.IsNullOrEmpty()) {
+        bool scriptTypeOrNot;
+		if (IsHasSetAutoStartupByFolder(strLnkPath, scriptTypeOrNot) && !strLnkPath.IsNullOrEmpty()) {
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("remove auto start lnk file: %s", strLnkPath.GetData());
 			RemoveFileA(strLnkPath);
 		}
@@ -1768,9 +1775,17 @@ int ResourceWatcherFSM::DetectAutoStartupType()
 
     if (vbsType == 0 || vbsType == -1) {
 		CSimpleStringA strLnkPath(true);
-		if (IsHasSetAutoStartupByFolder(strLnkPath)) {
-			LogWarn(Severity_Low, Error_Debug, LOG_WARN_CHECK_AUTO_STARTUP_WITH_STARTMENU, strLnkPath);
-			vbsType = 3;
+        bool scriptType = false;
+		if (IsHasSetAutoStartupByFolder(strLnkPath, scriptType)) {
+            if (!scriptType) {
+				LogWarn(Severity_Low, Error_Debug, LOG_WARN_CHECK_AUTO_STARTUP_WITH_STARTMENU_FROMSETUP, strLnkPath);
+				vbsType = 3;
+            }
+            else {
+				LogWarn(Severity_Low, Error_Debug, LOG_WARN_CHECK_AUTO_STARTUP_WITH_STARTMENU_FROMSCRIPT, strLnkPath);
+				vbsType = 4;
+            }
+
 		}
     }
     return vbsType;
@@ -1854,11 +1869,14 @@ int ResourceWatcherFSM::InitialAutoStartupSetType()
     return ret;
 }
 
-BOOL ResourceWatcherFSM::IsHasSetAutoStartupByFolder(CSimpleStringA& strPath)
+BOOL ResourceWatcherFSM::IsHasSetAutoStartupByFolder(CSimpleStringA& strPath, bool& scriptsType)
 {
     BOOL result(FALSE);
+
     strPath.Clear();
+    scriptsType = false;
     const char* STARTUP_DIR_FULL_PATH = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp";
+    const char* STRATUP_FILENAME_FROM_SCRIPTS = "spexplorerauto.lnk";
 
 #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
     const char* CMB_LINK_FILE_NAME = "招商银行可视柜台(ST测试).lnk";
@@ -1902,6 +1920,38 @@ BOOL ResourceWatcherFSM::IsHasSetAutoStartupByFolder(CSimpleStringA& strPath)
 			toolkit_array_free2(arr);
 		}
     }
+
+    if (!result) {
+		CSimpleStringA fullStartFileNameFromScripts(STARTUP_DIR_FULL_PATH);
+		fullStartFileNameFromScripts += "\\";
+		fullStartFileNameFromScripts += STRATUP_FILENAME_FROM_SCRIPTS;
+		if (ExistsFileA(fullStartFileNameFromScripts)) {
+            strPath = fullStartFileNameFromScripts;
+            scriptsType = true;
+			result = TRUE;
+        }
+        else {
+			// Get and display the user name.
+            const DWORD INFO_BUFFER_SIZE = 2048;
+            char infoBuf[INFO_BUFFER_SIZE];
+			ZeroMemory(infoBuf, INFO_BUFFER_SIZE);
+            DWORD bufCharCount = INFO_BUFFER_SIZE;
+			if (!GetUserName(infoBuf, &bufCharCount)) {
+				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetUserName failed, GLE=%u", GetLastError());
+            }
+            else {
+                DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("User name:%s", infoBuf);
+				fullStartFileNameFromScripts = CSimpleStringA::Format("C:\\Users\\%s\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup", infoBuf);
+				fullStartFileNameFromScripts += "\\";
+				fullStartFileNameFromScripts += STRATUP_FILENAME_FROM_SCRIPTS;
+				if (ExistsFileA(fullStartFileNameFromScripts)) {
+					scriptsType = true;
+                    strPath = fullStartFileNameFromScripts;
+					result = TRUE;
+				}
+            }
+        }
+    }
     return result;
 }
 

+ 3 - 2
Module/mod_ResourceWatcher/ResourceWatcherFSM.h

@@ -334,13 +334,14 @@ public:
 	//0:explorer.exe
 	//1:vbs
 	//2:vtm.exe
-	//3:startmenu lnk
+	//3:startmenu lnk from RVCTermimalApplicationSetup
+	//4:startmenu lnk from install scripts
 	//-1:failed
 	int DetectAutoStartupType();
 	ErrorCodeEnum ChangeAutoStartupWithExe(bool resetVBS = false, bool resetExplorer = false);
 	int InitialAutoStartupSetType();
 
-	BOOL IsHasSetAutoStartupByFolder(CSimpleStringA& strPath);
+	BOOL IsHasSetAutoStartupByFolder(CSimpleStringA& strPath, bool& scriptsType);
 	void DetectVersionHasChangedAndWarn();
 	void DetectDestopFileAndWarn(bool bClear, CSimpleStringA& strFileSaveList);
 	ErrorCodeEnum DetectVTMInstalledBySetup(BOOL& fYes);

+ 2 - 1
Module/mod_ResourceWatcher/ResourceWatcher_UserCode.h

@@ -60,7 +60,8 @@
 #define LOG_WARN_UPDATE_AUTO_STARTUP_WITH_EXE_SUCC 0x50A00045
 #define LOG_WARN_UPDATE_AUTO_STARTUP_WITH_EXE_FAILED 0x50A00046
 #define LOG_WARN_CHECK_AUTO_STARTUP_UNKNOWN 0x50A00047 //注册表未知内容
-#define LOG_WARN_CHECK_AUTO_STARTUP_WITH_STARTMENU 0x50A00048 //开始菜单里设置开机自启动
+#define LOG_WARN_CHECK_AUTO_STARTUP_WITH_STARTMENU_FROMSETUP 0x50A00048 //开始菜单里设置开机自启动(通过安装程序RVCTerminalApplicationSetup)
+#define LOG_WARN_CHECK_AUTO_STARTUP_WITH_STARTMENU_FROMSCRIPT 0x50A00049 //开始菜单里设置开机自启动(通过安装脚本)
 
 #define LOG_WARN_GET_FILE_CONTENT 0x50A00050
 #define LOG_WARN_READ_FILE_INFO 0x50A00051