1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
''Klasse
Public Class clsHideTaskManager
Implements IDisposable
Public Enum TaskManagerState As Integer
Disabled = 1
Enabled = 0
End Enum
Public Reg_hkcu As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser
Public Const subKey As String = "Software\Microsoft\Windows\CurrentVersion\Policies\System"
Public Sub SetTaskManager(ByVal _state As TaskManagerState)
Try
Dim reg As Microsoft.Win32.RegistryKey = Reg_hkcu.OpenSubKey(subKey, True)
If reg Is Nothing AndAlso _state = TaskManagerState.Disabled Then
reg = Reg_hkcu.CreateSubKey(subKey)
ElseIf reg Is Nothing Then
Exit Sub
End If
reg.SetValue("DisableTaskMgr", CInt(_state))
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Function GetTaskManagerState() As TaskManagerState
Dim _val As Integer = -1
Dim _reg As Microsoft.Win32.RegistryKey = Reg_hkcu.OpenSubKey(subKey)
''Wird nichts gemacht ist der Taskmanageraufruf moeglich
If _reg Is Nothing Then
Return TaskManagerState.Enabled
Else
_val = CInt(_reg.GetValue("DisableTaskMgr"))
End If
Return CType(IIf(_val = 1, TaskManagerState.Disabled, TaskManagerState.Enabled), TaskManagerState)
End Function
Protected Overrides Sub Finalize()
Me.Dispose()
MyBase.Finalize()
End Sub
Public Sub Dispose() Implements System.IDisposable.Dispose
Try
Reg_hkcu.Close()
Reg_hkcu = Nothing
GC.SuppressFinalize(Me)
Catch
End Try
End Sub
End Class
''Mögliche Anwendung/Aufruf:
''Auf einem Formual eine CheckBox und ein Button plazieren, die Klasse Win32 Registry importieren und lost gehts
Imports Microsoft.Win32.Registry
Public Class Form1
Private cls As New clsHideTaskManager
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
cls.Dispose()
End Sub
Private Sub Loaded(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
cbDisableTM.Checked = cls.GetTaskManagerState = clsHideTaskManager.TaskManagerState.Disabled
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cls.SetTaskManager(CType(IIf(cbDisableTM.Checked, clsHideTaskManager.TaskManagerState.Disabled, _
clsHideTaskManager.TaskManagerState.Enabled), clsHideTaskManager.TaskManagerState))
Button1.Enabled = False
End Sub
End Class
|