0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

HKEY_CLASS_ROOT や HKEY_CURRENT_USER へ書き込みできない対処例 (.NET Framework)

Last updated at Posted at 2020-10-05

はじめに

現在のユーザーで書き込み権限はあるはずのレジストリへ、Microsoft.Win32.Registry 系統のレジストリ操作で書き込み失敗した場合の確認事項です。
CreateSubKey も同様)

次のようなコードで System.UnauthorizedAccessException 例外が発生してしまう場合...

sample.cs
Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("*\\shell\\test").SetValue(null, "自作アプリで開く");

解決例

次のとおり OpenSubKey メソッドの第二引数に true を指定します。

sample.cs
Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("*\\shell\\test", true).SetValue(null, "自作アプリで開く");

OpenSubKey(String) は「サブキーを読み取り専用で取得します」でした。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?