Blog Syntax Highlighter

Testing Syntax Highlighter for the blog with some random PowerShell code.
The code allow you to set a program “always on top”


# Your executable here
# $exe = "notepad"
$exe = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"

function Set-TopMost($handle) {
$FnDef = '
[DllImport("user32.dll")]
public static extern bool SetWindowPos(int hWnd, int hAfter, int x, int y, int cx, int cy, uint Flags);
';
$user32 = Add-Type -MemberDefinition $FnDef -Name 'User32' -Namespace 'Win32' -PassThru
$user32::SetWindowPos($handle, -1, 0,0,0,0, 3)
}

$pname = [System.IO.Path]::GetFileNameWithoutExtension($exe)

$p = (Get-Process $pname -ErrorAction "SilentlyContinue") | ? { $_.MainWindowHandle -ne 0 }
if ($p -eq $null) {
Write-Host "Process '$pname' not found, starting: $exe"
& $exe
Write-Host "Waiting for process '$pname'"
while ($p -eq $null) {
sleep -Milliseconds 100
$p = (Get-Process $pname -ErrorAction "SilentlyContinue") | ? { $_.MainWindowHandle -ne 0 }
}
}

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *