啟動控制台各視窗

來源:互聯網
上載者:User
首先複習怎樣調用外部程式:
Delphi 運行外部程式是使用 Windows.WinExec 或 ShellAPI.ShellExecute, 譬如:

WinExec('notepad.exe', SW_NORMAL); {開啟記事本}WinExec('regedit.exe', SW_NORMAL); {開啟登錄編輯程式}

DLL 檔案與 EXE 檔案的主要區別就是 EXE 可以直接運行, 而 DLL 不可以;
但在 Win32 系統下, 我們可以使用系統檔案 rundll32.exe 調用 DLL 中的功能;
譬如下面一句程式可以開啟控制台視窗:

WinExec('rundll32.exe shell32.dll,Control_RunDLL', SW_NORMAL); //可以簡化一下(省略尾碼):WinExec('rundll32 shell32,Control_RunDLL', SW_NORMAL);//SW_NORMAL 是視窗開啟狀態選項的常量, 它的值是 1, 為了代碼簡潔, 可以再簡化: WinExec('rundll32 shell32,Control_RunDLL', 1);

本例:


代碼檔案:
unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;type  TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    Button3: TButton;    Button4: TButton;    Button5: TButton;    Button6: TButton;    Button7: TButton;    Button8: TButton;    Button9: TButton;    Button10: TButton;    Button11: TButton;    Button12: TButton;    Button13: TButton;    Button14: TButton;    Button15: TButton;    Button16: TButton;    Button17: TButton;    Button18: TButton;    Button19: TButton;    Button20: TButton;    Button21: TButton;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure Button3Click(Sender: TObject);    procedure Button4Click(Sender: TObject);    procedure Button5Click(Sender: TObject);    procedure Button6Click(Sender: TObject);    procedure Button7Click(Sender: TObject);    procedure Button8Click(Sender: TObject);    procedure Button9Click(Sender: TObject);    procedure Button10Click(Sender: TObject);    procedure Button11Click(Sender: TObject);    procedure Button12Click(Sender: TObject);    procedure Button13Click(Sender: TObject);    procedure Button14Click(Sender: TObject);    procedure Button15Click(Sender: TObject);    procedure Button16Click(Sender: TObject);    procedure Button17Click(Sender: TObject);    procedure Button18Click(Sender: TObject);    procedure Button19Click(Sender: TObject);    procedure Button20Click(Sender: TObject);    procedure Button21Click(Sender: TObject);  end;var  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL', 1);              {控制台}end;procedure TForm1.Button2Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL access.cpl', 1);   {協助工具功能選項}end;procedure TForm1.Button3Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL appwiz.cpl', 1);   {添加或刪除程式}end;procedure TForm1.Button4Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL desk.cpl', 1);     {顯示 屬性}end;procedure TForm1.Button5Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL firewall.cpl', 1); {Windows 防火牆}end;procedure TForm1.Button6Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL hdwwiz.cpl', 1);   {添加硬體嚮導}end;procedure TForm1.Button7Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL inetcpl.cpl', 1);  {Internet 屬性}end;procedure TForm1.Button8Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL intl.cpl', 1);     {地區和語言選項}end;procedure TForm1.Button9Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL irprops.cpl', 1);  {無線連結}end;procedure TForm1.Button10Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL joy.cpl', 1);      {遊戲控制器}end;procedure TForm1.Button11Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL main.cpl', 1);     {滑鼠 屬性}end;procedure TForm1.Button12Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL mmsys.cpl', 1);    {聲音和音訊裝置 屬性}end;procedure TForm1.Button13Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL ncpa.cpl', 1);     {網路連接}end;procedure TForm1.Button14Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL netsetup.cpl', 1); {網路安裝嚮導}end;procedure TForm1.Button15Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL nusrmgr.cpl', 1);  {使用者帳號}end;procedure TForm1.Button16Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL odbccp32.cpl', 1); {ODBC 資料來源管理器}end;procedure TForm1.Button17Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL powercfg.cpl', 1); {電源選項 屬性}end;procedure TForm1.Button18Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL sysdm.cpl', 1);    {系統屬性}end;procedure TForm1.Button19Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL telephon.cpl', 1); {電話和數據機選項}end;procedure TForm1.Button20Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL wscui.cpl', 1);    {Windows 資訊安全中心}end;procedure TForm1.Button21Click(Sender: TObject);begin  WinExec('rundll32 shell32,Control_RunDLL wuaucpl.cpl', 1);  {自動更新}end;end.

表單檔案:

object Form1: TForm1  Left = 0  Top = 0  Caption = 'Form1'  ClientHeight = 227  ClientWidth = 430  Color = clBtnFace  Font.Charset = DEFAULT_CHARSET  Font.Color = clWindowText  Font.Height = -11  Font.Name = 'Tahoma'  Font.Style = []  OldCreateOrder = False  Position = poDesktopCenter  PixelsPerInch = 96  TextHeight = 13  object Button1: TButton    Left = 8    Top = 8    Width = 132    Height = 25    Caption = #25511#21046#38754#26495#31383#21475    TabOrder = 0    OnClick = Button1Click  end  object Button2: TButton    Left = 8    Top = 39    Width = 132    Height = 25    Caption = #36741#21161#21151#33021#36873#39033    TabOrder = 1    OnClick = Button2Click  end  object Button3: TButton    Left = 8    Top = 70    Width = 132    Height = 25    Caption = #28155#21152#25110#21024#38500#31243#24207    TabOrder = 2    OnClick = Button3Click  end  object Button4: TButton    Left = 8    Top = 101    Width = 132    Height = 25    Caption = #26174#31034' '#23646#24615    TabOrder = 3    OnClick = Button4Click  end  object Button5: TButton    Left = 8    Top = 132    Width = 132    Height = 25    Caption = 'Windows '#38450#28779#22681    TabOrder = 4    OnClick = Button5Click  end  object Button6: TButton    Left = 8    Top = 163    Width = 132    Height = 25    Caption = #28155#21152#30828#20214#21521#23548    TabOrder = 5    OnClick = Button6Click  end  object Button7: TButton    Left = 8    Top = 194    Width = 132    Height = 25    Caption = 'Internet '#23646#24615    TabOrder = 6    OnClick = Button7Click  end  object Button8: TButton    Left = 150    Top = 8    Width = 132    Height = 25    Caption = #21306#22495#21644#35821#35328#36873#39033    TabOrder = 7    OnClick = Button8Click  end  object Button9: TButton    Left = 150    Top = 39    Width = 132    Height = 25    Caption = #26080#32447#38142#25509    TabOrder = 8    OnClick = Button9Click  end  object Button10: TButton    Left = 150    Top = 70    Width = 132    Height = 25    Caption = #28216#25103#25511#21046#22120    TabOrder = 9    OnClick = Button10Click  end  object Button11: TButton    Left = 150    Top = 101    Width = 132    Height = 25    Caption = #40736#26631' '#23646#24615    TabOrder = 10    OnClick = Button11Click  end  object Button12: TButton    Left = 150    Top = 132    Width = 132    Height = 25    Caption = #22768#38899#21644#38899#39057#35774#22791' '#23646#24615    TabOrder = 11    OnClick = Button12Click  end  object Button13: TButton    Left = 150    Top = 163    Width = 132    Height = 25    Caption = #32593#32476#36830#25509    TabOrder = 12    OnClick = Button13Click  end  object Button14: TButton    Left = 150    Top = 194    Width = 132    Height = 25    Caption = #32593#32476#23433#35013#21521#23548    TabOrder = 13    OnClick = Button14Click  end  object Button15: TButton    Left = 291    Top = 8    Width = 132    Height = 25    Caption = #29992#25143#24080#21495    TabOrder = 14    OnClick = Button15Click  end  object Button16: TButton    Left = 291    Top = 39    Width = 132    Height = 25    Caption = 'ODBC '#25968#25454#28304#31649#29702#22120    TabOrder = 15    OnClick = Button16Click  end  object Button17: TButton    Left = 291    Top = 70    Width = 132    Height = 25    Caption = #30005#28304#36873#39033' '#23646#24615    TabOrder = 16    OnClick = Button17Click  end  object Button18: TButton    Left = 291    Top = 101    Width = 132    Height = 25    Caption = #31995#32479#23646#24615    TabOrder = 17    OnClick = Button18Click  end  object Button19: TButton    Left = 291    Top = 132    Width = 132    Height = 25    Caption = #30005#35805#21644#35843#21046#35299#35843#22120#36873#39033    TabOrder = 18    OnClick = Button19Click  end  object Button20: TButton    Left = 291    Top = 163    Width = 132    Height = 25    Caption = 'Windows '#23433#20840#20013#24515    TabOrder = 19    OnClick = Button20Click  end  object Button21: TButton    Left = 291    Top = 194    Width = 132    Height = 25    Caption = #33258#21160#26356#26032    TabOrder = 20    OnClick = Button21Click  endend
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.