using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Mesoft
{
namespace WindowActivites
{
public class WindowOperation
{
#region "Variable Declaration";
public static int intLLKey;
public const int WH_KEYBOARD_LL = 13;
#endregion
#region "Stuctures"
public struct KBDLLHOOKSTRUCT
{
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
}
#endregion
#region "Methods"
public void KillTaskManager()
{
Microsoft.Win32.RegistryKey regkey;
string keyValueInt = "1";
string subKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
try
{
regkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(subKey);
regkey.SetValue("DisableTaskMgr", keyValueInt);
regkey.Close();
}
catch (Exception ex)
{
throw ex;
}
}
[DllImport("user32.dll")]
private static extern int FindWindow(string className, string windowText);
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int command);
[DllImport("user32", EntryPoint = "SetWindowsHookExA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int SetWindowsHookEx(int idHook, LowLevelKeyboardProcDelegate lpfn, int hMod, int dwThreadId);
[DllImport("user32", EntryPoint = "UnhookWindowsHookEx", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int UnhookWindowsHookEx(int hHook);
public delegate int LowLevelKeyboardProcDelegate(int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam);
[DllImport("user32", EntryPoint = "CallNextHookEx", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int CallNextHookEx(int hHook, int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam);
public void SetWindowsHookEx()
{
try
{
SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]).ToInt32(), 0);
}
catch (Exception ex)
{
throw ex;
}
}
public int LowLevelKeyboardProc(int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam)
{
try
{
bool blnEat = false;
switch (wParam)
{
case 256:
case 257:
case 260:
case 261:
//Alt+Tab, Alt+Esc, Ctrl+Esc, Windows Key,
blnEat = ((lParam.vkCode == 9) && (lParam.flags == 32)) | ((lParam.vkCode == 27) && (lParam.flags == 32)) | ((lParam.vkCode == 27) && (lParam.flags == 0)) | ((lParam.vkCode == 91) && (lParam.flags == 1)) | ((lParam.vkCode == 92) && (lParam.flags == 1)) | ((lParam.vkCode == 73) && (lParam.flags == 0));
break;
}
if (blnEat == true)
{
return 1;
}
else
{
return CallNextHookEx(0, nCode, wParam, ref lParam);
}
}
catch (Exception ex)
{
throw ex;
}
}
public void KillStartMenu()
{
try
{
int hwnd = FindWindow("Shell_TrayWnd", "");
ShowWindow(hwnd, 0);
}
catch (Exception ex)
{
throw ex;
}
}
public void ShowStartMenu()
{
try
{
int hwnd = FindWindow("Shell_TrayWnd", "");
ShowWindow(hwnd, 1);
}
catch (Exception ex)
{
throw ex;
}
}
public void ShowTaskManager()
{
try
{
string subKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser;
Microsoft.Win32.RegistryKey sk1 = rk.OpenSubKey(subKey);
if (sk1 != null)
{
rk.DeleteSubKeyTree(subKey);
}
}
catch (Exception ex)
{
throw ex;
}
}
public void CloseAllWindow()
{
try
{
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses(System.Environment.MachineName))
{
if (p.MainWindowHandle != IntPtr.Zero)
{
p.Kill();
}
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}
}
No comments:
Post a Comment