简体   繁体   English

如何从C#WinForm应用程序自动登录到桌面应用程序?

[英]How to automatically log into a desktop application from a C# WinForm App?

I am pretty good googler but I have hit a road block this time. 我是一个非常不错的Googler,但这次我遇到了障碍。 I created a C# WinForm app that opens the application ICBusinessManager's login window. 我创建了一个C#WinForm应用程序,该应用程序打开了应用程序ICBusinessManager的登录窗口。 What I can't figure out is how to make my winform log in automatically. 我不知道如何使我的winform自动登录。 The IC app's login window has a 'Log on' and a 'Cancel' button. IC应用程序的登录窗口具有“登录”和“取消”按钮。 I am fairly new to development(currently self-teaching) and I apologize in advance if I am not clear. 我对开发还很陌生(目前正在自学),如果不清楚,我会提前道歉。 Please ask if you need me to be more specific. 请询问您是否需要我更具体。

 private void roboDialerBtn_Click(object sender, EventArgs e)
{

            Process roboDialer = new Process();
            roboDialer.StartInfo.FileName = "ICBusinessManager.exe";
            roboDialer.StartInfo.Arguments = "ProcessStart.cs";  
            roboDialer.Start();

        }

You may be able to log in using SendKeys. 您也许可以使用SendKeys登录。 Try something like this using whatever combination of \\t and {enter} you need to tab from each input option giving the control focus (and thus allowing for it to type). 使用\\t{enter}任意组合尝试类似的操作,您需要从每个输入选项中制表,以提供控件焦点(并允许其键入)。 This opens notepad, waits a little for notepad to open, and then types "username", a tab character, "password", a tab character and then enter. 这将打开记事本,稍等一会儿打开记事本,然后键入“用户名”,制表符,“密码”,制表符,然后输入。

var info = new ProcessStartInfo() { FileName = "Notepad.exe" };
new Process() { StartInfo = info }.Start();
System.Threading.Thread.Sleep(500);
System.Windows.Forms.SendKeys.SendWait("username\tpassword\t{enter}");

You may be able to use Process.WaitForInputIdle(int) instead of Thread.Sleep(int) depending on the application you're starting. 您可能可以使用Process.WaitForInputIdle(int)而不是Thread.Sleep(int)具体取决于要启动的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM