Hyper Expert /Blog
About
Archives

HOW-TO: Lock your desktop screen with a password (not a screen saver)

Imagine this scenario, you are teaching a class, your classroom has a projector or a big screen TV to display pictures or presentations, your students are taking a test and you want to be able to lock your computer with a password to a picture or some classroom guidelines while you step out of the class for a quick moment. The only way to password protect your PC is to either log off, lock your account, or display a screensaver, either one of these will not let you display a specific web page on the screen, or maybe a picture or some class guidelines.

There is a simple way to do this, the below HTML code (saved as .hta) when launched, it opens up in full screen mode, locks your screen with the password 123, with very little HTML knowledge, you can change the password to anything you want and customize the page to show anything you want, you will not be able to minimize it or close the screen without inputting the password!

<html>
<head>
<TITLE>LOGIN</TITLE>  
   <HTA:APPLICATION  
   APPLICATIONNAME="LOGIN"  
   VERSION="1.0.0.0"  
   BORDER="none"  
   INNERBORDER="no"  
   CAPTION="no"  
   SYSMENU="no"  
   MAXIMIZEBUTTON="no"  
   MINIMIZEBUTTON="no"  
   ICON="NO"  
   SCROLL="no"  
   SCROLLFLAT="yes"  
   SINGLEINSTANCE="yes"  
   WINDOWSTATE="maximize"  
   SHOWINTASKBAR="no"  
   CONTEXTMENU="no"  
   SELECTION="no"/> 
</head>

<SCRIPT Language="VBScript">
Sub RunScript
   Password=InputBox("Type your Password :","Type your Password")  
   IF Password ="" THEN  
      MsgBox "Password is empty !",16,"Password is empty !"
   End If
   If Password = "123" Then
   window.close
   End if
End Sub

Sub Pointer
   document.body.style.cursor = "hand"
End Sub

Sub DefaultCursor
   document.body.style.cursor = "default"
End Sub
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript"> 
function document.onkeydown() {  
   var alt=window.event.altKey; 
   if (event.keyCode==116 || event.keyCode==27 || alt && event.keyCode==115) { 
   event.keyCode=0; 
   event.cancelBubble=true; 
   return false; 
   } 
} 
</SCRIPT> 

<body text=white bgcolor=#1234568>

<center><span id="ClickableSpan" onClick="RunScript" onmouseover="Pointer" 
onmouseout="DefaultCursor">
Click here to UnLock The Screen</span>

</body>
</html>

 
Download source file

EDIT
I have added the VBS script below to automatically close explorer.exe, launches ScreenLock.hta file to lock the screen, then the VBS script will wait in the background, once you put in the password to unlock the screen, the vbs script will launch explorer.exe again and closes itself.

This may improve security a bit!

On Error Resume Next 
Set objShell = CreateObject("WScript.Shell") 
Set fso = CreateObject("Scripting.FileSystemObject")

dim strComputer 
dim wmiNS 
dim wmiQuery 
dim objWMIService 
dim colItems 
dim objItem 
Dim strOUT 
 
strComputer = "." 
wmiNS = "\root\cimv2" 
wmiQuery = "Select processID from win32_process where name = 'explorer.exe'" 
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS) 
Set colItems = objWMIService.ExecQuery(wmiQuery) 
 
For Each objItem in colItems 
    	objItem.terminate(1) 'need 1 to keep from restarting explorer 
    subLaunch     
Next 
 
Sub subLaunch 
Dim objShell 
Dim strProg 
 
strProg = "ScreenLock.hta" 
Const MaxWindow = 3 
Const blnWait = True 
 
Set objShell = CreateObject("wscript.shell") 
objShell.Run strProg,maxWindow,blnWait 
 
subcreateProcess 
 
End Sub  
 
Sub subcreateProcess 
Dim obj 'uses get method to get win32_process so we can launch new explorer 
Set obj = objWMIService.Get("win32_process") 
obj.create("explorer.exe") 
End sub

End If

WScript.Quit()

 
Download source with VBS script

///

Hi, my name is Ali. I am a Systems Engineer. I live in the beautiful Evergreen state. I have a Bachelor degree of science in Information Technology with a handful of accompanying I.T. certificates. I also have a degree in Computer Networking. I am an Apple Certified Technician, Microsoft MCITP and a Linux expert.

3 Comments

  1. Carlos · May 31, 2013

    This is awesome and it works great with one exception….can you make it always on top? I was able to get around it with ALT+TAB and other methods and it would be perfect if there was no way around it but putting in the password!

    Reply
    • Ali · May 31, 2013

      Of course, it is possible, give me a minute let me update the code šŸ˜‰

      Reply
    • Ali · May 31, 2013

      I may have spoke way too soon! It is possible, but through a registry edit! and in order to do that, you will need to at least log off and log back in to make it work! I am still searching of a way! of you come up with anything, let me know

      Reply

Would you like to share your thoughts?