Created
February 4, 2016 08:35
-
-
Save Mandar-Shinde/0c4958d80f10ba63842f to your computer and use it in GitHub Desktop.
Reloads Taskbar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Runtime.InteropServices; | |
using System.Diagnostics; | |
using System.Threading; | |
namespace RemoveTrayPin | |
{ | |
class Program | |
{ | |
[DllImport("user32.dll", SetLastError = true)] | |
static extern bool PostMessage(IntPtr hWnd, [MarshalAs(UnmanagedType.U4)] uint Msg, IntPtr wParam, IntPtr lParam); | |
[DllImport("user32.dll", SetLastError = true)] | |
static extern IntPtr FindWindow(string lpClassName, string lpWindowName); | |
//[DllImport("USER32.DLL")] | |
//public static extern int SendMessage(IntPtr hwnd, int msg, int character,IntPtr lpsText); | |
const int WM_USER = 0x0400; //http://msdn.microsoft.com/en-us/library/windows/desktop/ms644931(v=vs.85).aspx | |
//public const int WM_PAINT = 0xF; | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
// REG Delete | |
//HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\TypeedPaths | |
var ptr = FindWindow("Shell_TrayWnd", null); | |
PostMessage(ptr, WM_USER + 436, IntPtr.Zero,IntPtr.Zero); | |
// Repaint | |
//SendMessage(ptr, WM_PAINT, 0, IntPtr.Zero); | |
do | |
{ | |
ptr = FindWindow("Shell_TrayWnd", null); | |
if (ptr.ToInt32() == 0) | |
break; | |
Thread.Sleep(10); | |
} while (true); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("{0} {1}", ex.Message, ex.StackTrace); | |
} | |
Console.WriteLine("Restarting the shell."); | |
string explorer = string.Format("{0}\\{1}", Environment.GetEnvironmentVariable("WINDIR"), "explorer.exe"); | |
Process process = new Process(); | |
process.StartInfo.FileName = explorer; | |
process.StartInfo.UseShellExecute = true; | |
process.Start(); | |
Console.ReadLine(); | |
} | |
} | |
} | |
// from stackoverflow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment