如何以编程方式登录Windows 7,8桌面 [英] How could programmatically login into window 7,8 desktop

查看:92
本文介绍了如何以编程方式登录Windows 7,8桌面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用.NET登录到Windows 7,8机器上的帐户

I would like to know if there is any way to login into an account on a Window 7,8 machine using .NET

例如,您有一项服务,在开始执行某项操作(例如,自动化Windows应用程序)之前,您必须登录此帐户.

For example you have a service which before start doing something (etc automate a window application) you have to login into this account.

我希望窗口服务登录用户Dekstop以便能够运行我的任务

I would like the window service to login into user Dekstop as to be able to run my tasks

推荐答案

有一种方法可以通过编程方式登录Windows,而无需使用凭据提供程序.请执行以下步骤:

There is one way you can programmatically login to windows without using credential providers. Follow the following steps:

  1. 打开运行类型"netplwiz",取消选中用户必须输入用户名和密码才能使用此计算机"复选框,最终将窗口设置为自动登录.

  1. Open run type "netplwiz" uncheck the box that says "user must enter a user name and password to use this computer", which ultimately sets windows to auto login.

创建一个c#Windows登录表单,如下所示.或者,您可以根据要求将表单创建为第三方身份验证.我有自己的登录身份验证.

Create a c# windows login form as shown below. Or simply you can create your form as per requirement as a 3rd party authentication. I have my own login authentication.

将表单的窗口状态属性设置为最大化".

Set the window state property of the form as "maximized".

在按钮单击事件上,调用函数"Process.Start(@"C:\Windows\system32\userinit.exe");" userinit.exe是在Windows登录事件之后立即运行的可执行文件.该exe通常位于"C:\ Windows \ system32"位置.

On the button click event, call the function "Process.Start(@"C:\Windows\system32\userinit.exe");" The userinit.exe is the executable file which runs just after the windows logon event. This exe is located usually in "C:\Windows\system32" location.

创建应用程序的exe文件.

Create the exe file of your application.

现在打开注册表编辑器并找到路径:

Now open the registry editor and locate to path:

HKEY_LOCAL_MACHINE>软件> Microsoft> Windows> CurrentVersion> Winlogon.

HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > Windows > CurrentVersion >Winlogon.

  1. 将userinit属性的路径替换为应用程序的exe文件,如上图所示.

  1. Replace the path of userinit attribute with your exe file of your application as shown in the above picture.

现在,一旦自动登录完成winform应用程序启动,就重新启动计算机,如图所示,这是我创建的登录身份验证"表单.输入用户名和密码后,单击登录"按钮,它将执行userinit.exe,然后将我重定向到桌面屏幕.

Now restart your computer once the auto login completes the winform application is launched as in my case "Login Authentication" form created by me as shown in the picture. Once I enter the username and password, then click on Login button it exeutes the userinit.exe and I am redirected to the desktop screen.

因此,这是一种创建第三方登录表单以根据应用程序要求登录Windows计算机的方法.

So this is one way you can create your third party login form to logon to windows machine as per your application's requirement.

这篇关于如何以编程方式登录Windows 7,8桌面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆