[code language=”powershell” title=”Powershell Code”] $signature = @’ [DllImport("user32.dll", SetLastError = true)] public static extern bool LockWorkStation(); ‘@ Add-Type -MemberDefinition $signature -Name CustomName -Namespace CustomNamespace -PassThru [CustomNamespace.CustomName]::Lockworkstation() [/code] Notes Keyword PUBLIC is a must, or else wont be able to call the native function. Unlike variables, Add-Type cant be changed once created in a powershell session. …
Continue reading “LockWorkstation using Powershell and pInvoke”