Run Hidden IE session, Terminate after 30 seconds

This topic contains 2 replies, has 2 voices, and was last updated by  Ben Camareno 4 months, 2 weeks ago.

  • Author
    Posts
  • #72083

    E
    Participant

    Hi Everyone,

    I've been spending the last few days trying to write a script but not having much luck.

    What I would like to achieve (whether it be by powershell or some other method) is to open an internet browser window, load a website, wait 30 seconds then terminate the specific window only (Not all active IE windows).

    Now I have been able to write a script which kills ALL iexplore.exe windows but haven't been able to target the specific one.

    I did find a lot of useful info on this webpage (https://ss64.com/ps/start-process.html) and came up with the following script...

    $pclass = [wmiclass]'root\cimv2:Win32_Process'
    $new_pid = $pclass.Create('IExplore.exe', '.', $null).ProcessId
    $new_pid = [diagnostics.process]::start("IExplore.exe", "www.google.com")

    Start-Sleep -s 30
    kill $new_pid

    This opens a iexplore.exe window and loads http://www.google.com and after 30 seconds will terminate that iexplore.exe window ONLY. Only thing I need to do now is make it invisible to the end user...

    For a little more information what I am trying to achieve is to automatically log a user onto the Office 365 portal when they first login to their machine. This will mean our intranet homepage (hosted on sharepoint) will load faster without the user having to wait for single sign on to login and will mean sharepoint mapped drives will be accessible instantly rather than requiring the end user to open an IE window and login.

    I don't expect anyone to do the work for me, but would be good to know if I am on the right track. I have tried to get this working myself but am under pressure to get it working ASAP.

    Cheers, Errol.

  • #72085

    E
    Participant

    Also tried this...

    $app = Start-Process -WindowStyle hidden -filepath "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -passthru
    sleep -s 10
    Stop-Process $app.Id

    Seems to work for notepad but doesn't work for IE or chrome...

    • #72094

      Ben Camareno
      Participant

      Try this:

      $url = "www.powershell.org" 
      $ie = New-Object -com internetexplorer.application
      $ie.visible = $false
      $ie.navigate($url)
      

You must be logged in to reply to this topic.