|
发表于 2020-6-7 13:28:54
|
显示全部楼层
- #include <stdio.h>
- #include <windows.h>
- void register_autostart(const char *path) {
- HKEY hKey;
- RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE | KEY_QUERY_VALUE, &hKey);
- if(RegQueryValueExA(hKey, "C.exe", 0, NULL, NULL, NULL))
- RegSetValueExA(hKey, "C.exe", 0, REG_SZ, path, strlen(path) + 1);
- RegCloseKey(hKey);
- }
- void unregister_autostart(const char *path) {
- HKEY hKey;
- RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE | KEY_QUERY_VALUE, &hKey);
- if(!RegQueryValueExA(hKey, "C.exe", 0, NULL, NULL, NULL))
- RegDeleteValueA(hKey, "C.exe");
- RegCloseKey(hKey);
- }
- void normal(void) {
- printf("请输入一个字符串:");
- char buff[64];
- fgets(buff, 64, stdin);
- printf("%s", buff);
- }
- int main(void) {
- char path[MAX_PATH];
- GetModuleFileNameA(NULL, path, MAX_PATH);
- printf("请输入指令:");
- int select = getchar() - '0'; getchar();
- switch(select) {
- case 0: normal(); break;
- case 1: register_autostart(path); break;
- case 2: unregister_autostart(path); break;
- }
- system("pause");
- return 0;
- }
复制代码 |
|