Advertisement
Guest User

Untitled

a guest
Nov 14th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Lock-RemoteWorkstation
  2. {
  3. param(
  4. $Computername,
  5. $Credential
  6. )
  7.     if(!(get-module taskscheduler)){Import-Module TaskScheduler}
  8.     New-task -ComputerName $Computername -credential:$Credential |  
  9.     Add-TaskTrigger -In (New-TimeSpan -Seconds 30) |
  10.     Add-TaskAction -Script `
  11.     {  
  12.     $signature = @"  
  13.    [DllImport("user32.dll", SetLastError = true)]  
  14.    public static extern bool LockWorkStation();  
  15. "@  
  16.     $LockWorkStation = Add-Type -memberDefinition $signature -name "Win32LockWorkStation" -namespace Win32Functions -passthru  
  17.     $LockWorkStation::LockWorkStation() | Out-Null
  18.     } | Register-ScheduledTask TestTask -ComputerName $Computername -credential:$Credential
  19. }
  20.  
  21. Function llm #lock Local machine
  22. {
  23.  
  24.  $signature = @"  
  25.    [DllImport("user32.dll", SetLastError = true)]  
  26.    public static extern bool LockWorkStation();  
  27. "@  
  28.     $LockWorkStation = Add-Type -memberDefinition $signature -name "Win32LockWorkStation" -namespace Win32Functions -passthru  
  29.  
  30.     $LockWorkStation::LockWorkStation()|Out-Null
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement