Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Lock-RemoteWorkstation
- {
- param(
- $Computername,
- $Credential
- )
- if(!(get-module taskscheduler)){Import-Module TaskScheduler}
- New-task -ComputerName $Computername -credential:$Credential |
- Add-TaskTrigger -In (New-TimeSpan -Seconds 30) |
- Add-TaskAction -Script `
- {
- $signature = @"
- [DllImport("user32.dll", SetLastError = true)]
- public static extern bool LockWorkStation();
- "@
- $LockWorkStation = Add-Type -memberDefinition $signature -name "Win32LockWorkStation" -namespace Win32Functions -passthru
- $LockWorkStation::LockWorkStation() | Out-Null
- } | Register-ScheduledTask TestTask -ComputerName $Computername -credential:$Credential
- }
- Function llm #lock Local machine
- {
- $signature = @"
- [DllImport("user32.dll", SetLastError = true)]
- public static extern bool LockWorkStation();
- "@
- $LockWorkStation = Add-Type -memberDefinition $signature -name "Win32LockWorkStation" -namespace Win32Functions -passthru
- $LockWorkStation::LockWorkStation()|Out-Null
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement