请各位老师指点,怎样关联“.EXE”文件?
也就是当“EXE”文件启动时,我的程序也同时启动;我不是搞病毒啊
我这样作的为什么不行?
CString str;
str.Format("%s",AfxGetApp()->m_lpCmdLine);
const char*MutexObject="Mysvchost";
hMutex=NULL;
hMutex=::CreateMutex(false,false,MutexObject);
if(hMutex!=NULL)
{
DWORD err=GetLastError();
if(err==ERROR_ALREADY_EXISTS)::PostQuitMessage(0);
}
if(str!="")
{
CString temp;
char ch;
int length=str.GetLength();
for(int i=0;i<length;i++)
{
ch=str.GetAt(i);
if(ch=='\\')
temp=temp+ch;
}
temp=temp.Left(temp.GetLength()-2);
temp=temp.Mid(1);
char str1[]="\"%1\"%*";
::RegSetValue(HKEY_CLASSES_ROOT,"exefile\\shell\\open\\command",
REG_SZ,(LPCTSTR)str1,strlen(str1)+1);
ShellExecute(NULL,"open",temp,NULL,NULL,SW_HIDE);
}
TCHAR str2[256];
GetModuleFileName(NULL,str2,255);
strcat(str2,"\"%1\"%*");
::RegSetValue(HKEY_CLASSES_ROOT,"exefile\\shell\\open\\command",
REG_SZ,(LPCTSTR)str2,strlen(str2)+1);