Skip to content

Instantly share code, notes, and snippets.

View Benshi's full-sized avatar

OHSAWA Masashi Benshi

  • Toukei Computer, Co.,Ltd.
  • TOKYO, Japan
  • 19:23 (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 / 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 / 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 / @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 / @クライアント証明書の判定.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"

@Benshi
Benshi / 旧暦.md
Last active July 31, 2023 05:37
平成改元時の旧暦表記
  • 改元レジストリ:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\Calendars\Japanese\Eras

平成改元は 1989/01/08 (平成元年1月8日)で、
その前日は 1989/01/07 (昭和64年1月7日)

旧暦の 1989/01/07 は昭和63年11月30日で、
旧暦の 1989/02/05 は平成元年1月1日。

では、1989/07/08~1989/12/05 (旧暦では 12月1日~12月29日)は、
旧暦では昭和63年なのか、それとも平成0年なのか?

@Benshi
Benshi / @wankuma102182.md
Last active July 18, 2023 01:04
csc.exe によるコンパイル例

csc.exe によるコンパイル例

No102182 (XP さん) 2023/07/17(Mon) 13:54:23

分類:[C#]

c#をやって見ようかと思いとりあえず インターネット上にあるソースコード をcsc.exeでコンパイルしたのですが、「エントリポイントにMainメソッドが含まれていない」と出ます
投げやりですがまず動作させてみたいのでどこに
何を書けば良いのか教えてください。

パソコン WindowsXP
言語 c#2.0

@Benshi
Benshi / Example.cmd
Last active July 18, 2023 00:36
Wankuma No102182
@CD /D %~dp0
@SET CSC=%WINDIR%\Microsoft.NET\Framework\v2.0.50727\csc.exe
@REM --- .NET Fraemwork 2.0 ---
%CSC% /t:winexe /out:FormTimer.exe /m:Sample.FormTimer *.cs
REM --- .NET Compact Fraemwork 2.0 ---
REM IF "%PROCESSOR_ARCHITECTURE%" EQU "x86" (
REM SET FAP="%ProgramFiles%\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE"
REM ) ELSE (
@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 にしてコンパイルしてください。