Last-modified: 2020-07-29 (水) 16:41:13
WindowsTips/チートシート

はじめに

Windowsでbashを手軽に使いたいなどでbashを使えるようにすれば、LinuxTips/チートシートの一部を流用できます。

パッケージ(Chocolatey)

更新

Everything is expanded.Everything is shortened.
  1
  2
 
 
cup all
cup <パッケージ名>

インストール

Everything is expanded.Everything is shortened.
  1
 
choco install <パッケージ名>

強制インストール

Everything is expanded.Everything is shortened.
  1
 
choco install -f <パッケージ名>

パッケージ検索

Everything is expanded.Everything is shortened.
  1
  2
 
 
choco list
choco list <パッケージ名>

インストール済みのパッケージ一覧

Everything is expanded.Everything is shortened.
  1
 
choco list -lo

アンインストール

Everything is expanded.Everything is shortened.
  1
 
cuninst <パッケージ名>

権限

アプリ起動時の権限昇格を簡単に行う

ライセンス

プロダクトキーを差し替える

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
-
!
-
!
REM 差し替え(既にあれば上書き, この後ライセンス認証が必要)
slmgr /ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
REM ライセンス情報の確認
slmgr /dlv

エクスプローラー

任意のフォルダでコマンドプロンプトを起動

ネットワーク

相手のコンピュータ名を取得

Everything is expanded.Everything is shortened.
  1
  2
-
!
REM NetBIOSが有効な場合のみ使用可能
nbtstat -A <IP>

静的経路設定

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
-
!
 
-
!
 
 
 
REM -p:レジストリ
route -p add <IP|ネットワークアドレス> mask <サブネットマスク> <デフォルトゲートウェイ> metric <メトリック> if <インターフェイス番号(route printで確認できる)>
 
REM 例
route -p add 172.25.32.0 mask 255.255.255.0 172.25.32.254 metric 1 if 19
 
REM 削除
route delete <IP|ネットワークアドレス>

特定のポートを開いているプロセスを調査

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
-
|
|
!
 
-
!
REM 管理者権限で実行
REM findstrで絞り込めたら楽だが、結果が2行になるので使えない
REM 全出力のプロンプトを眺めるよりは、結果をファイルにリダイレクトして、エディタで検索した方が楽
netstat /ab > <結果出力先>
 
REM もしくはPID一覧を出して、PIDからプロセスを特定(結局1度で終わらないので、上の方が幾分マシ)
netstat /ao | findstr LISTENING

ホップ数(中継機器数)を取得

Everything is expanded.Everything is shortened.
  1
 
tracert <IP>

統計情報の表示

Everything is expanded.Everything is shortened.
  1
 
netstat -s

共有フォルダのマウント/アンマウント

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
 
 
 
-
!
 
net use <マウント先> <共有パス> <パスワード> /user:<ユーザー名>
net use <マウント先> /d /y
 
REM 例
net use z: \\192.168.50.2\data foo /user:bar
net use /d /y z:

指定したポートでの疎通確認

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
-
!
-
!
 
-
!
-
!
REM 要SysinternalsSuite
psping <IP>:<port>
REM 例
psping google.co.jp:80
 
REM 要Nmap
nping -tcp -p <port> <IP>
REM 例
nping -tcp -p 80 google.co.jp

TCPグローバルパラメータの取得

Everything is expanded.Everything is shortened.
  1
 
netsh int tcp show global

MTU確認/変更

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
-
!
-
|
|
!
REM 確認
netsh interface ipv4 show interfaces
REM 設定(永続)
REM 再起動までにしたい場合は、store=active を追加
REM https://technet.microsoft.com/en-us/library/cc731521(v=ws.10).aspx
netsh interface ipv4 set subinterface <interface name> mtu=<MTU値>

名前解決

Everything is expanded.Everything is shortened.
  1
  2
-
!
REM 問い合わせ
nslookup <名前|IP> <DNSサーバー(省略可能)>

DNSキャッシュのクリア

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
-
!
 
 
 
-
!
 
-
!
 
REM DNSクライアントのキャッシュクリア
ipconfig /flushdns
net stop dnscache
net start dnscache
 
REM DNSリゾルバキャッシュの内容表示
ipconfig /displaydns
 
REM Chrome のDNSキャッシュクリア
chrome://net-internals/#dns
DNS - Clear host cache

DHCPサーバーから取り直し

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
 
 
-
!
-
!
ipconfig /renew <アダプタ名(省略可能, ワイルドカードもOK)>
 
REM 例 すべてのアダプタで取り直し
ipconfig /renew
REM 例 "イーサネット"というアダプタで取り直し
ipconfig /renew イーサネット

静的ルーティングの表示

Everything is expanded.Everything is shortened.
  1
 
route print

ARPテーブルを表示

Everything is expanded.Everything is shortened.
  1
 
app -a

ARPテーブルのクリア

Everything is expanded.Everything is shortened.
  1
 
arp -d

ログイン時にネットワークドライブを接続状態にする

割り当て作成時に[サインイン時に再接続]を有効にしても、ログイン後にドライブをダブルクリックしないと接続しない場合の対処

  1. gpedit.msc
  2. [管理用テンプレート]-[システム]-[ログオン]
  3. [コンピュータ起動時とログイン時にネットワークを常に待つ]を有効にする

ファイアーウォール

ポリシー確認

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
-
!
-
!
# 全て
netsh advfirewall show allprofiles
# カレント
netsh advfirewall show currentprofile

ルール確認

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
-
|
!
-
-
# 全て
# 出力量が多いのでリダイレクトした方がよい
netsh advfirewall firewall show rule name=all verbose > <出力先>
# すべての動的なinboundルール
netsh advfirewall firewall show rule name=all dir=in type=dynamic

調査

共有ライブラリの依存関係を調べる

共有ライブラリ内のシンボル名を調べる

名前付きパイプが有効か調べる

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
-
!
-
!
-
!
REM 要SysinternalsSuite
 
REM 一覧表示
pipelist
REM 絞り込み
pipelist | findstr <名前付きパイプ名>

タスク情報の取得

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
-
!
-
!
 
-
!
 
-
!
 
-
!
REM 一覧表示
tasklist
REM 一覧表示
wmic process get Caption, Handle, HandleCount, ThreadCount, WorkingSetSize, PeakWorkingSetSize, VirtualSize, PeakVirtualSize, PageFileUsage, PeakPageFileUsage, PageFaults
 
REM 指定したDLLを使用しているプロセスの列挙
tasklist /M <DLL名>
 
REM svchostがホストしているプロセスの取得
tasklist /SVC | findstr svchost.exe
 
REM フィルタで絞り込み
tasklist /FI "<条件>"

システム情報の取得

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
-
!
-
!
-
!
-
!
-
!
-
!
-
!
-
!
-
!
-
!
-
!
-
!
REM システム情報を取得
systeminfo
REM ドライブ名一覧を取得(管理者権限)
fsutil fsinfo drives
REM 全ての接続とポート、PIDを列挙
netstat -ano
REM ユーザー、グループ一覧を取得
whoami /all
REM 現在の接続状況を表示
net use
REM 所属しているネットワーク上のPC一覧を取得
net view
REM 共有フォルダ一覧を取得
net share
REM 現在のコードページを取得
chcp
REM 製造情報を取得
wmic csproduct
REM SMBIOS上のシリアル番号を取得
wmic csproduct get identifyingnumber
REM SMBIOS上のUUIDを取得
wmic csproduct get UUID
REM マザーボードのシリアル番号を取得
wmic baseboard get serialnumber

電源

スリープを解除する可能性を調べる

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
-
!
-
!
-
!
-
!
REM 管理者権限
 
REM スリープを解除するアクティブなタイマーを列挙
powercfg /waketimers
REM スリープを解除できるデバイスを列挙
powercfg -devicequery wake_armed
REM 最後にスリープを解除したイベントを表示
powercfg -lastwake

スリープを抑止する可能性を調べる

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
-
!
-
!
REM 管理者権限
 
REM 電源要求を列挙(スリープを抑止している可能性を列挙)
powercfg /requests

セキュリティ

HDDのデータを完全に消去する

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
-
!
-
!
 
-
!
REM 3回データを上書きして復元不可能にする
cipher /w:<ドライブ名>
REM その後、精神衛生上クイックフォーマットして完了
 
 
REM 例. Iドライブを完全消去(ドライブ名の[:]を忘れると、カレントドライブの空き領域に対して実行する模様)
cipher /w:i:

ディスク

パーティションを削除する

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
-
|
|
!
 
-
!
 
-
!
 
-
!
 
REM 通常は[ディスクの管理]からGUI操作で行うほうが容易
REM Linux用のパーティションなどは上記からは消せないので、Windows上で行うならdiskpartを使う
REM Linux上でやるならfdiskやgpartedで行う
 
diskpart
REM ディスク一覧(対象のディスク番号を覚える)
list disk
select disk <ディスク番号>
REM パーティション一覧(対象のパーティション番号を覚える)
list partition
select patition <パーティション番号>
REM 削除
delete patition
exit

ファイル/フォルダ

ファイル/フォルダのコピー

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
-
|
|
!
REM /E: 空ディレクトリもコピー
REM /COPYALL: ファイル情報をすべてコピー
REM /NP: 進捗状況なし
robocopy <コピー元> <コピー先> /E /COPYALL /R:<リトライ回数(既定値1,000,000)> /W:<リトライ間隔(既定値30秒)> /NP /UNILOG:<ログ出力先>

シンボリックリンクを作成

Everything is expanded.Everything is shortened.
  1
  2
  3
-
|
!
REM /D: ディレクトリのシンボリックリンクを作成(何もつけないとファイルのシンボリックリンク)
REM シンボリックリンクなので、現時点で存在していないパスでも作成できる
mklink /D <シンボリックリンクパス> <実体のパス>

ハードリンクを作成

Everything is expanded.Everything is shortened.
  1
  2
-
!
REM /H: ハードリンクを作成
mklink /H <ハードリンクパス> <実体のパス>

証明書

自己証明書を作成(powershell)

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
-
|
|
|
!
 
 
 
 
-
!
 
 
 
 
 
 
 
 
 
# makecertで行うと、秘密鍵を含まない証明書をエクスポートするのが面倒
# (作成した証明書のフィンガープリントが取れないので、検索しなければならない)
# New-SelfSignedCertificateは、Powershell5以降でなければ使えないので、Windows7は標準では使えない
# また、Windows8標準のPowershellでは、New-SelfSignedCertificateは存在するが、NotAfterなど一部のオプションは使えない
 
$subject="[email protected]"
$expiryDate = (Get-Date).AddYears(100)
$outputFilePath=".\out.crt"
 
# -KeyExportPolicyを、ExportableEncryptedやExportableとすれば、秘密鍵をエクスポートできるようになる
$cert = New-SelfSignedCertificate `
    -Subject "${subject}" `
    -KeyAlgorithm RSA `
    -KeyLength 4096 `
    -HashAlgorithm sha256 `
    -NotAfter ${expiryDate} `
    -CertStoreLocation "Cert:\CurrentUser\My" `
    -KeyExportPolicy NonExportable `
    -Provider "Microsoft Enhanced Cryptographic Provider v1.0"
Export-Certificate -cert $cert -FilePath "${outputFilePath}"

自己証明書を作成(makecert)

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
-
|
|
!
 
 
 
 
 
 
 
 
-
!
REM 通常、パスが通っていないので、everythingで探してフルパスで使う
REM -r: 自己証明書
REM -skを消し、-peをつけると、秘密鍵をエクスポートできるようになる
"C:\Program Files (x86)\Windows Kits\10\bin\x64\makecert.exe" ^
    -n <サブジェクト> ^
    -a <署名アルゴリズム> ^
    -e <有効期限> ^
    -ss <格納先証明書ストア(Local|My)> ^
    -r ^
    -sky <キータイプ(signature|exchange)> ^
    -sk <キーコンテナ名>
 
REM 例
"C:\Program Files (x86)\Windows Kits\10\bin\x64\makecert.exe" -n "[email protected]" -a sha256 -e 12/31/2100 -ss My -r -sky exchange -sk foo

pfxファイルからX509証明書(der)の取得

Everything is expanded.Everything is shortened.
  1
 
Get-PfxCertificate -FilePath <pfxファイルパス> | Export-Certificate -FilePath <出力先ファイルパス> -Type CERT

証明書ストア

証明書ストアにアクセス

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
-
!
 
-
!
 
 
-
|
|
|
|
!
REM 個人
Get-ChildItem Cert:\CurrentUser\My\
certutil -store my
REM 信頼されたルート証明機関
Get-ChildItem Cert:\CurrentUser\AuthRoot\
certutil -store authroot
 
REM mmcで見えるが、powershellで見えない場合は
REM mmc上で[表示]-[オプション]
REM [表示する項目]-[物理証明書ストア]で、物理証明書ストアを表示し
REM 該当の証明書が物理的にどこに配置されているかを確認
REM それが、例えばローカルコンピュータの信頼されたルート証明機関なら
Get-ChildItem Cert:\LocalMachine\root\

スマートカード

情報取得

Everything is expanded.Everything is shortened.
  1
 
certutil -scinfo

証明書のインポート

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
-
!
-
!
 
-
!
REM pin入力必要
certutil -csp <プロバイダー名> -importpfx <pfxファイルパス>
REM pin入力省略
certutil -pin <PIN> -csp <プロバイダー名> -importpfx <pfxファイルパス>
 
REM 例
certutil -csp "Microsoft Base Smart Card Crypto Provider" -importpfx ".\foo.pfx"

証明書の削除

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
-
!
 
-
!
REM キーコンテナ名は、certutil -scinfoで確認できる
certutil -csp <プロバイダー名> -delkey <キーコンテナ名>
 
REM 例
certutil -csp "Microsoft Base Smart Card Crypto Provider" -delkey "owhpg324npgsu2t"

ショートカット

プログラムの実行

高DPI

高DPIに対応していないアプリでレイアウトが崩れて使い物にならない場合の回避策

検索

コマンドプロンプトから検索

Everything is expanded.Everything is shortened.
  1
  2
  3
-
|
!
REM エクスプローラーから検索するのと対して変わらないゴミ速度。両方とも使うシチュエーションはない
REM 素直にeverythingを使う
where /R <フォルダパス> <検索条件>

サービス

起動/停止

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
 
 
 
 
 
 
 
# 同期
net start <サービス名>
net stop <サービス名>
 
# 非同期
sc start <サービス名>
sc stop <サービス名>

アンインストール

Everything is expanded.Everything is shortened.
  1
  2
-
!
REM 管理者権限
sc delete <サービス名>

多言語

言語を追加する

  1. [Windowsキー]-[lang]-[Settings]-[Add a language](デフォルト言語が英語の場合)
  2. [Add a language]-<追加した言語を選択>
  3. <追加した言語をダブルクリック>-[Download and install language pack]
  4. インストール完了まで待つ
  5. 必要ならば[Move up]で優先順を変更
  6. OS再起動

bash on Ubuntu on Windows

インストール

Everything is expanded.Everything is shortened.
  1
  2
  3
-
!
 
REM ユーザー毎
 
lxrun /install

アンインストール

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
-
!
-
!
 
-
!
REM ユーザー毎
 
REM 削除
lxrun /uninstall
 
REM すべて削除
lxrun /uninstall /full

デスクトップ

タスクビュー

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
-
!
-
!
 
 
-
!
-
!
REM 仮想デスクトップ切り替え(Alt+Tabの仮想デスクトップ版)
[win]+Tab
REM 隣接する仮想デスクトップへ移動
[win]+[Ctrl]+[←]/[→]
 
 
REM 新規仮想デスクトップ作成
[win]+[Ctrl]+[D]
REM 現在の仮想デスクトップ削除
[win]+[Ctrl]+[F4]

スナップ

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
-
!
-
!
-
!
REM アクティブなウインドウを左右どちらかに寄せて上下最大化
[win]+[←]/[→]
REM アクティブなウインドウを最大化
[win]+[↑]
REM アクティブなウインドウを中央下部に表示([↓]2回で最小化)
[win]+[↓]

その他

実行ファイルの場所を調べる

Everything is expanded.Everything is shortened.
  1
 
where <実行ファイル名>

GodMode

  1. 新規フォルダを作成し、名前を"GOD.{ED7BA470-8E54-465E-825C-99712043E01C}"にする

Base64エンコード

Everything is expanded.Everything is shortened.
  1
  2
-
!
REM 本来証明書用のユーティリティなので、出力結果はよく見るPEMのヘッダー,フッターが付いているので、不要なら消す
certutil -f -encode <入力ファイルパス> <出力ファイルパス>

ホスト名取得

Everything is expanded.Everything is shortened.
  1
 
hostname

Windowsエクスペリエンスインデックス取得

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
-
!
-
!
REM 計測(管理者権限のcmdで実行)
winsat formal
REM 結果表示(管理者権限のpowershellで実行)
Get-CimInstance Win32_WinSat