service中调用外部程序问题(200分)

  • 主题发起人 主题发起人 bys
  • 开始时间 开始时间
B

bys

Unregistered / Unconfirmed
GUEST, unregistred user!
我用delphi7写了一个nt service,用于监控指定目录中特定文件是否存在,检查到文件存在时调用另外一个aaa.exe文件进行其它处理.我的系统是xp专业版,nt service运行正常,但调用外部exe时,在任务管理器中查看进程aaa.exe已经调用成功,但aaa.exe中的代码并没有执行,连FormCreate事件中的代码都没有执行.而我单独运行aaa.exe时,运行正常.请各位指点!
 
用户权限问题?再就是允许与桌面交互的问题。你允许与桌面交互,然后指定一个<br>用户试试吧。
 
把一下的 ServiceDesktop 单元放到 dpr 任何引用 user32.dll 单元之前,比如,作为第一个非内存管理器 pas 的单元引用到 dpr 中。<br>具体的可以参考这个说明:<br>http://www.torry.net/samples/samples/os/isarticle.zip <br><br>unit ServiceDesktop;<br><br>interface<br><br>function InitServiceDesktop: boolean;<br>procedure DoneServiceDeskTop;<br><br>implementation<br><br>uses Windows, SysUtils;<br><br>const<br>&nbsp; DefaultWindowStation = 'WinSta0';<br>&nbsp; DefaultDesktop &nbsp; &nbsp; &nbsp; = 'Default';<br>var<br>&nbsp; hwinstaSave: HWINSTA;<br>&nbsp; hdeskSave: HDESK;<br>&nbsp; hwinstaUser: HWINSTA;<br>&nbsp; hdeskUser: HDESK;<br>function InitServiceDesktop: boolean;<br>var<br>&nbsp; dwThreadId: DWORD;<br>begin<br>&nbsp; dwThreadId := GetCurrentThreadID;<br>&nbsp; // Ensure connection to service window station and desktop, and<br>&nbsp; // save their handles.<br>&nbsp; hwinstaSave := GetProcessWindowStation;<br>&nbsp; hdeskSave &nbsp; := GetThreadDesktop(dwThreadId);<br><br><br>&nbsp; hwinstaUser := OpenWindowStation(DefaultWindowStation, FALSE, MAXIMUM_ALLOWED);<br>&nbsp; if hwinstaUser = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; OutputDebugString(PChar('OpenWindowStation failed' + &nbsp;SysErrorMessage(GetLastError)));<br>&nbsp; &nbsp; Result := false;<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br><br>&nbsp; if not SetProcessWindowStation(hwinstaUser) &nbsp;then<br>&nbsp; begin<br>&nbsp; &nbsp; OutputDebugString('SetProcessWindowStation failed');<br>&nbsp; &nbsp; Result := false;<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br><br>&nbsp; hdeskUser := OpenDesktop(DefaultDesktop, 0, FALSE, MAXIMUM_ALLOWED);<br>&nbsp; if hdeskUser = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; OutputDebugString('OpenDesktop failed');<br>&nbsp; &nbsp; SetProcessWindowStation(hwinstaSave);<br>&nbsp; &nbsp; CloseWindowStation(hwinstaUser);<br>&nbsp; &nbsp; Result := false;<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br>&nbsp; Result := SetThreadDesktop(hdeskUser);<br>&nbsp; if not Result then<br>&nbsp; &nbsp; OutputDebugString(PChar('SetThreadDesktop' + SysErrorMessage(GetLastError)));<br>end;<br><br>procedure DoneServiceDeskTop;<br>begin<br>&nbsp; // Restore window station and desktop.<br>&nbsp; SetThreadDesktop(hdeskSave);<br>&nbsp; SetProcessWindowStation(hwinstaSave);<br>&nbsp; if hwinstaUser &lt;&gt; 0 then<br>&nbsp; &nbsp; CloseWindowStation(hwinstaUser);<br>&nbsp; if hdeskUser &lt;&gt; 0 then<br>&nbsp; &nbsp; CloseDesktop(hdeskUser);<br>end;<br><br>initialization<br>&nbsp; InitServiceDesktop;<br>finalization<br>&nbsp; DoneServiceDesktop;<br>end.
 
是service的桌面交互问题,在service的属性里面设置!
 
tseug,zdfcqu 是正解, 也可以在服务控件的属性选择 interactive := true;<br>可以揭帖了,呵呵
 
多人接受答案了。
 
后退
顶部