In our previous post, “Locking A Windows PC In C# & .NET”, we looked at how to lock a Windows PC in C#.

In this post we will look at how to do the same thing in Visual Basic.NET.

The approach, and the code, are very similar.

Imports System.Runtime.InteropServices
<DllImport("user32.dll", SetLastError:=True)>

Private Shared Function LockWorkStation() As Boolean

The invocation is the same.

LockWorkStation();

TLDR

You can call the Windows API from Visual Basic .NET, and invoke the LockWorkStation() method to lock your computer.