易截截图软件、单文件、免安装、纯绿色、仅160KB

delphi 動態安裝服務


unit winntService;
interface
uses
Windows,WinSvc,WinSvcEx;
function InstallService(const strServiceName,strDisplayName,strDescription,strFilename: string):Boolean;
procedure UninstallService(strServiceName:string);
implementation
function StrLCopy(Dest: PChar; const Source: PChar; MaxLen: Cardinal): PChar; assembler;
asm
PUSH EDI
PUSH ESI
PUSH EBX
MOV ESI,EAX
MOV EDI,EDX
MOV EBX,ECX
XOR AL,AL
TEST ECX,ECX
JZ @@1
REPNE SCASB
JNE @@1
INC ECX
@@1: SUB EBX,ECX
MOV EDI,ESI
MOV ESI,EDX
MOV EDX,EDI
MOV ECX,EBX
SHR ECX,2
REP MOVSD
MOV ECX,EBX
AND ECX,3
REP MOVSB
STOSB
MOV EAX,EDX
POP EBX
POP ESI
POP EDI
end;
function StrPCopy(Dest: PChar; const Source: string): PChar;
begin
Result := StrLCopy(Dest, PChar(Source), Length(Source));
end;
function InstallService(const strServiceName,strDisplayName,strDescription,strFilename: string):Boolean;
var
//ss : TServiceStatus;
//psTemp : PChar;
hSCM,hSCS:THandle;
Service: SC_HANDLE;
srvdesc : PServiceDescription;
desc : string;
//SrvType : DWord;
lpServiceArgVectors:pchar;
begin
Result:=False;
hSCM:=OpenSCManager(nil,nil,SC_MANAGER_ALL_ACCESS);
if hSCM=0 then Exit;
Service := OpenService(hSCM, Pchar(strServiceName), SERVICE_ALL_ACCESS);
if Service<=0 then
begin
hSCS:=CreateService(
hSCM,
Pchar(strServiceName),
Pchar(strDisplayName),
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS or SERVICE_INTERACTIVE_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_IGNORE,
Pchar(strFilename),
nil,
nil,
nil,
nil,
nil);
if hSCS=0 then Exit;//MessageBox(hHandle,Pchar(SysErrorMessage(GetLastError)),Pchar(Application.Title),MB_ICONERROR+MB_TOPMOST);
if Assigned(ChangeServiceConfig2) then
begin
desc := Copy(strDescription,1,1024);
GetMem(srvdesc,SizeOf(TServiceDescription));
GetMem(srvdesc^.lpDescription,Length(desc) + 1);
try
StrPCopy(srvdesc^.lpDescription, desc);
ChangeServiceConfig2(hSCS,SERVICE_CONFIG_DESCRIPTION,srvdesc);
finally
FreeMe


相关文档:

在Delphi中,字符串查找 函数

Delphi提供的字符串函数里有一个Pos函数,它的定义是:
function Pos(Substr: string; S: string): Integer;
它的作用是在字符串S中查找字符串Substr,返回值是Substr在S中第一次出现的位置,如果没有找到,返回值为0。
使用pos函数来查找字符第一次出现的位置
var
str1:string;
i,j:integer;
begin
str1:='dsf465 ......

DELPHI 让窗体不在任务栏显示

需要用到的一个函数:
LONG SetWindowLong(
HWND hWnd,
int nIndex,
LONG dwNewLong
);
其中nIndex GWL_EXSTYLE     Retrieves the extended window styles.
dwNewLong   WS_EX_TOOLWINDOW     Creates a tool window; that is, a window intended to ......

Delphi多线程学习(2):Delphi中的多线程类TThread。

2010-02-22 17:08:46
Delphi把多线程相关的API封装在TThread这个类中,可以方便实现多线程运用。首先看下TThread的声明:
TThread = class

private
FHandle: THandle;
FThreadID: THandle;
FCreateSuspended: Boolean;
FTerminated: Boolean;
FSuspended: Boolean;
FFreeOnTerminate: ......

Delphi多线程学习(8):优先级

一个线程的优先级取决于创建线程的进程的优先级(priority class)和线程本身相对的优先级(relative priority)。
    1、进程优先级:
    不同操作系统 优先级数目不同。Windows2000以上的版本列表如下:
Idle:(标志:IDLE_PRIORITY_CLASS,值为$40);
Below Normal:(标志:BEL ......

Delphi多线程学习(10):Label(VCL)同步的问题

上文中,多线程同步主窗体的Label的Caption属性值,发现一个问题:使用Synchronize用于同步的时候,主窗体好像死掉一样;而直接用子程序为Label的引用赋值,则有时会出现“Canvas  does not allow drawing”错误。书上说VCL同步一定要用Synchronize,而不能直接访问。
    测试:
{主窗体} ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号