照着别人的代码写了个“设置个性CMD的东西” unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Registry; type TForm1 = class(TForm) Label1: TLabel; Edit1: TEdit; Memo1: TMemo; Label2: TLabel; Button1: TButton; Button2: TButton; Button3: TButton; procedure Button3Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure SetBat(const Path:string = ''); var reg:TRegistry; begin reg:=TRegistry.Create; reg.RootKey:=HKEY_LOCAL_MACHINE; reg.OpenKey('/SOFTWARE/Microsoft/Command Processor',True); reg.WriteString('AutoRun',Path); reg.Free; if Path<>'' then MessageDlg('设置完毕',mtInformation,[mbok],0) else MessageDlg('已经还原',mtInformation,[mbOK],0); end; procedure DirPath(const Title:String;ITems:TStrings); var path,s:string; F:Textfile; i:Integer; WinPath:array[0..MAX_PATH] of Char; //第二个参数表示winding盘符路径最大长度 begin GetWindowsDirectory(WinPath,MAX_PATH);//得到windows目录 path:=(WinPath+'/hellsb.bat'); //path此时等于:PATH=WINDOWS/HELLSB.BAT AssignFile(f,path); //在windows下创建名为hellsb.bat的文件 Rewrite(f); //会覆盖已存在的文件 writeln(f,'@echo off'); //像hellsb.bat下写入文件 Writeln(f,'cls'); Writeln(f,'title ' + title); if ITems.Count-1 > -1 then begin for i:=0 to ITems.Count-1 do begin S:=Trim(ITems[i]); Writeln(f,'echo ' + s); end; end; CloseFile(f); if FileExists(path) then setbat(path); //如果存在文件的话就进行传参 end; procedure TForm1.Button3Click(Sender: TObject); begin WinExec('Cmd.exe',1) //打开CMD,第二个参数为非0的正整数 end; procedure TForm1.Button1Click(Sender: TObject); begin DirPath(Edit1.Text,Memo1.Lines); //调用DirPath并进行传参 end; procedure TForm1.FormCreate(Sender: TObject); begin SetWindowLong(Memo1.Handle,GWL_STYLE,GetWindowLong(Memo1.Handle,GWL_STYLE) or ES_CENTER); //设置文字居中显示,同样适用于TEdit组件 end; end.