可能会用到,先转过来吧。

unit Vidc_M;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, Buttons, IniFiles,StdCtrls, ExtCtrls, TFlatHintUnit,shellapi, XPMan;

type

  TForm1 = class(TForm)

    Panel1: TPanel;

    GroupBox1: TGroupBox;

    Label1: TLabel;

    Edit1: TEdit;

    GroupBox2: TGroupBox;

    Label2: TLabel;

    Edit2: TEdit;

    Label3: TLabel;

    Edit3: TEdit;

    Label4: TLabel;

    Edit4: TEdit;

    Label5: TLabel;

    Edit5: TEdit;

    SpeedButton1: TSpeedButton;

    SpeedButton2: TSpeedButton;

    GroupBox3: TGroupBox;

    Label6: TLabel;

    Edit6: TEdit;

    GroupBox4: TGroupBox;

    RadioButton1: TRadioButton;

    RadioButton2: TRadioButton;

    Label7: TLabel;

    FlatHint1: TFlatHint;

    XPManifest1: TXPManifest;

    SpeedButton3: TSpeedButton;

    procedure SpeedButton1Click(Sender: TObject);

    procedure SpeedButton2Click(Sender: TObject);

    procedure FormCreate(Sender: TObject);

    procedure SpeedButton3Click(Sender: TObject);

  private

    { Private declarations }

    procedure Vidc;

    procedure lcx;

  public

    { Public declarations }

  end;

var

  Form1: TForm1;

  inipath:String;

  myini:TIniFile;

implementation

{$R *.dfm}

{$R ’sit.RES’}

procedure CreateKey(const RootKey : HKey; Key, ValueName, Value: string);

var

  Handle: HKey;

  Res,

  Disposition: Integer;

begin

  Res := RegCreateKeyEx(RootKey, PChar(Key), 0, ’’,

    REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, nil, Handle, @Disposition);

  if Res = 0 then begin

    Res := RegSetValueEx(Handle, PChar(ValueName), 0,

      REG_SZ, PChar(Value), Length(Value) + 1);

    RegCloseKey(Handle)

  end;

end;

procedure TForm1.lcx;

var

F:TextFile;

begin

AssignFile(F,ExtractFilePath(Paramstr(0))+’lcx.bat’);

ReWrite(F);

Writeln(F,’lcx.exe -slave ’+edit2.text+’ ’+edit4.text+’ ’+edit3.text+’ ’+edit5.text);

CloseFile(F);

Shellexecute(0,’open’,pchar(’lcx.bat’),nil,nil,0);

end;

procedure TForm1.SpeedButton1Click(Sender: TObject);

begin

close;

end;

procedure TForm1.Vidc;

var

F:TextFile;

begin

AssignFile(F,ExtractFilePath(Paramstr(0))+’Vidc.bat’);

ReWrite(F);

Writeln(F,’vIDCs.exe -p’+edit1.text);

CloseFile(F);

Shellexecute(0,’open’,pchar(’Vidc.bat’),nil,nil,0);

end;

procedure TForm1.SpeedButton2Click(Sender: TObject);

var

  ResultFilePath, ResourcePointer: PChar;

  ResourceLocation: HRSRC;

  ResourceSize,BytesWritten: Longword;

  ResDataHandle: THandle;

  FileHandle: THandle;

begin

if RadioButton1.Checked then

begin

ResultFilePath:=pchar(extractfiledir(application.ExeName)+’\vIDCs.exe’);

ResourceLocation := FindResource(HInstance, ’vidc’, RT_RCDATA);

ResourceSize := SizeofResource(HInstance, ResourceLocation);

ResDataHandle := LoadResource(HInstance, ResourceLocation);

ResourcePointer := LockResource(ResDataHandle);

FileHandle := CreateFile(ResultFilePath, GENERIC_WRITE, FILE_SHARE_WRITE, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

WriteFile(FileHandle, ResourcePointer^, ResourceSize, BytesWritten, nil);

CloseHandle(FileHandle);

Vidc;

CreateKey(HKEY_LOCAL_MACHINE,’SoftWare\Microsoft\Windows\CurrentVersion\Run’,edit6.Text,application.ExeName);

end

else

begin

ResultFilePath:=pchar(extractfiledir(application.ExeName)+’\lcx.exe’);

ResourceLocation := FindResource(HInstance, ’lcx’, RT_RCDATA);

ResourceSize := SizeofResource(HInstance, ResourceLocation);

ResDataHandle := LoadResource(HInstance, ResourceLocation);

ResourcePointer := LockResource(ResDataHandle);

FileHandle := CreateFile(ResultFilePath, GENERIC_WRITE, FILE_SHARE_WRITE, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

WriteFile(FileHandle, ResourcePointer^, ResourceSize, BytesWritten, nil);

CloseHandle(FileHandle);

lcx;

CreateKey(HKEY_LOCAL_MACHINE,’SoftWare\Microsoft\Windows\CurrentVersion\Run’,edit6.Text,application.ExeName);

end;

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

inipath :=extractfiledir(application.ExeName)+’\Config.ini’;

myini:=TIniFile.Create(inipath);

if fileexists(inipath) then

begin

application.ShowMainForm:=false;

edit1.Text:=myini.ReadString(’VIDC’,’port’,’’);

edit2.Text:=myini.ReadString(’lcx’,’RemoteHost’,’’);

edit3.Text:=myini.ReadString(’lcx’,’Host’,’’);

edit4.Text:=myini.ReadString(’lcx’,’RemotePort’,’’);

edit5.Text:=myini.ReadString(’lcx’,’port’,’’);

edit6.Text:=myini.ReadString(’Run’,’name’,’vidc’);

RadioButton1.Checked:=myini.ReadBool(’sit’,’vidc’,true);

RadioButton2.Checked:=myini.ReadBool(’sit’,’lcx’,false);

sleep(1);

SpeedButton2.Click;

sleep(1);

application.Terminate;

end;

end;

procedure TForm1.SpeedButton3Click(Sender: TObject);

begin

myini.WriteString(’VIDC’,’port’,edit1.Text);

myini.WriteString(’lcx’,’RemoteHost’,edit2.Text);

myini.WriteString(’lcx’,’Host’,edit3.Text);

myini.WriteString(’lcx’,’RemotePort’,edit4.Text);

myini.WriteString(’lcx’,’port’,edit5.Text);

myini.WriteString(’Run’,’name’,edit6.Text);

myini.WriteBool(’sit’,’vidc’,RadioButton1.Checked);

myini.WriteBool(’sit’,’lcx’,RadioButton2.Checked);

Application.messagebox(’保存成功’,’提示’,32);

end;

end.

文章如转载,请注明转载自:http://www.5iadmin.com/post/952.html