System.Windows.Forms.SendKeys.SendInput >>任务计划程序拒绝访问 [英] System.Windows.Forms.SendKeys.SendInput >> Access denied at Task Scheduler

查看:121
本文介绍了System.Windows.Forms.SendKeys.SendInput >>任务计划程序拒绝访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个模糊问题,这是以下设置.

我在 Windows 2012R2 服务器上有一个小型 C# 应用程序,可以每天使用任务计划程序登录某个网站.

这是 HTML 登录代码段:

<input class="decorative-input" id="signin_email" name="email" placeholder="Email Address" type="email"/>

<div class="control-group row-space-2"><input class="decorative-input" id="signin_password" name="password" placeholder="密码" type="password"/>

<div class="clearfix row-space-2"><label for="remember_me2" class='checkbox remember-me'><input type="checkbox" name="remember_me" id="remember_me2" value="true" class="remember_me"/>记得我<a href="/forgot_password" class="forgot-password">忘记密码?</a>

<button type="submit" class="btn btn-block btn-primary large btn-large padded-btn-block">登录

该应用程序有一个 Form.WebBrowser,它打开一个带有用户和密码字段的网站.应用程序检查属性并发送回车以登录.这里是代码片段:

HtmlElementCollection tagsColl=webBrowser1.Document.GetElementsByTagName("input");foreach(tagsColl 中的 HtmlElement currentTag){if (currentTag.Name.Equals("email"))currentTag.SetAttribute("value", 用户名);if (currentTag.Name.Equals("password"))currentTag.SetAttribute("value", 密码);currentTag.Focus();SendKeys.Send("{ENTER}");}

当我手动运行该应用程序时,它完全正常.

关于任务计划程序设置.我尝试了很多不同的设置,请看这里:

账号:本地\管理员=>错误:访问被拒绝[x] 仅在用户登录时运行=>错误:访问被拒绝[x] 运行天气用户是否登录=>没有出现带有 WebBrowser 的表单,我可以看到任务管理器中正在运行的任务,但没有任何反应[x] 以最高权限运行=>没有效果配置:Windows Server 2012 R2

当任务调度程序运行作业时,我总是遇到以下异常.

错误:拒绝访问************** 异常文本 **************System.ComponentModel.Win32Exception (0x80004005): 访问被拒绝在 System.Windows.Forms.SendKeys.SendInput(Byte[] oldKeyboardState, Queue previousEvents)在 System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait)在 System.Windows.Forms.SendKeys.Send(String 键)在 airbnblogin.Form1.autofill(字符串用户名,字符串密码)在 airbnblogin.Form1.
d__0.MoveNext()--- 从上一个抛出异常的位置开始的堆栈跟踪结束 ---

我猜是因为 Windows 用户可能没有登录,所以无法输入字符串.

所以这是我的问题,我该如何解决这个问题?我愿意接受每一个建议/进一步的解释!

解决方案

这个有效!

tagsColl = webBrowser1.Document.GetElementsByTagName("button");foreach(tagsColl 中的 HtmlElement curElement){if (curElement.GetAttribute("submit").Equals("")){curElement.InvokeMember("点击");}}

I got a fuzzy problem, here is the following setup.

I got a small C# application to login to a certain website on a daily basis with a task scheduler on a Windows 2012R2 Server.

Here is the HTML login snipet:

<div class="control-group row-space-1">
<input class="decorative-input" id="signin_email" name="email" placeholder="Email Address" type="email" />
</div>
<div class="control-group row-space-2">
<input class="decorative-input" id="signin_password" name="password" placeholder="Password" type="password" />
</div>

<div class="clearfix row-space-2">
<label for="remember_me2" class='checkbox remember-me'>
<input type="checkbox" name="remember_me" id="remember_me2" value="true" class="remember_me"/>
Remember me
</label>
<a href="/forgot_password" class="forgot-password">Forgot password?</a>
</div>

<button type="submit" class="btn btn-block btn-primary large btn-large padded-btn-block">
Log In
</button>

The application has a Form.WebBrowser which opens a website with a user and password field. The application checks for a attribute and send enter to login. Here the code snipet:

HtmlElementCollection tagsColl=webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement currentTag in tagsColl)
{
    if (currentTag.Name.Equals("email"))
        currentTag.SetAttribute("value", username);
    if (currentTag.Name.Equals("password"))
        currentTag.SetAttribute("value", password);
    currentTag.Focus();
    SendKeys.Send("{ENTER}");
}

The application works totally fine when Im running it manually.

About the task scheduler setup. I tried a lot of different setups, have a look here:

Account:
local\Administrator
=> Error: Access denied

[x] Run only when user is logged in
=> Error: Access denied

[x] Run weather user is logged in or not
=> The Form with the WebBrowser doesent appear, I can see the task running in the task manager but nothing happens

[x] Run with highest privilegs
=> No effect

Configure for: Windows Server 2012 R2

When the task scheduler running the job I always got the following exception.

Error: Access denied

************** Exception Text **************
System.ComponentModel.Win32Exception (0x80004005): Access is denied
at System.Windows.Forms.SendKeys.SendInput(Byte[] oldKeyboardState, Queue previousEvents)
at System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait)
at System.Windows.Forms.SendKeys.Send(String keys)
at airbnblogin.Form1.autofill(String username, String password)
at airbnblogin.Form1.<main>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---

I guess it is because the Windows User is not logged in probably so it cant input the strings.

So here is my question, how can I come around this problem? Im open for every suggestion/further explanation!

解决方案

This one works!

tagsColl = webBrowser1.Document.GetElementsByTagName("button");
        foreach (HtmlElement curElement in tagsColl)
        {
            if (curElement.GetAttribute("submit").Equals(""))
            {
                curElement.InvokeMember("click");
            }
        }

这篇关于System.Windows.Forms.SendKeys.SendInput &gt;&gt;任务计划程序拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
C#/.NET最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆