C#编写的Windows服务不能调用FindWindowEx这个API函数吗?

3x3只眼 2010-04-04 06:39:28
我本人平时通过调用FindWindowEx这个API函数获得指定标题栏文字的窗口的句柄,在控制台应用程序和Windows窗体程序中使用都正常.最近在学习用C#编写Windows服务,但是却发现这个函数调用不成功,总是返回0.但是同样情况下在控制台应用程序和Windows窗体程序中却能返回正确的窗口句柄.
据我在网上找的资料.看起来Windows服务因为没有界面的缘故,所以是不能调用某些API函数的.但是,FindWindowEx这个函数好像并没有涉及界面操作啊...所以我想问一下,是不是这个缘故导致在服务中调用FindWindowEx无法成功?亦或者其它原因?
另外,C#编写的Windows服务能够使用整个.NET类库中的类吗?还是说也有限制?
望高手解答,谢谢~_~
...全文
185 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
huming_0706 2010-11-16
  • 打赏
  • 举报
回复
请问你是如何解决的 qq:249680978 谢谢!!
3x3只眼 2010-04-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xray2005 的回复:]
Within a Windows Service, all Desktop related APIs won't work as you expected.
That's because Windows Services run in different logon sessions than the current logon user. They have separate user……
[/Quote]

Thanks very much!
3x3只眼 2010-04-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wuyq11 的回复:]
与桌面有关
http://topic.csdn.net/t/20021021/18/1112992.html#
[/Quote]

谢谢~_~
xray2005 2010-04-04
  • 打赏
  • 举报
回复
Within a Windows Service, all Desktop related APIs won't work as you expected.
That's because Windows Services run in different logon sessions than the current logon user. They have separate user accounts (you can check it out in Service Manager) and "desktops"(invisible). So, those windows shown up in your desktop won't be found by any windows services.
As an alternative, you could use a background application rather than service, like MSN Messenger stuff. Those app really runs within the logon user's session and desktop.


如梦给的答案
wuyq11 2010-04-04
  • 打赏
  • 举报
回复
Justin-Liu 2010-04-04
  • 打赏
  • 举报
回复
没研究过 帮顶

110,539

社区成员

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

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

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