#include <windows.h>
#include <tchar.h>
#include <stdio.h>
void CreateInf(LPCTSTR drivers);//创建aotorun.inf
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
const TCHAR drivers[] = L"G:\\";
CreateInf(drivers);
return 0;
}
void CreateInf(LPCTSTR drivers)
{
HANDLE hFile = NULL;
TCHAR ch[MAX_PATH];
DWORD szWrite = 0;
_tprintf(ch, L"%sautorun.inf", drivers);
//添加AutoRun的执行代码
const TCHAR autoBuffer[] = L"[AutoRun]\
open = D:\\KGMusic\\KuGou.exe\
shell\\open = 打开(&O)\
shell\\open\\D:\\KGMusic\\KuGou.exe\
shell\\open\\Default = 1";
//创建写入文件,设为隐藏和系统文件
CreateFile(ch, GENERIC_WRITE, 0, NULL, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM,
WriteFile(hFile, autoBuffer, sizeof(autoBuffer), &szWrite, NULL), NULL);
CloseHandle(hFile);
}
------解决思路----------------------
void CreateInf(LPCTSTR drivers)
{
HANDLE hFile = NULL;
TCHAR ch[MAX_PATH] = {0};
DWORD szWrite = 0;
wsprintf(ch, _T("%sautorun.inf"), drivers);
//添加AutoRun的执行代码
const TCHAR autoBuffer[] = _T("[AutoRun]\
open = D:\\KGMusic\\KuGou.exe\
shell\\open = 打开(&O)\
shell\\open\\D:\\KGMusic\\KuGou.exe\
shell\\open\\Default = 1");
//创建写入文件,设为隐藏和系统文件
hFile = CreateFile(ch, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,FILE_ATTRIBUTE_HIDDEN
------解决思路----------------------
FILE_ATTRIBUTE_SYSTEM,0);
WriteFile(hFile, autoBuffer, sizeof(autoBuffer), &szWrite, NULL);
CloseHandle(hFile);
}