如何製作自動執行光碟


先建立一個文字檔,檔名為 AUTORUN.INF

內容如下:

[AutoRun]
open=AutoRUN.exe
icon=AutoRUN.exe,0

只有兩行,第一行表示將自動執行的程式,第二行表示光碟的圖示所在。

我們現在教 AutoRUN.EXE 的寫法 :

1. 展示圖片開頭 -  利用圖形元件

2. 自動結束程式,並執行檔案總管 - 利用 Timer , ProgressBar 計時,時間到執行 ShellExecute 並 Close();
    

//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#include <dos.h>
#include <process.h>
#include <shellapi.h>

#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{

}
//---------------------------------------------------------------------------


void __fastcall TForm1::TimerTimer(TObject *Sender)
{
  ProgressBar->Position++;

if(ProgressBar->Position>9)
{

Timer->Enabled=false;
ShellExecute(Handle,"explore",".",NULL,NULL,SW_SHOWMAXIMIZED);
Close();

}


}
//---------------------------------------------------------------------------

由於此程式會被備分至光碟根目錄,故會變成在光碟根目錄開啟檔案總管。

(本程式的重點只有 ShellExecute 要改為其他語言應不困難故從略)

 

不會寫程式或看不懂上面程式寫些甚麼的人不必難過,底下教各位"必殺技":

1.open 部分: 直接使用Windows目錄下的 explorer.exe

                        open=explorer.exe  目錄名稱

                           

                            直接使用Windows目錄下的 notepad.exe

                               open=notepad.exe  文件名稱

 

                            其他請類推,並請將相關檔案全燒至光碟內。

2. icon 部分 :  直接指定 .ico 檔案 (網路抓比較快)

 

舉例如下: 

              [AutoRun]
              open=EXPLORER.EXE
.
              icon=EYE.ICO

 

 


回主網頁  回網路教學