📄 关于注册mscomm程序的编写.txt
字号:
#include <windows.h>
#include <stdio.h>
#include <string.h>
void CPFile(char file);
void regsted();
void regOCX();
void CPFile(char file[],char tarpath[]) //将三个文件拷贝到系统目录
{
char tempsys[100];
char *r;
char *t;
r=tarpath;
t=tempsys;
strcpy(t,r);
char path[256];
char *p;
char *q;
GetModuleFileName(GetModuleHandle(NULL),path,sizeof(path));
p = path;
while(strchr(p,'\\'))
{
p = strchr(p,'\\');
p++;
}
*p = '\0';
p=strchr(path,'\0');
q=file;
strcpy(p,q);
p=strchr(tempsys,'\0');
*p = '\\';
p++;
q=file;
strcpy(p,q);
CopyFile(path,tempsys,FALSE);
}
void regsted() //将相关信息写入注册表
{
HKEY hKey;
DWORD dwDip;
LPBYTE owner_Get=new BYTE[80];
DWORD type_1=REG_SZ;
DWORD cbData_1=80;
long exist=RegQueryValueEx(HKEY_CLASSES_ROOT, "Licenses\\4250E830-6AC2-11cf-8ADB-00AA00C00905", NULL, &type_1, owner_Get, &cbData_1);
if(exist!=ERROR_SUCCESS)
{
long ret = RegCreateKeyEx(HKEY_CLASSES_ROOT,"Licenses\\4250E830-6AC2-11cf-8ADB-00AA00C00905",0l,NULL,REG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dwDip);
DWORD leng=37;
char key[37]="kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun";
LPBYTE lpb=new BYTE(37);
for(int i=0;i<37;i++)
lpb[i]=key[i];
long ret2 = RegSetValueEx(hKey,NULL,NULL,REG_SZ,lpb,leng);
}
}
void regOCX()//调用新进程注册组件
{
char commandline[256];
char windowsdir[256];
char lastcommandline[257];
PROCESS_INFORMATION pi;
STARTUPINFO si = {sizeof(si)};
char OCXfile[50]="\\MSCOMM32.OCX";
char REGfile[50]="\\regsvr32.exe";
char *p,*q;
GetSystemDirectory(windowsdir, 256);
p=commandline;
q=windowsdir;
strcpy(p,q);
p=strchr(commandline,'\0');
q=OCXfile;
strcpy(p,q);
p=strchr(windowsdir,'\0');
q=REGfile;
strcpy(p,q);
p=commandline;
q=&lastcommandline[1];
strcpy(q,p);
lastcommandline[0]=' ';
// 启动regsvr32.exe作为子进程
BOOL ret = CreateProcess(windowsdir, lastcommandline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
if(ret)
{
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
char sys[100];
char file1[20]="Mscomm32.ocx";
char file2[20]="Mscomm32.dep";
char file3[20]="Mscomm.srg";
GetSystemDirectory(sys,100);
CPFile(file1,sys);
CPFile(file2,sys);
CPFile(file3,sys);
regOCX();
regsted();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -