qshinoの日記

Powershell関係と徒然なこと

WPF複数ページ

WPF複数ページ

題名通り、WPFでの複数ページ対応方法。

  1. 子ウインドウ
  2. NavigationWindow
  3. TabControl

用途に応じて使い分ける。

  1. 初心者向けの初期設定などの一方通行型としたい場合は、NavigationWindow。バックも可能だが、一本道だとユーザーが次に何をするか悩みにくい。

  2. ダッシュボードの様に、常に決まった初期ウインドウ上で作業し続ける事が多い場合は、子ウインドウ。モーダル、非モーダルを選べる。常にメインウインドウが存在し、安心感がある。

  3. 継続利用し、かつ、使用者が熟練する事を想定し、高い柔軟性を盛り込みたい場合はTabControl。但し、乱用すると最初にどのタブを使う必要があるのか、どのタブに欲しい機能があるのかなど、使用者が迷う可能性があり、初心者向けではないかもしれない。特に階層を深くすればするほど、迷子を量産するので、注意が必要である。とは言え、10タブx3階層とすれば、1000ページを収納でき、他に比べ圧倒的な収容力を誇る。

非同期実行 by powershell

非同期実行 by powershell

  1. RunSpace
  2. Start-Job
  3. Start-Process
  4. AppDomain
  5. 独立アプリ起動
  6. System.Diagnostics.Process

非同期中、標準入出力を制御できるもの。

  • Start-Job : receive-job
  • Start-Process: ファイル指定
  • Process: Stream

終了値を取得できるもの

  • RunSpace
  • Start-Process
  • Process

面倒ではあるが、Start-Processか、Processクラスを使用するのが最も柔軟性が高い。

簡単さを追い求めるなら、Start-jobが楽ではあるが、それでもRemove-Jobなどの後処理が必要。

最初は面倒ではあるが、ライブラリを作ってProcessクラスを使用するのも一つの手。

但し、今の所、非同期プロセスの標準出力を受け取り、WPFの様な別スレッドで使う方法が確立できておらず、もう少し調査が必要。

ProcessのDataReceivedEvent からのWPF/UIスレッドのDispatcher.BeginInvoke(Action)をPowerShellで試行した限りでは、Delegate=Actionの型が合わずにエラーとなり、未だ成功していない。手持ちの対策候補はスクリプトブロックを[action]型にキャストする程度であり、時間ができたら試行する予定。

ポートスキャンサービス

ポートスキャンサービス

外部からポートスキャンをしてくれるサービス。

Sields Up

https://www.grc.com/x/ne.dll?bh0bkyd2

参考

http://www.atmarkit.co.jp/fsecurity/rensai/securitytips/006portscan.html

AppDomain再び

AppDomain再び

PowerShellによるAppDomain制御。

ちょっと古い記事。10年前のもの。

by oising 2007/12/07 As knowledge of PowerShell increases for those new to .NET, there comes a point when people start to notice some shortcomings of the Assembly loading/unloading mechanisms of the 2.0 CLR. Namely, once you load an assembly into PowerShell to use it, you can’t unload it again. The only way to remove it from memory is to restart PowerShell. Eventually, you might read something about how Assemblies can be loaded into AppDomains, and AppDomains themselves can be unloaded. This is true, but for the most part it is not much use in PowerShell unless the Types in question where specifically designed with this in mind. For those of you who understand enough of what I’m talking about to get this far without going “huh?”, the following script will demonstrate some of the issues at hand:

Before you run this script, please disable PowerTab or any other SnapIns that may load the WinForms assembly into the current AppDomain. In short, this script creates a Form object in a child AppDomain, examines the current AppDomain for the WinForms assembly. It then attempts to manipulate the Form and again examines the current AppDomain for the WinForms assembly.

# full qualified display name to WinForms assembly   
$assembly = "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"  
  
function IsWinFormsLoaded() {   
    $loaded = [appdomain]::currentdomain.getassemblies()   
    $winforms = $loaded | ? { $_.fullname -like "system.windows*" }   
    return ($winforms -ne $null)       
}   
  
if (-not (IsWinFormsLoaded)) {   
    "Creating child AppDomain..."  
    $child = [appdomain]::Createdomain("child",$null,$null)   
  
    # create a remote instance of a WinForms Form in a child AppDomain   
    "Creating remote WinForms Form in child AppDomain... "  
    $handle = $child.CreateInstance($assembly, "System.Windows.Forms.Form")   
  
    # examine returned ObjectHandle   
    "Returned object is a {0}" -f $handle.GetType()   
    $handle | gm # dump methods   
  
    # Did WinForms get pulled into our AppDomain?   
    "Is Windows Forms loaded in this AppDomain? {0}" -f (IsWinFormsLoaded)   
  
    # attempt to manipulate remote object, so unwrap   
    "Unwrapping, examining methods..."  
    $form = $handle.Unwrap()   
    $form | gm | select -first 10   
  
    # is Windows Forms loaded now?   
    "Is Windows Forms loaded in this AppDomain? {0}" -f (IsWinFormsLoaded)   
  
} else {   
    write-warning "System.Windows.Forms is already loaded. Please disable PowerTab or other SnapIns that may load System.Windows.Forms and restart PowerShell."  
} 

Hopefully this will clear up any outstanding questions. I’ll post more information about this later, or possibly add to this post.

参考

http://www.nivot.org/post/2007/12/07/WhyAppDomainsAreNotAMagicBullet

https://msdn.microsoft.com/en-us/library/ms173140(v=vs.80).aspx

https://msdn.microsoft.com/en-us/library/ms173139(v=vs.80).aspx

Windows7 整列

Windows7ウインドウ整列

Windows7でウインドウを整列する方法。

  1. タスクバーで右クリック。
  2. ウインドウを上下に並べて表示 または、左右に並べて表示
  3. 戻す時 タスクバーで、元に戻す。

結構便利。

参考

https://www.microsoft.com/ja-jp/atlife/tips/archive/windows/tips/276.aspx