UWSCãPowerShellã«ç§»æ¤ãã¦ã¿ã
åã¯ãShortcutExecutorã使ã£ã¦ããWindowsãã¼ï¼ä½ããã«è²ã å²ãæ¯ã£ã¦ãã¾ãã
ä¾ãã°ãWin + P 㧠Poderosa ãèµ·å or ãã§ã«èµ·åãã¦ãããã¢ã¯ãã£ãï¼æ大åããããã«ãã¦ãã¾ãã
ãã¤ãã¯ãShortcutExecutor ãã UWSC ã®ã¹ã¯ãªããããããã¦ãããã§ãããUWSC ã®èµ·åãå¾®å¦ã«é ãã®ã§ãPowerShell ã«ç§»æ¤ãã¦ã¿ã¾ãããã§ããPowerShell ã®æ¹ãé ãã£ããorz
ç ´æ£ããã®ãããã£ãããªãã®ã§ãããã«ãæ®éª¸ãæ®ãã¦ããã¾ãã
UWSC çï¼ãã¤ã使ã£ã¦ãããã¤ï¼ãpoderosa.uws ã§ä¿åãã¦ãå®è¡ãã¦ãã ããã
isFound = false for i = 0 to GETALLWIN() - 1 titleName = STATUS(ALL_WIN_ID[i], ST_TITLE) ifb titleName = "Poderosa" or POS(" - Poderosa", titleName) <> 0 then CTRLWIN(ALL_WIN_ID[i], MAX) CTRLWIN(ALL_WIN_ID[i], ACTIVATE) isFound = true break endif next ifb !isFound then EXEC("C:\Program Files\Poderosa\Poderosa.exe") endif
PowerShellç
以ä¸ããpoderosa.ps1 ã¨ä¿åãã¦ãPowerShell.exe .\poderosa.ps1 ã§å®è¡ãã¦ãã ãããååã®æ¹ã¯ãPowerShellからWin32APIを呼ぶ - 潜在推力 ã§æ¸ããã¦ãããWin32 API ãå¼ã³åºãããã®é¢æ°ã§ãã
# http://d.hatena.ne.jp/ps1/20080312/1205339720 function New-PType() { [AppDomain]::CurrentDomain.DefineDynamicAssembly( (New-Object Reflection.AssemblyName 'PInvokeAssembly'), 'Run' ).DefineDynamicModule('PInvokeModule').DefineType('PInvokeType', "Public,BeforeFieldInit") } # DLLå, æ»ãå¤ã®å, ã¡ã½ããå, å¼æ°ã®å function New-PMethod([string]$dll_name, [Type]$return_type, [string]$method_name, [Type[]]$parameter_types){ $ptype = New-PType $ptype.DefineMethod( $method_name, 'Public,HideBySig,Static,PinvokeImpl', $return_type, $parameter_types ).SetCustomAttribute( (New-Object Reflection.Emit.CustomAttributeBuilder ([Runtime.InteropServices.DllImportAttribute].GetConstructor([string])), $dll_name) ) # apiã«ã¡ã³ãã¼ã追å $invoke = { for($i = 0; $i -lt $this.ParameterTypes.Length; $i++){ $args[$i] = $args[$i] -as $this.ParameterTypes[$i] } return $this.InvokeMember($this.MethodName, 'Public,Static,InvokeMethod', $null, $null, $args) } $api = $ptype.CreateType() $api = Add-Member -InputObject $api -MemberType NoteProperty -Name MethodName -Value $method_name -passthru Add-Member -InputObject $api -MemberType NoteProperty -Name ParameterTypes -Value $parameter_types Add-Member -InputObject $api -MemberType ScriptMethod -Name Invoke -Value $invoke return $api } # --------------------------------------------------------------------------------------------------- $showWindow = New-PMethod "user32.dll" ([Bool]) "ShowWindow" @([IntPtr], [Int32]) $setForegroundWindow = New-PMethod "user32.dll" ([Bool]) "SetForegroundWindow" @([IntPtr]) $SC_MINIMIZE = 61472 $SC_MAXIMIZE = 61488 $SC_RESTORE = 61728 # --------------------------------------------------------------------------------------------------- $isFound = $False foreach ($p in Get-Process) { if (($p.MainWindowTitle -eq "Poderosa") -or ($p.MainWindowTitle -like "* - Poderosa")) { $isFound = $True $b = $showWindow.Invoke($p.MainWindowHandle, $SC_MAXIMIZE) $b = $setForegroundWindow.Invoke($p.MainWindowHandle); break } } if (-! $isFound) { Invoke-Item "C:\Program Files\Poderosa\Poderosa.exe" }