# 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"
PS C:\> Split-File-Path'C:\movies\Woman tries putting gas in a Tesla.mp4'-PartSizeBytes10MB -AddSelfExtractor-Verbose VERBOSE: saving to C:\users\tobwe\Downloads\Woman tries putting gas in a Tesla.mp4.0.part... VERBOSE: saving to C:\users\tobwe\Downloads\Woman tries putting gas in a Tesla.mp4.1.part... VERBOSE: saving to C:\users\tobwe\Downloads\Woman tries putting gas in a Tesla.mp4.2.part... VERBOSE: Adding extractor scripts...
Mode LastWriteTime Length Name --------------------------- -a----03.03.201918:112004 Extract Woman tries putting gas in a Tesla.mp4.lnk -a----03.03.201916:5424081750 Woman tries putting gas in a Tesla.mp4 -a----03.03.201918:1110485760 Woman tries putting gas in a Tesla.mp4.0.part -a----03.03.201918:1110485760 Woman tries putting gas in a Tesla.mp4.1.part -a----03.03.201918:113110230 Woman tries putting gas in a Tesla.mp4.2.part -a----03.03.201918:113179 Woman tries putting gas in a Tesla.mp4.3.part.ps1
PS> Join-File-Path'C:\users\tobwe\Downloads\Woman tries putting gas in a Tesla.mp4'-Verbose-DeletePartFiles VERBOSE: processing C:\users\tobwe\Downloads\Woman tries putting gas in a Tesla.mp4.0.part... VERBOSE: processing C:\users\tobwe\Downloads\Woman tries putting gas in a Tesla.mp4.1.part... VERBOSE: processing C:\users\tobwe\Downloads\Woman tries putting gas in a Tesla.mp4.2.part... VERBOSE: Deleting part files...
Mode LastWriteTime Length Name --------------------------- -a----03.03.201916:256291456 Woman tries putting gas in a Tesla.mp4.00.part -a----03.03.201916:256291456 Woman tries putting gas in a Tesla.mp4.01.part -a----03.03.201916:256291456 Woman tries putting gas in a Tesla.mp4.02.part -a----03.03.201916:255207382 Woman tries putting gas in a Tesla.mp4.03.part
PS C:\> Join-File-Path"C:\Users\tobwe\Downloads\Woman tries putting gas in a Tesla.mp4"-DeletePartFiles-Verbose VERBOSE: processing C:\Users\tobwe\Downloads\Woman tries putting gas in a Tesla.mp4.00.part... VERBOSE: processing C:\Users\tobwe\Downloads\Woman tries putting gas in a Tesla.mp4.01.part... VERBOSE: processing C:\Users\tobwe\Downloads\Woman tries putting gas in a Tesla.mp4.02.part... VERBOSE: processing C:\Users\tobwe\Downloads\Woman tries putting gas in a Tesla.mp4.03.part... VERBOSE: Deleting part files...
try { # get the file parts $files = Get-ChildItem-Path"$Path.*.part" | # sort by part Sort-Object-Property { # get the part number which is the "extension" of the # file name without extension $baseName = [IO.Path]::GetFileNameWithoutExtension($_.Name) $part = [IO.Path]::GetExtension($baseName) if ($part-ne$null-and$part-ne'') { $part = $part.Substring(1) } [int]$part } # append part content to file $writer = [IO.File]::OpenWrite($Path) $files | ForEach-Object { Write-Verbose"processing $_..." $bytes = [IO.File]::ReadAllBytes($_) $writer.Write($bytes, 0, $bytes.Length) } $writer.Close()
if ($DeletePartFiles) { Write-Verbose"Deleting part files..." $files | Remove-Item } } catch { throw"Unable to join part files: $_" } }