From d246075c5e5d9ebe6a26a820d2ba989fd4c17c6e Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期一, 15 九月 2025 17:57:03 +0800
Subject: [PATCH] 1. SG精度检添加读取注册表功能 2. SG精度检查开机自启动增强,取消时不存在不删除注册表,启动时不存在或路径不一样才修改

---
 SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
index c1c2459..ae284a7 100644
--- a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
+++ b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
@@ -417,19 +417,34 @@
 	strAppName = strAppName.Left(strAppName.ReverseFind('.'));
 
 	HKEY hKey;
-	LONG lRet = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_WRITE, &hKey);
+	LONG lRet = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_READ | KEY_WRITE, &hKey);
 
 	if (lRet != ERROR_SUCCESS) { 
 		return false;
 	}
 
+	DWORD dwType = 0;
+	TCHAR szValue[MAX_PATH] = { 0 };
+	DWORD dwSize = sizeof(szValue);
+	lRet = RegQueryValueEx(hKey, strAppName, 0, &dwType, (LPBYTE)szValue, &dwSize);
+
 	if (bEnable) {
-		// 璁剧疆鑷惎
-		lRet = RegSetValueEx(hKey, strAppName, 0, REG_SZ, (BYTE*)(LPCTSTR)strAppPath, (strAppPath.GetLength() + 1) * sizeof(TCHAR));
+		if (lRet != ERROR_SUCCESS || _tcsicmp(szValue, strAppPath) != 0) {
+			// 璁剧疆鑷惎
+			lRet = RegSetValueEx(hKey, strAppName, 0, REG_SZ, (BYTE*)(LPCTSTR)strAppPath, (strAppPath.GetLength() + 1) * sizeof(TCHAR));
+		}
+		else {
+			lRet = ERROR_SUCCESS;
+		}
 	}
 	else {
-		// 鍙栨秷鑷惎
-		lRet = RegDeleteValue(hKey, strAppName);
+		if (lRet == ERROR_SUCCESS) {
+			// 鍙栨秷鑷惎
+			lRet = RegDeleteValue(hKey, strAppName);
+		}
+		else {
+			lRet = ERROR_SUCCESS;
+		}
 	}
 
 	RegCloseKey(hKey);

--
Gitblit v1.9.3