如何实现windows服务应用程序自动“允许服务与桌面交互”

mumuliang 2005-12-01 02:23:51
安装一个windows服务应用程序,
并且在安装过程中将该服务的属性“允许服务与桌面交互”设置为true。

有思路的同志请尽量说详细点,
因为我很初级,很可能不知道对您的思路该如何开始。

谢谢。
...全文
440 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
puny 2006-01-24
  • 打赏
  • 举报
回复
http://www.codeproject.com/csharp/cswindowsservicedesktop.asp
mumuliang 2005-12-21
  • 打赏
  • 举报
回复
up
mumuliang 2005-12-02
  • 打赏
  • 举报
回复
re: lookfeng() ( ) 信誉:91
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
public static extern bool ChangeServiceConfig(IntPtr serviceHandle, int serviceType, int startType, int errorControl, string binaryPath, string loadOrderGroup, IntPtr pTagId, char[] dependencies, string userName, string password, string displayName);

这个api里涉及的参数太多,要回去找个api的参考书来看看才知道啊。thx 先

re: zyno2() ( ) 信誉:100

你给出的地址所讲的答案基本上只是理论正确,实际行不通(!)。尤其是最后行
=======
System.ServiceProcess.ServiceType = InteractiveProcess;
=======
System.ServiceProcess.ServiceType是一个类,而非指ServiceProcess的一个属性ServiceType。一个ServiceProcess实例的ServiceType状态是作为属性保存给ProcessController的,所以即使要使用ServiceType属性,也是ProcessController的实例,行如
myController.ServiceType=ServiceType.InteractiveProcess;
但这也是不可行的,因为ServiceType只读。



cjnet 2005-12-01
  • 打赏
  • 举报
回复
学习,顶
zyno2 2005-12-01
  • 打赏
  • 举报
回复
http://blog.blogchina.com/websites/1038731.html
lookfeng 2005-12-01
  • 打赏
  • 举报
回复
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
public static extern bool ChangeServiceConfig(IntPtr serviceHandle, int serviceType, int startType, int errorControl, string binaryPath, string loadOrderGroup, IntPtr pTagId, char[] dependencies, string userName, string password, string displayName);

[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
public static extern IntPtr OpenService(IntPtr databaseHandle, string serviceName, int access);

[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
public static extern IntPtr OpenSCManager(string machineName, string databaseName, int access);





lookfeng 2005-12-01
  • 打赏
  • 举报
回复
恐怕得通过 API来实现:
OpenService
ChangeServiceConfig
mumuliang 2005-12-01
  • 打赏
  • 举报
回复
如果有在其他阶段,比方说服务启动阶段将该“允许服务与桌面交互”设置为true的方法,也可以说说看

我只是希望由程序来完成这个设置过程。

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧