|
From: Vatay V. N. <no...@va...> - 2002-08-15 18:39:06
|
esh...@ya... eredi =FCzenete:
> I want a code on C++ to run the CD when I but it in
> the CD drive.
For any time I have written 1 little console autorun for experiment, but =
in C
and you can run it with autorun.inf file "open=3Dfile.exe <associated.fli=
e>"
Note: The executable files (exe, bat, com) can run directly without autor=
un files.
if I good remember - in autorun.inf file with "open=3Dxxy.exe" command.
#include <windows.h>
#include <shellapi.h>
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
LPTSTR lpCL=3DGetCommandLine(), lpFile, lpParams, lpFilePart;
TCHAR lpDirectory[MAX_PATH];
DWORD n, m;
// get our file name
if (lpCL[0]=3D=3DTEXT('\"')) {
lpCL++;
for (n=3D0; lpCL[n] && lpCL[n]!=3DTEXT('\"'); n++);
}
else for (n=3D0; lpCL[n] && lpCL[n]!=3DTEXT(' '); n++);
lpCL[n]=3D0;
// get first command line parameter
n++;
while (lpCL[n]=3D=3DTEXT(' ')) n++; // skip any spaces
m=3Dn;
if (lpCL[n]=3D=3DTEXT('\"')) {
n++; m++;
while (lpCL[n] && lpCL[n]!=3DTEXT('\"')) n++;
}
else while (lpCL[n] && lpCL[n]!=3DTEXT(' ')) n++;
lpFile=3D&lpCL[m];
lpCL[n]=3D0;
// the rest are the parameters
lpParams=3D&lpCL[n+1];
if (GetFullPathName(lpCL, MAX_PATH,
lpDirectory,&lpFilePart) <=3D MAX_PATH)
{
SHELLEXECUTEINFO sei;
// truncate the file name, we only need the directory
lpFilePart[0]=3D0;
memset(&sei, 0, sizeof(sei));
sei.cbSize=3Dsizeof(sei);
sei.lpFile=3DlpFile;
sei.lpParameters=3DlpParams;
sei.lpDirectory=3DlpDirectory;
ShellExecuteEx(&sei);
return 0;
}
return 1;
}
(o_ _o)
(o_ (o_ //\ vatay /\\ _o) _o)
_(/)_(\)_V_/ \_V_(/)_(\)_
_________________________________________________________________________=
__
QNX is like a wigwam - no windows, no gates, only apaches inside with boa=
's
|