-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUninstall_Font.h
160 lines (139 loc) · 4.39 KB
/
Uninstall_Font.h
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <windows.h>
#include <stdio.h>
int Remove_FontReg(char *name);
int Remove_FontReg_USER(char *name);
void Uninstall_Font(char *PATH);
char *find_FontReg(void);
int Remove_FontReg(char *name)
{
HKEY hKey;
LONG result;
// 打开注册表的"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"子键
result = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts", 0, KEY_WRITE, &hKey);
if (result != ERROR_SUCCESS)
{
printf("RegOpenKeyExA failed, error code = %d\n", result);
return -1;
}
// 删除"Arial"字体
result = RegDeleteKeyExA(HKEY_LOCAL_MACHINE, name, KEY_WOW64_64KEY, 0);
if (result != ERROR_SUCCESS)
{
printf("RegDeleteKeyExA HKEY_LOCAL_MACHINE 64 failed, error code = %d\n", result);
}
result = RegDeleteKeyExA(HKEY_LOCAL_MACHINE, name, KEY_WOW64_32KEY, 0);
if (result != ERROR_SUCCESS)
{
printf("RegDeleteKeyExA HKEY_LOCAL_MACHINE 32 failed, error code = %d\n", result);
}
// 关闭注册表键
RegCloseKey(hKey);
return 0;
}
int Remove_FontReg_USER(char *name)
{
HKEY hKey;
LONG result;
// 打开注册表的"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"子键
result = RegOpenKeyExA(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts", 0, KEY_WRITE, &hKey);
if (result != ERROR_SUCCESS)
{
printf("RegOpenKeyExA failed, error code = %d\n", result);
return -1;
}
// 删除"Arial"字体
result = RegDeleteKeyExA(HKEY_CURRENT_USER, name, KEY_WOW64_64KEY, 0);
if (result != ERROR_SUCCESS)
{
printf("RegDeleteKeyExA HKEY_CURRENT_USER 64 failed, error code = %d\n", result);
}
result = RegDeleteKeyExA(HKEY_CURRENT_USER, name, KEY_WOW64_32KEY, 0);
if (result != ERROR_SUCCESS)
{
printf("RegDeleteKeyExA HKEY_CURRENT_USER 32 failed, error code = %d\n", result);
}
// 关闭注册表键
RegCloseKey(hKey);
return 0;
}
void Uninstall_Font(char *PATH)
{
if(strchr(PATH,':'))
{
char str[65536] = "C:\\Windows\\Fonts\\";
strcat(str,PATH);
stpcpy(PATH,str);
}
if (!RemoveFontResourceA(PATH))
{
int nErr = GetLastError();
printf("从系统字体库删除字体失败! 错误码:%d\n", nErr);
}
// 删除系统字体,操作需要程序具有管理员权限
if (!DeleteFileA(PATH))
{
int nErr = GetLastError();
printf("删除系统字体失败! 错误码:%d\n", nErr);
}
Remove_FontReg("WQY12PX+ (OpenType)");
Remove_FontReg_USER("WQY12PX+ (OpenType)");
}
char *find_FontReg(void)
{
HKEY hKey;
LONG result = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts", 0, KEY_QUERY_VALUE, &hKey);
if (result != ERROR_SUCCESS)
{
printf("RegOpenKeyExA HKEY_LOCAL_MACHINE failed, error code = %d\n", result);
return NULL;
}
char *szValue;
szValue = malloc(65536);
DWORD dwValueSize = 65536;//sizeof(szValue);
result = RegQueryValueExA(hKey, "WQY12PX+ (OpenType)", NULL, NULL, (LPBYTE)szValue, &dwValueSize);
switch(result){
case ERROR_SUCCESS:
printf("WQY12PX+ (OpenType) = %s\n", szValue);
break;
case ERROR_FILE_NOT_FOUND:
printf("RegQueryValueExA HKEY_LOCAL_MACHINE failed, error code = ERROR_FILE_NOT_FOUND\n");
result = RegOpenKeyExA(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts", 0, KEY_QUERY_VALUE, &hKey);
if (result != ERROR_SUCCESS)
{
printf("RegOpenKeyExA HKEY_CURRENT_USER failed, error code = %d\n", result);
free(szValue);
return NULL;
}
result = RegQueryValueExA(hKey, "WQY12PX+ (TrueType)", NULL, NULL, (LPBYTE)szValue, &dwValueSize);
switch(result){
case ERROR_SUCCESS:
printf("WQY12PX+ (TrueType) = %s\n", szValue);
break;
case ERROR_FILE_NOT_FOUND:
printf("RegQueryValueExA HKEY_CURRENT_USER failed, error code = ERROR_FILE_NOT_FOUND\n");
free(szValue);
return NULL;
default:
printf("RegQueryValueExA HKEY_CURRENT_USER failed, error code = %d\n", result);
free(szValue);
return NULL;
}
break;
default:
printf("RegQueryValueExA HKEY_LOCAL_MACHINE failed, error code = %d\n", result);
free(szValue);
return NULL;
}
// if (result != ERROR_SUCCESS)
// {
// printf("RegQueryValueExA HKEY_LOCAL_MACHINE failed, error code = %d\n", result);
// free(szValue);
// return NULL;
// }
// else
// {
// printf("WQY12PX+ (OpenType) = %s\n", szValue);
// }
RegCloseKey(hKey);
return szValue;
}