Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7872783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:18:49+00:00 2026-06-03T02:18:49+00:00

I just finished writing a script with PowerShell and I need it to run

  • 0

I just finished writing a script with PowerShell and I need it to run every time my system wakes up from sleep or Hibernation.
I tried the gpedit.msc -> User Config -> Windows Settings -> Scripts -> Logon but this does not work when my system Wakes up from ‘Sleep’… probably because ‘Sleep’ – > ‘Wake -up’ is not technically new logon (As a user I am already logged-on).

Either a Sleep-Wake event or Login (User Login) event should trigger my script.

Any ideas on how I can do this?

More Info on what my script does: It checks if internet/network is connected. If yes, it will attempt to run the Cisco VPN connection command line utility with required arguments and logs me into VPN. Every time I wake my system up from sleep and login I need the damn VPN to connect me automatically.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:18:51+00:00Added an answer on June 3, 2026 at 2:18 am

    I figured it out. I used the Task Scheduler as Richard indicated above.

    I set the Trigger as..
    On an Event -> System -> Kernel-Power -> 42

    If anyone is interested… here is the script (I am a beginner with PowerShell scripts, so welcome your inputs)

    $strComputerName = gc env:computername
    $strVPN = 'c:\Program Files (x86)\Cisco Systems\VPN Client\vpnclient.exe'
    $vpnArgs = 'connect', 'ProfileName', 'user', 'XXXXXXXX', 'pwd', 'XXXXXXXXXX'
    [int]$count = 6
    Write-Host "Checking for Internet Connectivity"
    While (!([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet))
    {
        Write-Host "Sleeping for 10 seconds before checking for internet again"
        Start-Sleep -s 10
        $count--
        if ( $count -eq 0) 
        {
            Write-Host "Breaking from loop"
            break
        }
    }
    if ( $count -ne 0) { Invoke-Command -ScriptBlock { & $strVPN $vpnArgs } }
    else { Write-Host "No Internet Connectivity, so not attempting VPN connection" }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just finished writing this script and getting it to work but I need
I just finished writing a small script to combine a lot of png pictures
I just finished writing my very first command-line tool in Objective-C, compiled it, and
I just finished writing a date parser for my ECMAScript implementation. Previously I had
Hey, I've just finished writing a VB.NET application. Now I want to package the
im interested i just finished writing a program and one of the functions that
As a developer who has just finished writing thousands of lines of complex multi-threaded
As a programming exercise, I just finished writing a Sudoku solver that uses the
just finished writing a five card poker hand evaluator in C++. now im looking
I just finished writing a function that has ended up with nested code blocks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.