I want to simulate WindowsKey + L (The short cut to lock the console) in visual basic and bind it to a function. So when this function is called it will lock the console.
Can I do this?
I want to simulate WindowsKey + L (The short cut to lock the console)
Share
Simulating the hotkey is the wrong approach. All you need to do is call the
LockWorkStationfunction. This has the same result as pressing Ctrl+Alt+Del and selecting “Lock Workstation”, or using the Win+L hotkey, except that you can do it programmatically through code.To call this function from a VB application, you’ll need to write a declaration, like so:
You’ll want to place that declaration at the top of your module file, before any procedures are defined. Then, inside one of the procedures, you can call the function. For example:
Even better code would check the return value of
LockWorkStationfor an error code. A return value of 0 indicates an error. The standard way of checking for Win32 errors in VB,Err.LastDllError, will give you more information about what exactly went wrong.