# specify your command name $ContextCommand = "Open Script with Notepad" # specify the command to execute. "%1" represents the file path to your # PowerShell script $command = 'notepad "%1"'
FunctionLock-Screen { [CmdletBinding()] param ( # number of seconds to lock [int] $LockSeconds = 10,
# message shown. Use {0} to insert remaining seconds # do not use {0} for a static message [string] $Title = 'wait for {0} more seconds...',
# dim screen [Switch] $DimScreen )
# when run without administrator privileges, the keyboard will not be blocked!
# get access to API functions that block user input # blocking of keyboard input requires admin privileges $code = @' [DllImport("user32.dll")] public static extern int ShowCursor(bool bShow); [DllImport("user32.dll")] public static extern bool BlockInput(bool fBlockIt); '@
#requires -RunAsAdministrator # when run without administrator privileges, the keyboard will not be blocked!
# get access to API functions that block user input # blocking of keyboard input requires administrator privileges $code = @' [DllImport("user32.dll")] public static extern bool BlockInput(bool fBlockIt); '@
# create a new shortcut $shell = New-Object-ComObject WScript.Shell $scut = $shell.CreateShortcut($shortcutPath) # launch the script with powershell.exe: $scut.TargetPath = "powershell.exe" # skip profile scripts and enable execution policy for this one call # IMPORTANT: specify only the script file name, not the complete path $scut.Arguments = "-noprofile -executionpolicy bypass -file ""$filename""" # IMPORTANT: leave the working directory empty. This way, the # shortcut uses relative paths $scut.WorkingDirectory = "" # optinally specify a nice icon $scut.IconLocation = "$env:windir\system32\shell32.dll,162" # save shortcut file $scut.Save()
# open shortcut file in File Explorer explorer.exe "/select,$shortcutPath"