Skip to main content

Screen Lock with IniFile


This code will allow you to disable alt + f4, ctrl + alt + del, alt + tab, alt + esc, windows key, ctrl + esc.

Sample code:

  1. Public Class Form1
  2.  
  3. Public g_IniSettings As New IniFile
  4.  
  5. #Region "Alt + F4"
  6.  
  7.  
  8. Protected Overrides ReadOnly Property CreateParams() As CreateParams
  9. Get
  10. Dim cp As CreateParams = MyBase.CreateParams
  11. Const CS_NOCLOSE As Integer = &H200
  12. cp.ClassStyle = cp.ClassStyle Or CS_NOCLOSE
  13. Return cp
  14. End Get
  15. End Property
  16. #End Region
  17.  
  18. Friend Sub check_settings()
  19.  
  20. g_IniSettings.FileName = Application.StartupPath & "\ScreenLockSettings.ini"
  21.  
  22. Dim fi As New FileInfo(g_IniSettings.FileName)
  23.  
  24. If Not fi.Exists() Then
  25. 'MessageBox.Show("INI file not found:" & vbCrLf & vbCrLf & g_IniSettings.FileName, "Error")
  26. End If
  27.  
  28. Try
  29. ' Application.Run(New frmSettings)
  30. Catch e As Exception
  31. ' MessageBox.Show("Application Error:" & _
  32. ' vbCrLf & vbCrLf & e.ToString, "Error")
  33. End Try
  34. End Sub
  35.  
  36. Dim terminateProgram As Integer = 0
  37.  
  38. Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown, TextBox1.KeyDown, Button1.KeyDown
  39. If e.KeyCode = Keys.Enter Then
  40. Button1.PerformClick()
  41. End If
  42. End Sub
  43. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  44. Timer1.Start()
  45. check_settings()
  46.  
  47. g_IniSettings.FileName = Application.StartupPath & "\ScreenLockSettings.ini"
  48.  
  49. Dim fi As New FileInfo(g_IniSettings.FileName)
  50.  
  51. If Not fi.Exists Then
  52. terminateProgram = 1
  53. TopMost = False
  54. Form2.Show()
  55. Me.Hide()
  56. End If
  57.  
  58. End Sub
  59.  
  60. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  61.  
  62. If TextBox1.Text = g_IniSettings.GetSetting("Role", "Admin") Then
  63. terminateProgram = 1
  64. TopMost = False
  65. Form2.Show()
  66. Me.Hide()
  67. ElseIf TextBox1.Text = g_IniSettings.GetSetting("Role", "User") Then
  68. End
  69. Else
  70. terminateProgram = 0
  71. Timer1.Start()
  72. TextBox1.BackColor = Color.Red
  73. End If
  74. End Sub
  75.  
  76. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  77. If terminateProgram = 0 Then
  78. TopMost = True
  79. End If
  80. End Sub
  81.  
  82.  
  83. End Class

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Submitted byFawaz Ibrahim (not verified)on Fri, 08/30/2013 - 20:00

I think you can open the file {WINDOWS path + "\system32\taskmgr.exe" } for append
and so , if the user press {CTRL + ALT + DEL}, he will have an error message as the following {The current file is being used by another application}

Submitted byedzbil (not verified)on Thu, 09/12/2013 - 16:54

The better way to lock your screen is to kill and start the process so the task manager will be disabled, and start programatically by providing password from a user intend to unlock a computer.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.