2016年8月

首页2016年8月
25
Aug
0

左键菜单以管理员权限运行

`
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT*shellrunas]
[HKEY_CLASSES_ROOT*shellrunas]
@="获取超级管理员权限"
"Icon"="C:\Windows\System32\imageres.dll,-78"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT*shellrunascommand]
@="cmd.exe /c takeown /f "%1" && icacls "%1" /grant administrators:F"
"IsolatedCommand"="cmd.exe /c takeown /f "%1" && icacls "%1" /grant administrators:F"
[-HKEY_CLASSES_ROOTDirectoryshellrunas]

;www.xitonghe.com
[HKEY_CLASSES_ROOTDirectoryshellrunas]
@="获取超级管理员权限"
"Icon"="C:\Windows\System32\imageres.dll,-78"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOTDirectoryshellrunascommand]
@="cmd.exe /c takeown /f "%1" /r /d y && icacls "%1" /grant administrators:F /t"
"IsolatedCommand"="cmd.exe /c takeown /f "%1" /r /d y && icacls "%1" /grant administrators:F /t"
[-HKEY_CLASSES_ROOTdllfileshell]
[HKEY_CLASSES_ROOTdllfileshellrunas]
@="获取超级管理员权限"
"HasLUAShield"=""
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOTdllfileshellrunascommand]
@="cmd.exe /c takeown /f "%1" && icacls "%1" /grant administrators:F"
"IsolatedCommand"="cmd.exe /c takeown /f "%1" && icacls "%1" /grant administrators:F"
[-HKEY_CLASSES_ROOTDriveshellrunas]
[HKEY_CLASSES_ROOTDriveshellrunas]
@="获取超级管理员权限"
"Icon"="C:\Windows\System32\imageres.dll,-78"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOTDriveshellrunascommand]
@="cmd.exe /c takeown /f "%1" /r /d y && icacls "%1" /grant administrators:F /t"
"IsolatedCommand"="cmd.exe /c takeown /f "%1" /r /d y && icacls "%1" /grant administrators:F /t"
`

24
Aug
0

键盘练习工具

多年前做的键盘练习工具,方便大家练手用的

有喜欢的来吧,看看自己的分数,

比起金山打字通,这个更轻便,也更加向键盘工作者,你懂的

004.png
001.png
002.png
003.png

下载地址:
NumTraining.rar

23
Aug
0

讯飞语音离线合成包集成

`unit XunFei;

interface

uses
Vcl.Graphics,Data.SqlExpr,Data.DBXCommon,Vcl.Forms,windows,Vcl.Dialogs,System.SysUtils,
System.Classes;

type
TWaveHDR = record

riff:array[0..3] of AnsiChar;                // = "RIFF"
size_8:Integer;                              // = FileSize - 8
wave:array[0..3] of AnsiChar;                // = "WAVE"
fmt:array[0..3] of AnsiChar;                 // = "fmt "
fmt_size:Integer;                            // = 下一个结构体的大小 : 16

format_tag:Word;                         // = PCM : 1
channels:Word;                           // = 通道数 : 1
samples_per_sec:Integer;                     // = 采样率 : 8000 | 6000 | 11025 | 16000
avg_bytes_per_sec:Integer;                   // = 每秒字节数 : samples_per_sec * bits_per_sample / 8
block_align:Word;                        // = 每采样点字节数 : wBitsPerSample / 8
bits_per_sample:Word;                    // = 量化比特数: 8 | 16

data:array[0..3] of AnsiChar;                // = "data";
data_size:Integer;                           // = 纯数据长度 : FileSize - 44

end;

TMSPLogin = function (aUser,aPassword,login_params:PAnsiChar):Integer;stdcall;
TQTTSSessionBegin = function (params:PAnsiChar;errorCode:PInteger):PAnsiChar;stdcall;
TQTTSTextPut = function (sessionID:PAnsiChar;textString:PAnsiChar;textLen:Cardinal;params:PAnsiChar):Integer;stdcall;
TQTTSSessionEnd = function (sessionID:PAnsiChar;hints:PAnsiChar):Integer;stdcall;
TQTTSAudioGet = function (sessionID:PAnsiChar;audioLen:PCardinal;synthStatus:PInteger;errorCode:PInteger):Pointer;stdcall;

function CreateWav(aTxt,aFileName:PAnsiChar):Boolean;

const
DllFileName = 'msc.dll';
login_params = 'appid = 579e9ccd, work_dir = .';
session_begin_params = 'engine_type = local, voice_name = xiaoyan, text_encoding = GB2312, tts_res_path = fo|res\tts\xiaoyan.jet;fo|res\tts\common.jet, sample_rate = 16000, speed = 50, volume = 50, pitch = 50, rdn = 2';

implementation

function CreateWav(aTxt,aFileName:PAnsiChar):Boolean;
var
DllHandle:THandle;
MSPLogin :TMSPLogin;
QTTSSessionBegin:TQTTSSessionBegin;
QTTSTextPut:TQTTSTextPut;
QTTSSessionEnd:TQTTSSessionEnd;
QTTSAudioGet:TQTTSAudioGet;
ret:Integer;
WaveHDR:TWaveHDR;
FileStream: TFileStream;
sessionId:PAnsiChar;
audio_len:Cardinal;
synthStatus:Integer;
buffer:Pointer;
begin
DllHandle := LoadLibrary(DllFileName);
if DllHandle <> 0 then
begin

try
  //登陆
  @MSPLogin := GetProcAddress(DllHandle, PAnsiChar('MSPLogin'));
  if not (@MSPLogin = nil) then
  begin
    ret := MSPLogin(nil,nil,PAnsiChar(login_params));
  end;
  if ret <> 0 then
  begin
    ShowMessage('登陆错误码:' + IntToStr(ret));
  end;
  //
  WaveHDR.riff[0] := 'R';
  WaveHDR.riff[1] := 'I';
  WaveHDR.riff[2] := 'F';
  WaveHDR.riff[3] := 'F';
  WaveHDR.size_8 := 0;
  WaveHDR.wave[0] := 'W';
  WaveHDR.wave[1] := 'A';
  WaveHDR.wave[2] := 'V';
  WaveHDR.wave[3] := 'E';
  WaveHDR.fmt[0] := 'f';
  WaveHDR.fmt[1] := 'm';
  WaveHDR.fmt[2] := 't';
  WaveHDR.fmt[3] := ' ';
  WaveHDR.fmt_size := 16;
  WaveHDR.format_tag := 1;
  WaveHDR.channels := 1;
  WaveHDR.samples_per_sec := 16000;
  WaveHDR.avg_bytes_per_sec := 32000;
  WaveHDR.block_align := 2;
  WaveHDR.bits_per_sample := 16;
  WaveHDR.data[0] := 'd';
  WaveHDR.data[1] := 'a';
  WaveHDR.data[2] := 't';
  WaveHDR.data[3] := 'a';
  WaveHDR.data_size := 0;
  //开始合成
  if ret = 0 then
  begin
    @QTTSSessionBegin := GetProcAddress(DllHandle, PAnsiChar('QTTSSessionBegin'));
    sessionID := QTTSSessionBegin(PAnsiChar(session_begin_params), @ret);
    if ret <> 0 then
    begin
      ShowMessage('启动合成,错误码:' + IntToStr(ret));
    end;
  end;
  //合成语音
  if ret = 0 then
  begin
    @QTTSTextPut := GetProcAddress(DllHandle, PAnsiChar('QTTSTextPut'));
    ret := QTTSTextPut(sessionID,PAnsiChar(aTxt),Cardinal(Length(aTxt)),PAnsiChar(session_begin_params));
    if ret <> 0 then
    begin
      ShowMessage('合成语音,错误码:' + IntToStr(ret));
      @QTTSSessionEnd := GetProcAddress(DllHandle, PAnsiChar('QTTSSessionEnd'));
      QTTSSessionEnd(sessionID,PAnsiChar('TextPutError'));
    end;
  end;
  //取得合成的数据
  if FileExists(aFileName) then
  begin
    if not DeleteFile(aFileName) then
    begin
      ShowMessage('文件删除失败:' + aFileName);
      ret := -1;
    end;
  end;
  if ret = 0 then
  begin
    @QTTSAudioGet := GetProcAddress(DllHandle, PAnsiChar('QTTSAudioGet'));
    FileStream := TFileStream.Create(aFileName,fmCreate);
    try
      FileStream.Write(@WaveHDR,SizeOf(WaveHDR));
      FileStream.Position := SizeOf(WaveHDR);
      while True do
      begin
        buffer := QTTSAudioGet(sessionID,@audio_len ,@synthStatus,@ret);
        if ret <> 0 then
        begin
          ShowMessage('读取语音失败码:' + IntToStr(ret));
          Break;
        end;
        if buffer <> nil then
        begin
          FileStream.Write(buffer,audio_len);
          WaveHDR.data_size := WaveHDR.data_size + audio_len;
          FileStream.Position := FileStream.Position;
        end;
        if synthStatus = 2 then
          Break;
      end;
      WaveHDR.size_8 := WaveHDR.data_size + sizeof(WaveHDR) - 8;

      FileStream.Position := 4;
      FileStream.Write(@WaveHDR.size_8,SizeOf(WaveHDR.size_8));

      FileStream.Position := 40;
      FileStream.Write(@WaveHDR.data_size,SizeOf(WaveHDR.data_size));
    finally
      FreeAndNil(FileStream);
    end;
  end;
  //合成结束
  if ret = 0 then
  begin
    @QTTSSessionEnd := GetProcAddress(DllHandle, PAnsiChar('QTTSSessionEnd'));
    ret := QTTSSessionEnd(sessionID,PAnsiChar('Normal'));
    if ret <> 0 then
    begin
      ShowMessage('合成语音结束,错误码:' + IntToStr(ret));
    end;
  end;
finally
  FreeLibrary(DllHandle);
end;

end;
end;

end.
`

18
Aug
0

断点续传下载方法

function TfrmMain.DownLoadUpdateRAR(aUrl:string):Boolean;
var
IdHttp: TIdHttp;
MemStream: TFileStream;
tmpMemStream: TMemoryStream;
UrlStr,
DFileName: string;
FilePosition: int64;
FileSize: integer;
FileName:string;
begin
//初始化进度条
pbMain.Max := 0;
pbMain.Min := 0;
//获取下载地址
UrlStr := trim(aUrl);
IdHttp := tIdHttp.Create(nil);
try

IdHttp.ProtocolVersion := pv1_1 ;
IdHttp.HandleRedirects := true;
//获取重定向后的下载地址和文件大小
ShowLog('获取文件信息...');
IdHttp.Head(UrlStr);
FileSize := IdHttp.Response.ContentLength;
DFileName := idhttp.URL.URI;
//由下载地址转换为保存文件名
while pos('/',DFileName) > 0 do
begin
  delete(DFileName, 1, pos('/',DFileName));
end;
if DFileName = '' then
  Exit;
if not TDirectory.Exists(ExtractFilePath(Application.ExeName) + 'Update\') then
  TDirectory.CreateDirectory(ExtractFilePath(Application.ExeName) + 'Update\');
FLocalFileName := ExtractFilePath(Application.ExeName) + 'Update\' + DFileName;
ShowLog('文件名:【' + DFileName + '】  文件大小:【' + IntToStr(FileSize) + '】字节');
FilePosition := 0;
if FileExists(FLocalFileName) then
begin
  MemStream := TFileStream.Create(FLocalFileName,fmOpenWrite);
  ShowLog('文件【' + DFileName + '】存在,断点续传中...');
end
else
begin
  MemStream := TFileStream.Create(FLocalFileName,fmCreate);
  ShowLog('文件【' + DFileName + '】下载中...');
end;
MemStream.Position := MemStream.Size - 1;
//初始化进度条
pbMain.Max    := FileSize;
pbMain.Position := FilePosition;
tmpMemStream := TMemoryStream.Create;
try
  while FilePosition < FileSize do
  begin
    tmpMemStream.Clear;
    tmpMemStream.Position := 0;
    //方法2:已验证
    IdHttp.Request.Range := IntToStr(FilePosition) + '-' ;
    if FilePosition + 10240 < FileSize then
      IdHttp.Request.Range := IdHttp.Request.Range + IntToStr(FilePosition + 10239);

    IdHttp.get(idhttp.URL.URI, tmpMemStream);
    tmpMemStream.Position := 0;
    //此方法可防止占满内存的问题
    MemStream.CopyFrom(tmpMemStream,tmpMemStream.Size);

    FilePosition := MemStream.Size;
    //刷新进度条
    pbMain.Position := FilePosition;
    ShowLog('文件下载进度[' + FormatFloat('0.0',FilePosition * 100.0 / FileSize) + '%]...',True);
    Application.ProcessMessages;
  end;
finally
  FreeAndNil(tmpMemStream);
end;

finally

IdHttp.Free;
MemStream.Free;

end;
ShowLog('文件【' + DFileName + '】下载完成');
Result := True;
end;

18
Aug
0

进程操作常用函数

unit CheckProjectIsRunUnt;

interface
uses
Classes,Winapi.TlHelp32,system.SysUtils,Winapi.Messages,Winapi.Windows,Winapi.PsAPI,
StrUtils,System.Math,system.Types,system.Variants,System.IOUtils,mainFrm,Vcl.Forms;

function CloseDirectoryAllProject(aDirectory:string;selfPid:Cardinal):Boolean;
function CheckProjectIsRunK(aProjectPath:string;var aPID:Cardinal):Boolean;
function GetVersion(aFileName: string): string;
function KillTask(ExeFileName: string): Integer;
procedure UpdateApp(AppUpdateFileName,AppFileName:string);

implementation

procedure UpdateApp(AppUpdateFileName,AppFileName:string);
begin
if FileExists(AppUpdateFileName) then // 'a1.exe'
begin

if FileExists(AppFileName) then        // 'a.exe'
begin
  KillTask(AppFileName);        //   'a.exe'
  Sleep(500);
  DeleteFile(PWideChar(ExtractFilePath(Application.ExeName) + AppFileName)); // 'a.exe'
end;
ReNameFile(ExtractFilePath(Application.ExeName) + AppUpdateFileName , ExtractFilePath(Application.ExeName) + AppFileName );  //'a1.exe'   'a.exe'

end;
end;

function KillTask(ExeFileName: string): Integer;
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOL;
SnapshotHandle: THandle;
ProcessEntry32: TProcessEntry32;
begin
Result := 0;
SnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ProcessEntry32.dwSize := SizeOf(ProcessEntry32);
ContinueLoop := Process32First(SnapshotHandle, ProcessEntry32);

while Integer(ContinueLoop) <> 0 do
begin

if ((UpperCase(ExtractFileName(ProcessEntry32.szExeFile)) =
  UpperCase(ExeFileName)) or (UpperCase(ProcessEntry32.szExeFile) =
  UpperCase(ExeFileName))) then
  Result := Integer(TerminateProcess(
                    OpenProcess(PROCESS_TERMINATE,
                                BOOL(0),
                                ProcessEntry32.th32ProcessID),
                                0));
 ContinueLoop := Process32Next(SnapshotHandle, ProcessEntry32);

end;
CloseHandle(SnapshotHandle);
end;

function GetVersion(aFileName: string): string;
var
buf, p: pChar;
sVer: ^VS_FIXEDFILEINFO;
i: LongWord;
aMajor: integer;
aMinor: integer;
aRelease: integer;
aBuild: integer;
begin
i := GetFileVersionInfoSize(pchar(aFileName), i);
new(sVer);
p := pchar(sVer);
GetMem(buf, i);
ZeroMemory(buf, i);
result := '';
if GetFileVersionInfo(pchar(aFileName), 0, 4096, pointer(buf)) then
if VerQueryValue(buf, '', pointer(sVer), i) then
begin

aMajor := sVer^.dwFileVersionMS shr 16;
aMinor := sVer^.dwFileVersionMS and $0000ffff;
aRelease := sVer^.dwFileVersionLS shr 16;
aBuild := sVer^.dwFileVersionLS and $0000ffff;
Result := IntToStr(aMajor) + '.' + IntToStr(aMinor) + '.' + IntToStr(aRelease) + '.' + IntToStr(aBuild);

end;
Dispose(p);
FreeMem(buf);
end;

function GetProcessPath(ProcessID: DWORD): string;
var

 Hand: THandle;
 ModName: Array[0..Max_Path-1] of Char;
 hMod: HModule;
 n: DWORD;

begin
Result:='';
Hand:=OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,

                     False,
                     ProcessID);

if Hand>0 then
try

 ENumProcessModules(Hand,@hMod,Sizeof(hMod),n);
 if GetModuleFileNameEx(Hand,hMod,ModName,Sizeof(ModName))>0 then
  // Result:=ExtractFilePath(ModName);//得到路径
   Result:=ModName; //得到路径和文见名

except
end;
end;
function CheckProjectIsRunK(aProjectPath:string;var aPID:Cardinal):Boolean;
var
ContinueLoop: BOOL;
SnapshotHandle: THandle;
ProcessEntry32: TProcessEntry32;
begin
Result := False;
SnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ProcessEntry32.dwSize := SizeOf(ProcessEntry32);
ContinueLoop := Process32First(SnapshotHandle, ProcessEntry32);

while Integer(ContinueLoop) <> 0 do
begin

 if (UpperCase(GetProcessPath(ProcessEntry32.th32ProcessID)) = UpperCase(aProjectPath)) and (aPID<>ProcessEntry32.th32ProcessID) then
 begin
   Result := True;
   aPID:=ProcessEntry32.th32ProcessID;
   Exit;
 end;
 ContinueLoop := Process32Next(SnapshotHandle, ProcessEntry32);

end;
CloseHandle(SnapshotHandle);
end;

function CloseDirectoryAllProject(aDirectory:string;selfPid:Cardinal):Boolean;
var
ContinueLoop: BOOL;
SnapshotHandle: THandle;
ProcessEntry32: TProcessEntry32;
ProcessPath:string;
PID:Cardinal;
begin
Result := False;
aDirectory :=UpperCase(aDirectory);
SnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ProcessEntry32.dwSize := SizeOf(ProcessEntry32);
ContinueLoop := Process32First(SnapshotHandle, ProcessEntry32);

while Integer(ContinueLoop) <> 0 do
begin

 ProcessPath := UpperCase(GetProcessPath(ProcessEntry32.th32ProcessID));

// frmMain.ShowLog(ProcessPath);

 if Pos(aDirectory, ProcessPath) > 0 then
 begin
   PID:=ProcessEntry32.th32ProcessID;
   if selfPid = PID then
   begin
     ContinueLoop := Process32Next(SnapshotHandle, ProcessEntry32);
     Continue;
   end;
   frmMain.ShowLog('关闭进程[' + ExtractFileName(ProcessPath) + ']...');
   while TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0), PID), 0) = False do
   begin
     //直到返回TRUE
     frmMain.ShowLog('进程[' + ProcessPath + ']无法关闭...');
   end;;
 end;
 ContinueLoop := Process32Next(SnapshotHandle, ProcessEntry32);

end;
CloseHandle(SnapshotHandle);
Result := True;
end;

end.