在很多時候,我們需要使用
服務啟動指定的應用程
序來做到隱蔽啟動程式的目的。
但是當我們直接使用winexec來執行的時候,你會發現系統提示出錯。以下的**就是如何在
delphi編寫的服務中啟動指定的應用程式
。 function
runprocess
(const processname: string): boolean;
varsistartupinfo:startupinfo;
saprocess,sathread:security_attributes;
piprocinfo:process_information;
hd:cardinal;
processhd:thandle;
hds:thandle;
str:string;
begin
result:=false;
if not existfilename(processname) then
begin
exit;
end;
processhd:=getprocesshandleasname( 'explorer ');
if processhd = 0 then exit;
if openprocesstoken(processhd,token_all_access,hds) then
begin
if duplicatetokenex(hds,token_all_access,nil,securityidentification,tokenprimary,hd) then
begin
zeromemory(@sistartupinfo,sizeof(sistartupinfo));
sistartupinfo.cb:=sizeof(sistartupinfo);
saprocess.nlength:=sizeof(saprocess);
saprocess.lpsecuritydescriptor:=nil;
saprocess.binherithandle:=false;
sathread.nlength:=sizeof(sathread);
sathread.lpsecuritydescriptor:=nil;
sathread.binherithandle:=false;
result:=
createprocessasuser
(hd,nil,pchar(processname),nil,nil,false, create_default_error_mode,nil,nil,sistartupinfo,piprocinfo);
end;
end;
end;
引數:processname是你需要啟動的應用程式的絕對路徑。
一般希望啟動的時候被啟動的應用程式沒有執行。這時你就需要首先輪詢判斷此應用程式是否正在執行,以下**就是判斷你指定的應用程式是否在執行中。
function
i***erun
(const exename: string): boolean;
varok: bool;
processid: integer;
processfullpath: string;
pprocess: pprocessinfo;
processlisthandle: thandle;
processstruct: tprocessentry32;
begin
//檢測使用者端是否正在執行
processlisthandle :=
createtoolhelp32snapshot
processstruct.dwsize := sizeof(processstruct);
ok := process32first(processlisthandle, processstruct);
while integer(ok) <> 0 do
begin
processid:=processstruct.th32processid;
if uppercase(trim(processstruct.szexefile)) = uppercase(trim(exename)) then
begin
result:=true;
exit;
end;
ok := process32next(processlisthandle, processstruct);
end;
end;
其中引數 const exename: string 是你需要判斷的應用程式在任務管理器中的名稱。
掰掰開發」論壇
fxh7622
delphi呼叫webservice服務
我用delphi的thttprio控制項呼叫了c 寫的webservice。下面是我除錯時遇到的一些問題 注意末尾的 wsdl 不能少。要不可能會說找不到。2,設定thttprio控制項的屬性 開始把賦給了wsdllocation屬性。連線時總是報錯。後來賦給url屬性,就不報錯了。3,傳遞引數是w...
在Delphi中呼叫CHM幫助檔案
在delphi中,要呼叫chm檔案可以通過引用hhctrl.ocx檔案的函式htmlhelpa實現。不過在這裡,我們也可以使用api函式shellexecute來開啟chm幫助檔案。在網上找到的資料,通常以 shellexecute self.handle,open help.chm sw show...
Delphi開發Windows服務程式
開發步驟 2 現在乙個服務程式的框架已經搭起來了 開啟service1視窗,有幾個屬性說明一下 allowpause 是否允許暫停 allowstop 是否允許停止 dependencies 設定服務的依存關係,服務的啟動是否依賴於某個服務或者組 displayname 在 服務 視窗顯示的名稱 i...