Feb 10, 2013 05:28 PM
(This post was last modified: Feb 10, 2013 05:37 PM by Networkmancer.)
I think no one posted this simple way of blocking application in windows so Ill share mine.
Top most
To call
Disable Application
Enable Disabled Application
If you want to use open file dialog box
Top most
Code
Imports Microsoft.Win32To call
Disable Application
Code
appcontrol(True, yourblockprocessnameSTRING)Enable Disabled Application
Code
appcontrol(False, yourblockprocessnameSTRING)Code
Shared Sub appcontrol(accessFlag, exename)
If accessFlag = True Then
'adding to registry start
Try
Dim CU As Microsoft.Win32.RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun", True)
If CU Is Nothing Then
CU = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", True)
CU.SetValue("DisallowRun", 1, RegistryValueKind.DWord)
CU.CreateSubKey("DisallowRun")
CU = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun", True)
CU.SetValue(exename, exename & ".exe", RegistryValueKind.String)
CU = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", True)
MsgBox("Successfully Restricted " & exename & ".", MsgBoxStyle.Information)
Else
CU = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", True)
CU.SetValue("DisallowRun", 1, RegistryValueKind.DWord)
CU = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun", True)
CU.SetValue(exename, exename & ".exe", RegistryValueKind.String)
MsgBox("Successfully Restricted " & exename & ".", MsgBoxStyle.Information)
End If
Catch ex As Exception
MsgBox("Error writing the registry" & vbNewLine & "Please use windows admin account", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical)
End Try
'end
Else : accessFlag = False
Try
Dim CU As Microsoft.Win32.RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun", True)
CU.DeleteValue(exename)
MsgBox("Successfully Allowed " & exename & ".", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End If
End SubIf you want to use open file dialog box
Code
Private Sub OpenFileDialogBox1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialogBox1.FileOk
Try
path = ApplicationExplore.FileName.ToString()
exename = System.IO.Path.GetFileName(path)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub


