zoukankan      html  css  js  c++  java
  • Delphi32位程序拷贝system32目录中文件解决方法!

    源码下载:http://download.csdn.net/detail/sunylat/9740352

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
      System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
    
        function DisableWowRedirection: Boolean;
    
        function RevertWowRedirection: Boolean;
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses System.IOUtils;
    
    procedure TForm1.Button1Click(Sender: TObject);
    const
      sourceFile = 'c:windowssystem32cdedit.exe';
    var
      destFile: string;
    begin
      destFile := ExtractFilePath(paramstr(0)) + 'bcdedit.exe';
    
      try
        self.DisableWowRedirection;
    
        try
    
          if TFile.Exists(sourceFile) = true then
          begin
    
            self.Caption := '存在';
    
            TFile.Copy(sourceFile, destFile);
          end
          else
          begin
    
            self.Caption := '不存在';
          end;
    
        except
          on e: exception do
          begin
            showmessage(e.ToString);
          end;
    
        end;
    
      finally
        self.RevertWowRedirection;
      end;
    
    end;
    
    function TForm1.DisableWowRedirection: Boolean;
    type
      TWow64DisableWow64FsRedirection = function(var Wow64FsEnableRedirection
        : LongBool): LongBool; StdCall;
    var
      hHandle: THandle;
      Wow64DisableWow64FsRedirection: TWow64DisableWow64FsRedirection;
      isRedirect:LongBool;
    begin
      isRedirect := true;
      try
        hHandle := GetModuleHandle('kernel32.dll');
        @Wow64DisableWow64FsRedirection := GetProcAddress(hHandle,
          'Wow64DisableWow64FsRedirection');
        if ((hHandle <> 0) and (@Wow64DisableWow64FsRedirection <> nil)) then
          Wow64DisableWow64FsRedirection(isRedirect);
      except
        isRedirect := False;
      end;
    
      result:=isRedirect;
    end;
    
    function TForm1.RevertWowRedirection: Boolean;
    type
      TWow64RevertWow64FsRedirection = function(var Wow64RevertWow64FsRedirection
        : LongBool): LongBool; StdCall;
    var
      hHandle: THandle;
      Wow64RevertWow64FsRedirection: TWow64RevertWow64FsRedirection;
      isRedirect:LongBool;
    begin
      isRedirect := true;
      try
        hHandle := GetModuleHandle('kernel32.dll');
        @Wow64RevertWow64FsRedirection := GetProcAddress(hHandle,
          'Wow64RevertWow64FsRedirection');
        if ((hHandle <> 0) and (@Wow64RevertWow64FsRedirection <> nil)) then
          Wow64RevertWow64FsRedirection(isRedirect);
      except
        isRedirect := False;
      end;
    
      result:=isRedirect;
    end;
    
    end.

     参考文章:http://blog.csdn.net/gj333/article/details/8268379

  • 相关阅读:
    transition
    Java自增陷阱
    不同编码格式中,字节和字符的关系
    表单重复提交
    source folder和package的区别
    @test 测试案例不能添加参数
    http协议content-type
    jdbc的缺点和mybatis的优点
    ==和equals的区别
    spring IOC和AOP
  • 原文地址:https://www.cnblogs.com/sunylat/p/6295943.html
Copyright © 2011-2022 走看看