How do I lock a windows workstation programmatically? [duplicate]

I haven’t tried it myself, but I found this on google Process.Start(@”C:\WINDOWS\system32\rundll32.exe”, “user32.dll,LockWorkStation”); edit: I tried it, and it works! edit2: Here’s a solution using user32.dll that doesn’t start an external process. using System.Runtime.InteropServices; declare a method like this: [DllImport(“user32.dll”)] public static extern bool LockWorkStation(); and then call LockWorkStation();. VoilĂ 

Directing mouse events [DllImport(“user32.dll”)] click, double click

[DllImport(“user32.dll”, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, UIntPtr dwExtraInfo); private const uint MOUSEEVENTF_LEFTDOWN = 0x02; private const uint MOUSEEVENTF_LEFTUP = 0x04; private const uint MOUSEEVENTF_RIGHTDOWN = 0x08; private const uint MOUSEEVENTF_RIGHTUP = 0x10; You should Import and Define these Constant’s to work with … Read more

Move window when external application’s window moves

A method to hook a Windows Form to another process (Notepad, in this case) and follow the movements of the process’ Main Window, to create sort of a Toolbar that can interact with the process, using SetWinEventHook(). To get the hooked Window bounds, GetWindowRect() is not recommended. Better call DwmGetWindowAttribute() passing DWMWA_EXTENDED_FRAME_BOUNDS as the DWMWINDOWATTRIBUTE, … Read more

Using SetWindowPos with multiple monitors

System Displays disposition and VirtualScreen In a Windows System, the Primary Screen (programming perspective) is the Display device which has its upper left corner position set at Point(0,0). This implies that the Displays positioned on the left of the Primary Screen, will have negative X coordinates (the Y coordinate could be negative if the Display … Read more