none
Automating IE whith powershell - Running Schedule Task (Run whether user is logged on or not) RRS feed

  • Question


  • Well like the title say i made a little powershell task that i need to run even i stay logged or not. need run this on windows server 2008 r2 and i have admin user

    here's the script:

    $ie = new-object -ComObject "InternetExplorer.Application"

    $requestUri = "https://any_web"

    $ie.visible = $true
    $ie.silent = $true
    $ie.navigate($requestUri)

    while($ie.Busy) { Start-Sleep -Milliseconds 100 }

    $doc = $ie.Document

    $user = $doc.getElementsByTagName("input") | ? { $_.name -eq "username" }
    $pwd = $doc.getElementsByTagName("input") | ? { $_.name -eq "password" }
    $btn = $doc.getElementsByTagName("button") | ? { $_.name -eq "user_submitted_login_form" }

    $user.value = "user"
    $pwd.value = "password"
    $btn.click()

    while($ie.Busy) { Start-Sleep -Milliseconds 100 }

    $ie.Document.body.getAttributeNode("onload") | Out-File -FilePath C:\Users\folder\weblogin.txt

    If i run this from:

    powershell works fine and weblogin.txt have data

    ssis package work fine and weblogin.txt have data, but if i create a job and schedule it, like it works fine but weblogin.txt have not data

    windows task schedule works fine if i setup "Run only when user is logged on" and weblogin.txt have data

    if i try yo create a job and schedule in server or if i try to  schedule like windows task to "Run whether user is logged on or not" apparently work fine but weblogin.txt have not data

    i have not idea what can i do...  i read in an article somtehing like this

    You need to create a Desktop folder in

    32-bit
    C:\Windows\System32\config\ systemprofile\
    64-bit
    C:\Windows\SysWOW64\config\systemprofile\

    but nothing change...

    I hope some1 of you can help!

    Thanks!

    if you know about a different but functional way to do this... i'm all ears-
    Tuesday, October 15, 2019 11:39 PM

Answers

  • You cannot run IE in a scheduled task when you are not logged in. It is strictly forbidden.


    \_(ツ)_/

    • Marked as answer by Lufoque Wednesday, October 16, 2019 12:23 AM
    Tuesday, October 15, 2019 11:50 PM

All replies