Skip to content

Instantly share code, notes, and snippets.

View Benshi's full-sized avatar

OHSAWA Masashi Benshi

  • Toukei Computer, Co.,Ltd.
  • TOKYO, Japan
  • 21:00 (UTC +09:00)
  • X @Benshi_Orator
View GitHub Profile
@Benshi
Benshi / List-PartitionDetails.ps1
Last active October 2, 2025 03:46
固定ディスクのパーティション構成調査
function NullToEmpty($value) {
$s = "$value"
if ($s -eq "`0" -or $s -eq "") { return "" } else { return $s }
}
function Get-PartitionDetails {
$diskInfo = Get-Disk | Select-Object Number, PartitionStyle, MediaType, FriendlyName, SerialNumber, Manufacturer, Model, FirmwareVersion
$physical = Get-PhysicalDisk | Select-Object DeviceID, MediaType
Get-Partition | ForEach-Object {
@Benshi
Benshi / wankuma103860.md
Created September 22, 2025 03:04
[wankuma103860]DTE.Properties の引数について

No103860 (nittd さん) 2025/09/20(Sat) 10:23:25

Dim props As EnvDTE.Properties
props = DTE.Properties("FontsAndColors", "TextEditor")
Dim prop As EnvDTE.Property = props.Item("FontsAndColorsItems")
Dim clritems As EnvDTE.FontsAndColorsItems = prop.Object

これで取得は出来たのですが、この場合はTextEditorのものであって、他のものが取得できません。 DTE.Propertiesの2つの引数(String)の一覧が載っている場所、もしくは取得方法はありますでしょうか。

@Benshi
Benshi / UserForm1.frm
Last active September 7, 2025 11:35
[VBA] UIAutomation の階層を列挙する
Option Explicit
'
' Excel VBA 向けのサンプル
' 下記の参照設定が必要です
' Microsoft Scripting Runtime (scrrun.dll)
' UIAutomationClient (UIAutomationCore.dll)
'
' UserForm1 に、下記のコントロールが必要です
' CommandButton1
' OptionButton1 , OptionButton2 , OptionButton3
@Benshi
Benshi / Module1.bas
Created May 21, 2025 06:21
[VBA] collection to array
'Returning a collection as an array
' arg1: A collection to create an array from.
' arg2: [Optional] The lower bound (starting index) of the array.
Public Function ToArrayFromCollection(ByVal c As VBA.Collection, Optional baseIndex As Variant) As Variant()
Dim ary() As Variant
'ary = VBA.Array() 'If you want to always return a 0-based array
ary = Array() 'If you want to return an array that depends on the Option Base
Dim idxAry As Long
If IsMissing(baseIndex) Then
@Benshi
Benshi / HtmlDocumentHelper.bas
Created May 21, 2021 05:09
[VBA]ウィンドウから HTMLDocument オブジェクトを取得する
Option Explicit
Private Declare PtrSafe Function CLSIDFromString Lib "ole32" (ByVal pString As LongPtr, ByRef pCLSID As Currency) As Long
Private Declare PtrSafe Function RegisterWindowMessageW Lib "user32" (ByVal lpString As LongPtr) As Long
Private Declare PtrSafe Function SendMessageTimeoutW Lib "user32" (ByVal hWnd As LongPtr, ByVal msg As Long, ByVal wParam As LongPtr, ByRef lParam As LongPtr, ByVal fuFlags As Long, ByVal uTimeout As Long, ByRef lpdwResult As Long) As LongPtr
Private Declare PtrSafe Function ObjectFromLresult Lib "oleacc" (ByVal lResult As Long, ByRef riid As Currency, ByVal wParam As LongPtr, ppvObject As Any) As Long
Private Enum SMTO
NORMAL = 0
BLOCK = 1
ABORTIFHUNG = 2
@Benshi
Benshi / wankuma103223.vb
Created July 4, 2024 07:36
[VB]ハイパーリンクをクリップボードにコピー
Public Class Form1
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    ClipboardSetHyperLink(New Uri("http://bbs.wankuma.com/"), "C# と VB.NET の質問掲示板")
  End Sub
  Private Sub ClipboardSetHyperLink(url As Uri, text As String, Optional style As String = Nothing)
    Dim link = <a href=<%= url.ToString() %> style=<%= style %>><%= text %></a>
    Dim htmlLink = link.ToString()
    Dim contentsLength = New System.Text.UTF8Encoding(False).GetByteCount(htmlLink)
@Benshi
Benshi / @wankuma101896.md
Last active March 25, 2024 12:28
[C#]Edge で開かれているタブを閉じる

Visual Studio 2019 + C# で、Edge で開かれているタブを閉じるサンプル

元ネタ

  • No101896: Edgeで開かれているタブを指定の条件で閉じる
    at 2023/05/11(Thu) 17:10:21
    by 新米SE

メモ

  • (.NET Managed ではなく) COM 版の UIAutomationClient を用いたサンプルです。
  • error CS1752 が発生する場合は、ソリューション エクスプローラーで [参照]-[UIAutomationClient] を選択し、プロパティ一覧の中から 相互運用型の埋め込み を False にしてコンパイルしてください。
@Benshi
Benshi / @GDI+ を使ったJPEGファイルの作成.md
Last active November 24, 2023 07:19
[VB6] GDI+ を使ったJPEGファイルの作成
  • VB6 で、Jpeg ファイルを作成するサンプルです。少し手直しすれば Excel VBA などでも使えるはず。
  • 初版は VB初心者友の会 の、今は無き "テーマ掲示板2" に投稿したサンプルです。(2004/10/01)
  • 同じものを私の blog にも掲載していたのですが、yaplog! が 2020/01/31 にサービス終了を迎えて置き場が無くなっていたので、今回、GitHub Gist に再掲載してみました。
@Benshi
Benshi / PDF_to_GIFF.vb
Last active October 3, 2023 12:07
PDF ファイルを TIFF 画像に変換する
'NuGet で「Microsoft.Windows.SDK.Contracts」を参照しておく
Option Strict On
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Linq
Imports Windows.Data.Pdf
Public Class Form1
Private Const WICTiffEncoder As String = "0131be10-2001-4c5f-a9b0-cc88fab64ce8"
@Benshi
Benshi / @クライアント証明書の判定.md
Last active September 27, 2023 03:41
[C#] クライアント証明書の判定

certmgr.msc の「個人」にある証明書を列挙するには X509Certificate2Collection クラス を使う。
さらにそこから、個々の証明書の『目的』を得る実験的サンプル。

「クライアント認証」用の証明書を列挙するため、 X509KeyUsageExtension クラス を得るようにする。

Certificate Extensions は、X509Certificate2 オブジェクトに対して、 cert.Extensions[Oid] で得られる。
標準目的となる "Key Usage" の Oid は "2.5.29.15" で、
"Extended Key Usage" (EKU) の Oid は "2.5.29.37"