有没有办法使用WCF和C#登录Windows机器?我正在创建一个测试工具,需要它来远程登录 Windows 用户。
到目前为止,我们还无法成功完成此操作,因为一旦用户从计算机注销,自承载 WCF 就会关闭。
Is there any way to log on to a Windows machine using WCF and C#? I am creating a Test Harness and it will needed to remotely logon a Windows user.
So far we have not been able to do it successfully as once the user has been log off from the machine, self-hosted WCF is shut down.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题是您将该服务作为控制台应用程序托管。当用户注销时,应用程序将停止。
将您的服务托管在 Windows 服务中,这将使其能够在没有用户登录的情况下启动和运行。
MSDN 关于在 Windows 服务中托管
作为 OnStart 方法中的提示添加以下行:
和 using 语句:
如果您在服务启动和立即停止时遇到问题。这应该允许您在服务开始调试问题时将调试器附加到服务。
your problem is that you are hosting the service as a console app. When the user logs off, the app stops.
Host your service in a windows service, which will enable it to start and run without a user being logged on.
MSDN on hosting in a windows service
as a tip, in the OnStart method add the following line:
and a using statement:
if you have problems with the service starting and immediately stopping. This should allow you to attach a debugger to the service as it is starting to debug the issue.
使用 Web 端提供的凭据,您可以尝试通过 WMI 登录吗?但是,这确实取决于您打算对远程计算机执行的操作 - 其他选项是远程计算机上的客户端
Using supplied credentials on the web end you could try logging in via WMI? but, it does depend what you intend to do to the remote machines - other option would be a client on the remote machines