unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,ShellAPI,TLHelp32 ;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var
  list: TStringList;
  i,j,k: Integer;
  vSourcStr:string;
  vDstr:string;

OutBatchFile:Textfile;
  OutBatchFileName:string;
  processinfo:tProcessInformation;
  StartUpinfo:TStartupInfo;

RegBatchFile:Textfile;
  RegBatchFileName:string;

begin
  OutBatchFileName:=ExtractFilePath(ParamStr(0))+'OutReg.bat';
  AssignFile(OutBatchfile,OutBatchFileName);
  Rewrite(OutBatchFile);
  Writeln(OutBatchfile,'Regedit/e c:\files.reg HKEY_USERS');
  closefile(OutBatchFile);

FillChar(StartUpInfo,Sizeof(StartUpInfo),byte(0));
  StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartUpInfo.wShowWindow := SW_Hide;
  if CreateProcess(nil, PChar(OutBatchFileName), nil, nil,
  False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo,
  ProcessInfo) then
  begin
    SLEEP(2000);
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ProcessInfo.hProcess);
  end;

vSourcStr := 'Compact Check Count';
  vDstr:='"Compact Check Count"=dword:00000001';
  list := TStringList.Create;

list.LoadFromFile('C:\files.reg');
  k:= list.count - 1;
  for i := 0 to k do
  begin
    j:=Pos(vSourcStr,list[i]);
    if j<>0 then
    begin
      list.Delete(i);
      list.Insert(i,vDstr);
      list.SaveToFile('C:\files.reg');
    end;
  end;

RegBatchFileName:=ExtractFilePath(ParamStr(0))+'ImportReg.bat';
  AssignFile(RegBatchfile,RegBatchFileName);
  Rewrite(RegBatchFile);
  Writeln(RegBatchfile,'Regedit/s c:\files.reg HKEY_USERS');
  closefile(RegBatchFile);
  StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartUpInfo.wShowWindow := SW_Hide;
  if CreateProcess(nil, PChar(RegBatchFileName), nil, nil,
  False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo,
  ProcessInfo) then
  begin
    SLEEP(2000);
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ProcessInfo.hProcess);
  end;

DELETEFILE('C:\files.reg');
  DeleteFile(OutBatchFileName);
  DeleteFile(RegBatchFileName);

Application.ProcessMessages;
  SendMessage(handle,WM_CLOSE,0,0);

Application.Terminate;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Click;
end;

end.

Delphi Register的更多相关文章

  1. Delphi中register, pascal, cdecl, stdcall, safecall(转)

    源:http://blog.sina.com.cn/s/blog_552c78120100hsr9.html 注: 使用错误,或者在该加的地方没有加,可能会出现"privileged ins ...

  2. Delphi之静态方法,虚方法virtual,动态dynamic,抽象abstract,消息

    Delphi之静态方法,虚方法virtual,动态dynamic,抽象abstract,消息 http://www.cnblogs.com/zhwx/archive/2012/08/28/266055 ...

  3. Delphi 关键字详解[整理于 "橙子" 的帖子]

    absolute //它使得你能够创建一个新变量, 并且该变量的起始地址与另一个变量相同. var   Str: ];   StrLen: Byte absolute Str; //这个声明指定了变量 ...

  4. 转:Delphi 6 实用函数

    来自: daocaoren0824, 时间: -- ::, ID: 再给你一份 程序员实用函数 {▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎} {▎ ▎} {▎ 大 ...

  5. Delphi常用关键字用法详解

    本文详细介绍了Delphi中常用的各个关键字名称及用法,供大家在编程过程中借鉴参考之用.详情如下: absolute: ? 1 2 3 4 5 6 7 8 9 10 //它使得你能够创建一个新变量, ...

  6. 【转】Delphi 关键字详解

    absolute //它使得你能够创建一个新变量, 并且该变量的起始地址与另一个变量相同. var Str: string[32]; StrLen: Byte absolute Str; //这个声明 ...

  7. Delphi中window消息截获的实现方式(2)

    Delphi是Borland公司提供的一种全新的WINDOWS编程开发工具.由于它采用了具有弹性的和可重用的面向对象Pascal(object-orientedpascal)语言,并有强大的数据库引擎 ...

  8. delphi控件属性大全-详解-简介

    http://blog.csdn.net/u011096030/article/details/18716713 button 组件: CAPTION 属性 :用于在按钮上显示文本内容 Cancel ...

  9. Delphi Excel 操作大全

    Delphi Excel 操作大全 (一) 使用动态创建的方法首先创建 Excel 对象,使用ComObj:var ExcelApp: Variant;ExcelApp := CreateOleObj ...

随机推荐

  1. Linux route命令详解和使用示例(查看和操作IP路由表)

    Linux系统的route命令用于显示和操作IP路由表(show / manipulate the IP routing table).要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或 ...

  2. Red and Black

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. [leetcode]重建二叉树(先序和终须) 中序遍和后续

    分割后长度相等,就是参数麻烦,p,先序的起始点, ib,ie 终须的结束和开始. /** * Definition for binary tree * public class TreeNode { ...

  4. ORM介紹及ORM優點、缺點

      主要內容: 1.ORM的概念 2.為什麽要使用ORM 3.ORM的優缺點 4..Net中有那些ORM產品 5.總結 一.ORM的概念 ORM,即Object-Relational Mapping( ...

  5. JNI 从C文件向Java文件传递多个参数

    JNI C主函数 #include <jni.h> #include <string.h> #include <android/log.h> #include &q ...

  6. parseSdkContent failed Could not initialize class android.graphics.Typeface

    Deleting ".android" is temporarily fixing the problem with me as after sometime it begins ...

  7. seq命令

    seq 5 seq 5 >1.txt 其中的>是覆盖 seq 1 5 用来产生从数1到数5之间的所有整数 或, seq 5

  8. java集合类之TreeMap

    转自:http://blog.csdn.net/chenssy/article/details/26668941 TreeMap的实现是红黑树算法的实现,所以要了解TreeMap就必须对红黑树有一定的 ...

  9. 20169210《Linux内核原理与分析》第十周作业

    第一部分:实验 进程的调度时机与进程的切换 操作系统原理中介绍了大量进程调度算法,这些算法从实现的角度看仅仅是从运行队列中选择一个新进程,选择的过程中运用了不同的策略而已. 对于理解操作系统的工作机制 ...

  10. Android开发:如何安全的中止一个自定义线程Thread

    http://blog.csdn.net/yanzi1225627/article/details/8582078 经研究,我推荐这种写法: /*自定义线程*/ class MyThread impl ...