blog.devgenius.io Open in urlscan Pro
162.159.153.4  Public Scan

Submitted URL: https://blog.devgenius.io/how-to-prevent-computer-from-sleep-and-stay-awake-always-script-74a8906a7629
Effective URL: https://blog.devgenius.io/how-to-prevent-computer-from-sleep-and-stay-awake-always-script-74a8906a7629?gi=2796dadd9efc
Submission: On May 28 via manual from US — Scanned from DE

Form analysis 0 forms found in the DOM

Text Content

Open in app

Sign up

Sign in

Write


Sign up

Sign in




TWO EFFECTIVE WAYS KEEP YOUR PC AWAKE ALL THE TIME

Ganesh Hegde

·

Follow

Published in

Dev Genius

·
4 min read
·
Aug 10, 2023

59

2

Listen

Share



Many of us require a solution to keep our Windows 10 and Windows 11 computers
awake at all times. There are various situations where we need to prevent the
computer from going to sleep, such as displaying Microsoft Teams and Slack
status as "online" while you are away and when you need to perform continuous
background activity, etc.

The market is flooded with numerous apps, but trying them out can be scary due
to the risk of malware or viruses. This article shows a simple and risk-free
method to keep your computer awake for as long as you need.

This “screen stay awake” script works as an alternative to tools like Caffeine,
KeepingYouAwake, Mouse Jiggler, Don’t Sleep, Noise, etc.


TWO EFFICIENT WAYS TO CHANGE THE WINDOWS 10 OR 11 SLEEP SETTINGS

 1. Using in Built Windows Settings
 2. Using Powershell and/or Batch Script


WINDOWS SETTINGS TO TURN OFF THE SLEEP AND KEEP YOUR LAPTOP AWAKE

Step 1: Navigate to Settings in Windows

Step 2: Search for Power and Battery

Step 3: Navigate to Power and Battery Settings

Step 4: Change the Options

 * On battery power, put my device to sleep after: Never.
 * When plugged in, put my device to sleep after: Never.


Windows Settings Power and Battery to Control the Sleep Time

One of the major disadvantages of the above approach is, this will prevent your
computer from going to sleep but if you are using MS Teams, Slack, or any other
messengers, it will still show you away after a specific period of time. In
order to overcome that I am providing you with the simplest solution as
mentioned below.


STEP-BY-STEP GUIDE TO KEEP YOUR COMPUTER SCREEN AWAKE USING POWERSHELL SCRIPT
AND BATCH COMMAND


BATCH AND POWERSHELL SCRIPT TO KEEP WINDOWS 10/11 COMPUTER AWAKE.

This is the very simplest solution, which I have made. No need to install any
apps or no need to configure anything. Interestingly, you do not need to have
admin permissions to keep your screen awake.


STEP 1: CREATE A POWERSHELL SCRIPT

Copy and paste the below code and Save this as awakealways.ps1

Note:

 * Please use the same name(awakealways.ps1) as we will use this in the bat
   file.
 * You can use Notepad or Notepad++ to copy, paste and save this file.

#Save this as awakealways.ps1
add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

Write-Warning "This will Prevent screen from sleep"
$form = New-Object System.Windows.Forms.Form
$form.Text = 'AwakeScreen'
$form.Size = New-Object System.Drawing.Size(200,100)
$form.StartPosition = 'Manual'
$form.Location = New-Object System.Drawing.Point(1500,670)
$textBox = New-Object System.Windows.Forms.TextBox
#$textBox.Location = New-Object System.Drawing.Point(10,40)
$textBox.Size = New-Object System.Drawing.Size(200,100)
$textBox.Multiline = $true 
$form.Controls.Add($textBox)
$form.Topmost = $true
$form.Add_Shown({$textBox.Select()})
$form.Show()
 start-sleep -Milliseconds 1000
 try{

  Do {  
            $form.Activate()
            #[Microsoft.VisualBasic.Interaction]::AppActivate($form.fo)
             [System.Windows.Forms.SendKeys]::SendWait("{BS}")
    [System.Windows.Forms.SendKeys]::SendWait(".")
    start-sleep -Milliseconds 180000
  } While ($true)
 }

 finally
 {
  Write-Warning "Terminating Powershell Script"
  #Stop-Process  $form
        $form.Close()
 }


STEP 2: CREATE A .BAT FILE WITH NAME AWAKE.BAT

Copy and paste the below code.

@echo off
powershell.exe -ExecutionPolicy Bypass -File awakealways.ps1

Note: You need to create a bat file same folder as your PowerShell script file
(Else provide the correct path)


STEP 3: DOUBLE CLICK ON AWAKE.BAT

In Step 2 you have created the awake.bat which internally calls the Powershell
script. Now if you double-click on the batch file, The command prompt opens and
always keeps your screen awake.

Anytime you want to stop this script, navigate to the command line where the
script is being executed just press CTRL+C and Press Y when it asks for
confirmation.


ADVANTAGES OF SCREEN AWAKE USING THE POWERSHELL AND BATCH SCRIPT

 * No need to worry about malware and virus
 * No admin permission required
 * Unlike Windows 11 default lock screen setting this script keeps your all
   messengers such as Microsoft Teams, Slack, etc. shown Online.
 * It helps to keep background activity running for a long time.


FREQUENTLY ASKED QUESTIONS


1. HOW DO I KEEP MY LAPTOP ACTIVE WHILE AWAY?

The above given PowerShell script helps you to keep your laptop active while
away.


2. HOW DO I PREVENT MICROSOFT TEAMS AND SLACK FROM GOING AWAY?

The given PowerShell script is very powerful it simulates the keystrokes so it
keeps Microsoft Teams, Slack, and other messengers to stay online though you are
away.


3. HOW CAN I TEMPORARILY DISABLE OR STOP WINDOWS COMPUTERS FROM GOING TO SLEEP?

You can run the given batch command, and keep it running as long as you want.
The Laptop/Computer doesn’t go to sleep mode as long as it is running.


4. HOW CAN I PREVENT THE WINDOWS COMPUTER FROM GOING TO SLEEP WITHOUT
ADMINISTRATOR PERMISSION?

As I mentioned before you can execute the Powershell script without admin rights
to disable Windows from going to sleep.


5. CAN I USE THIS SCRIPT TO DISABLE SLEEP SETTINGS ON MY WINDOWS 10 AND WINDOWS
11?

Yes, this application or utility supports both Windows 10 and Windows 11. So,
you can use this script to temporarily disable Windows sleep settings.


6. CAN THIS COMMAND HELP ME TO STOP TURNING OFF WINDOWS 10 OR WINDOWS 11?

Absolutely Yes!, during keep awake PowerShell script execution time the computer
never goes to sleep.


FOLLOW ME ON LINKEDIN: HTTPS://WWW.LINKEDIN.COM/IN/GANESHSIRSI/





SIGN UP TO DISCOVER HUMAN STORIES THAT DEEPEN YOUR UNDERSTANDING OF THE WORLD.


FREE



Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.


Sign up for free


MEMBERSHIP



Access the best member-only stories.

Support independent authors.

Listen to audio narrations.

Read offline.

Join the Partner Program and earn for your writing.


Try for 5 $/month
Windows
Windows 10
Windows 11
Powershell
Batch


59

59

2


Follow



WRITTEN BY GANESH HEGDE

275 Followers
·Writer for

Dev Genius

https://www.linkedin.com/in/ganeshsirsi/

Follow




MORE FROM GANESH HEGDE AND DEV GENIUS

Ganesh Hegde

in

Geek Culture


HOW TO SETUP PLAYWRIGHT END TO END TEST AUTOMATION FRAMEWORK


EASY WAY TO SET UP AUTOMATION TESTING FRAMEWORK WITH PLAYWRIGHT, THIS TUTORIAL
USERS PAGE OBJECT MODEL AND TYPESCRIPT.

5 min read·Aug 15, 2021

75

3




Anusha SP

in

Dev Genius


JAVA 8 CODING AND PROGRAMMING INTERVIEW QUESTIONS AND ANSWERS


IT HAS BEEN 8 YEARS SINCE JAVA 8 WAS RELEASED. I HAVE ALREADY SHARED THE JAVA 8
INTERVIEW QUESTIONS AND ANSWERS AND ALSO JAVA 8 STREAM API…

6 min read·Jan 31, 2023

894

12




Ani Talakhadze

in

Dev Genius


TOP 10 ESSENTIAL STREAM OPERATIONS IN JAVA


BOOST YOUR JAVA EFFICIENCY WITH EXAMPLES, EXERCISES AND FUN FACTS

9 min read·Apr 21, 2024

99

4




Ganesh Hegde


HOW TO SET UP CYPRESS AND TYPESCRIPT END TO END TEST AUTOMATION FRAMEWORK FROM
SCRATCH STEP BY STEP…


THIS ARTICLE EXPLAINS CREATING OR SETTING UP A CYPRESS.IO END-TO-END TESTING
FRAMEWORK FROM SCRATCH USING TYPESCRIPT. UNLIKE ANOTHER…

8 min read·Dec 21, 2022

75

1



See all from Ganesh Hegde
See all from Dev Genius



RECOMMENDED FROM MEDIUM

Mohammad Abu Humaidan


AUTOMATE YOUR DEPLOYMENT USING AZURE DEVOPS CI CD PIPELINE IN 30 MINUTES


WHAT IS AZURE PIPELINE(MEAN)?

8 min read·May 11, 2024

54

1




Artturi Jalli


I BUILT AN APP IN 6 HOURS THAT MAKES $1,500/MO


COPY MY STRATEGY!


·3 min read·Jan 23, 2024

18.5K

198





LISTS


OUR FAVORITE PRODUCTIVITY ADVICE

9 stories·529 saves


Tony M Elkins


POWERSHELL: EXCHANGE CALENDAR ADMINISTRATION


WHILE THE OFFICE 365 ADMIN CENTER IS A DAILY RESOURCE IN IT ADMINISTRATION AND
CAN BE USED TO FIND WHAT CALENDARS A USER HAS ACCESS TO, THE…

4 min read·Jan 21, 2024

8





DINESH REDDY JETTI


ANSIBLE ZERO TO HERO — ANSIBLE FRAMEWORK FOR AZURE PIPELINES TO EXECUTE ON THE
REMOTE MACHINES —…


SETTING UP AN AZURE PIPELINE FOR AN ANSIBLE PLAYBOOK WITH ROLES INVOLVES
DEFINING THE NECESSARY CONFIGURATION FILES AND STEPS TO AUTOMATE…


·4 min read·Dec 15, 2023



Benoit Ruiz

in

Better Programming


ADVICE FROM A SOFTWARE ENGINEER WITH 8 YEARS OF EXPERIENCE


PRACTICAL TIPS FOR THOSE WHO WANT TO ADVANCE IN THEIR CAREERS

22 min read·Mar 20, 2023

16K

293




Hazel Paradise


HOW I CREATE PASSIVE INCOME WITH NO MONEY


MANY WAYS TO START A PASSIVE INCOME TODAY

5 min read·Mar 27, 2024

14.3K

352



See more recommendations

Help

Status

About

Careers

Press

Blog

Privacy

Terms

Text to speech

Teams


To make Medium work, we log user data. By using Medium, you agree to our Privacy
Policy, including cookie policy.