Skip to content

Instantly share code, notes, and snippets.

@CannoHarito
Last active September 9, 2019 10:25
Show Gist options
  • Save CannoHarito/5637b8d793b7bcaff080605f40b8fb67 to your computer and use it in GitHub Desktop.
Save CannoHarito/5637b8d793b7bcaff080605f40b8fb67 to your computer and use it in GitHub Desktop.
画面の電源を消すC#を扱うpowershellをcmdに格納したもの。離席.batはロックしてから画面を消灯する。以下の記事を参考に https://qiita.com/sharow/items/ef78f2f5a8053f6a7a41
@rem https://qiita.com/sharow/items/ef78f2f5a8053f6a7a41
echo.(Add-Type '[return: MarshalAs(UnmanagedType.Bool)][DllImport("user32.dll",SetLastError=true,CharSet=CharSet.Auto)]public static extern bool PostMessage(uint hWnd,uint Msg,IntPtr wParam,IntPtr lParam);' -Name "PM" -PassThru -Language CSharp)::PostMessage(0xffff,0x0112,0xf170,2)|powershell/c -
powershell "$t='[DllImport(\"user32.dll\")]public static extern bool ';$p='PostMessage';$l='LockWorkStation';$c=Add-Type \"$t$p(uint h,uint M,IntPtr w,IntPtr l);$t$l();\" -Name 'PM' -PassThru -Language CSharp;$c::$l();$c::$p(0xffff,0x0112,0xf170,2)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment