-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathautorun.cpp
142 lines (129 loc) · 3.94 KB
/
autorun.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "autorun.h"
#include "qsettings.h"
#include "qdebug.h"
#include "qstring.h"
#include "qt_windows.h"
autorun::autorun()
{
/*
* 初始化参数
* 调用搜索函数
*/
this->name1="HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
this->name2="HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
this->number=0;
this->search();
this->search2();
this->search3();
}
void autorun::search()
{
/*
* 调用windows.h中的注册表API获取HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run保存的开机启动项
* 利用KEY_WOW64_64KEY禁止32位程序自动跳转
*/
HKEY key;
QString path="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
RegOpenKeyEx(HKEY_LOCAL_MACHINE,reinterpret_cast<const wchar_t *>(path.utf16()),0,KEY_ALL_ACCESS|KEY_WOW64_64KEY,&key);
DWORD KeyCnt=0;
RegQueryInfoKey(key, NULL, NULL, NULL, NULL, NULL, NULL, &KeyCnt, NULL, NULL, NULL, NULL);
/*
* 遍历键值
* 得到的数据进行类型转换保存到类的实例
*/
for (unsigned int i=0;i<KeyCnt;i++)
{
wchar_t *s1 = new wchar_t[1000];
DWORD size=1000;
DWORD size2=1000;
char *s2 = new char[1000];
RegEnumValue(key,i,s1,&size,NULL,NULL,LPBYTE(s2),&size2);
int temp=0;
QString ss="";
while (s2[temp]!=0)
{
ss+=s2[temp];
temp+=2;
}
this->number +=1;
this->name[number] = QString::fromWCharArray(s1);
this->path[number] = ss;
delete []s1;
delete []s2;
}
}
void autorun::search2()
{
/*
* 调用windows.h中的注册表API获取HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run保存的开机启动项
* 自动跳转到WOW6432目录
*/
HKEY key;
QString path="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
RegOpenKeyEx(HKEY_LOCAL_MACHINE,reinterpret_cast<const wchar_t *>(path.utf16()),0,KEY_ALL_ACCESS,&key);
DWORD KeyCnt=0;
RegQueryInfoKey(key, NULL, NULL, NULL, NULL, NULL, NULL, &KeyCnt, NULL, NULL, NULL, NULL);
/*
* 遍历键值
* 得到的数据进行类型转换保存到类的实例
*/
for (unsigned int i=0;i<KeyCnt;i++)
{
wchar_t *s1 = new wchar_t[1000];
DWORD size=1000;
DWORD size2=1000;
char *s2 = new char[1000];
RegEnumValue(key,i,s1,&size,NULL,NULL,LPBYTE(s2),&size2);
int temp=0;
QString ss="";
while (s2[temp]!=0)
{
ss+=s2[temp];
temp+=2;
}
this->number +=1;
this->name[number] = QString::fromWCharArray(s1);
this->path[number] = ss;
delete []s1;
delete []s2;
}
}
void autorun::search3()
{
/*
* 调用windows.h中的注册表API获取HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run保存的开机启动项
* 利用KEY_WOW64_64KEY禁止32位程序自动跳转
*/
HKEY key;
QString path="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
RegOpenKeyEx(HKEY_CURRENT_USER,reinterpret_cast<const wchar_t *>(path.utf16()),0,KEY_ALL_ACCESS,&key);
DWORD KeyCnt=0;
RegQueryInfoKey(key, NULL, NULL, NULL, NULL, NULL, NULL, &KeyCnt, NULL, NULL, NULL, NULL);
/*
* 遍历键值
* 得到的数据进行类型转换保存到类的实例
*/
for (unsigned int i=0;i<KeyCnt;i++)
{
wchar_t *s1 = new wchar_t[1000];
DWORD size=1000;
DWORD size2=1000;
char *s2 = new char[1000];
RegEnumValue(key,i,s1,&size,NULL,NULL,LPBYTE(s2),&size2);
int temp=0;
QString ss="";
while (s2[temp]!=0)
{
ss+=s2[temp];
temp+=2;
}
this->number +=1;
this->name[number] = QString::fromWCharArray(s1);
this->path[number] = ss;
delete []s1;
delete []s2;
}
}
autorun::~autorun()
{
}