Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Deactivate or Reactivate the Task Manager
Author:
Heinz Prelle
E-mail:
Click to e-mail author
Submitted:
9/6/2008
Version:
VB 2005
Compatibility:
VB 2005, VB 2008
Category:
Windows Registry
Views:
14741
This example deactivates or reactivates the Windows Task Manager. The example needs two buttons: Button1 and Button2.
Declarations:
Option Explicit On Option Strict On Imports Microsoft.Win32
Code:
Public Class Form1 Private Structure RegistryValue Public Path As String Public Value As String End Structure Private rv As RegistryValue = New RegistryValue() Private ReadOnly Property OpenRegistryKeyForWriting() As RegistryKey Get Const Path As String = "Software\Microsoft\Windows\CurrentVersion\Policies\System" Return Registry.CurrentUser.OpenSubKey(Path, True) End Get End Property Private Sub EnableDisableTaskmanager(ByVal Index As String) Dim hKey As RegistryKey = Nothing Try Select Case Index Case "Disabled" hKey = Me.OpenRegistryKeyForWriting() If hKey Is Nothing Then hKey = Registry.CurrentUser.CreateSubKey(rv.Path) hKey.SetValue(rv.Value, 1, RegistryValueKind.DWord) Else hKey = Registry.CurrentUser.CreateSubKey(rv.Path) hKey.SetValue(rv.Value, 1, RegistryValueKind.DWord) End If Case "Enabled" hKey = Me.OpenRegistryKeyForWriting() If hKey IsNot Nothing Then hKey = Registry.CurrentUser.CreateSubKey(rv.Path) hKey.SetValue(rv.Value, 0, RegistryValueKind.DWord) End If End Select Catch ex As Exception MessageBox.Show(ex.Message.ToString(), "Info") Finally If hKey IsNot Nothing Then hKey.Close() End If End Try End Sub Private Function OSVersion() As Boolean If System.Environment.OSVersion.Platform = PlatformID.Win32NT = True Then Return True Else Return False End If End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load If Me.OSVersion = False Then MessageBox.Show("This example works only under WinNT or higher...", "Info") Application.Exit() End If Me.CenterToScreen() With Me.rv .Path = "Software\Microsoft\Windows\CurrentVersion\Policies\System" .Value = "DisableTaskMgr" End With End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click Me.EnableDisableTaskmanager("Disabled") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button2.Click Me.EnableDisableTaskmanager("Enabled") End Sub End Class
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement