2011-09-16 6 views
0

私は周りを回っているように見えないエラーで助けを得たいと考えていました。vb.net RegistryKey.CreateSubKeyエラーヘルプ

ちょっとした背景 - レジストリを使用する大きなウィンドウアプリケーションがあります(もともとは.NET v1.1で書かれており、v3.5にアップグレードされています)。私はそれを64ビットに準拠させようとしており、ほとんど完了しています。とにかく、レジストリ値を編集/変更するためにアプリケーションを管理するシステム管理者用に書かれた小さな.netユーティリティアプリケーションもあります。これらは暗号化されており、Regeditで変更することはできません。私が得ているエラーは、ユーティリティアプリケーションのコードです。

エラー:「指定RegistryKeyPermissionCheck値が無効であるパラメータ名:モード」

エラーがにユーティリティコードの試みはそうのような、非existantサブキーを作成するときにポップアップ表示:

Dim regKey As RegistryKey 
regKey = Registry.LocalMachine.OpenSubKey("Software\[APPLICATION]\[SUBKEY]\", True) 

If regKey Is Nothing Then 
    Dim tempKey As RegistryKey 
    tempKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True) 
    tempKey.CreateSubKey("[APPLICATION]\[SUBKEY]\") 
    tempKey.Close() 
    regKey = Registry.LocalMachine.OpenSubKey("[APPLICATION]\[SUBKEY]\", True) 
End If 

コードが...それはエラーをスローCreateSubKeyラインに当たるこのエラーを回避する方法はありますか?

ところで、このコードでは、既存のレジストリキー値に書き込み、読み取り、設定することができます。ご質問がある場合はお知らせください。ここで


スタックトレースです:

System.ArgumentException was unhandled 
Message="The specified RegistryKeyPermissionCheck value is invalid. Parameter name: mode" 
ParamName="mode" 
Source="mscorlib" 
StackTrace: 
    at Microsoft.Win32.RegistryKey.ValidateKeyMode(RegistryKeyPermissionCheck mode) 
    at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey, 
    RegistryKeyPermissionCheck permissionCheck, RegistrySecurity registrySecurity)  
    at PolarisRegistryEditor.PolarisKeys.SaveRegistryvalues(RegistryKey reg) in C:\apps 
    \Visual Studio 2008\Projects\PolarisRegistryEditor\PolarisRegistryEditor 
    \PolarisKeys.vb:line 321 
    at PolarisRegistryEditor.PolarisKeys.Save() in C:\apps\Visual Studio 2008\Projects 
    \PolarisRegistryEditor\PolarisRegistryEditor\PolarisKeys.vb:line 278  
    at PolarisRegistryEditor.Form1.btnSet_Click(Object sender, EventArgs e) in 
    C:\apps\Visual Studio 2008\Projects\PolarisRegistryEditor\PolarisRegistryEditor 
    \Form1.vb:line 36  
    at System.Windows.Forms.Control.OnClick(EventArgs e) at 
    System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at 
    System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 
    clicks) at System.Windows.Forms.Control.WndProc(Message& m) at 
    System.Windows.Forms.ButtonBase.WndProc(Message& m) at 
    System.Windows.Forms.Button.WndProc(Message& m) at 
    System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at 
    System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, 
    IntPtr wparam, IntPtr lparam) at 
    System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at 
    System.Windows.Forms.Application.ComponentManager.System.Windows. 
    Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 
    dwComponentID, Int32 reason, Int32 pvLoopData) at 
    System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 
    reason, ApplicationContext context) at 
    System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, 
    ApplicationContext context) at 
    Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() 
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase. 
    DoApplicationModel() at 
    Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase. 
    Run(String[] commandLine) at 
    PolarisRegistryEditor.My.MyApplication.Main(String[] Args) in 
    17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at 
    System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at 
    Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at 
    System.Threading.ExecutionContext.Run(ExecutionContext executionContext, 
    ContextCallback callback, Object state) at 
    System.Threading.ThreadHelper.ThreadStart() 
+0

例外のスタックトレースを送信します。 –

+0

(.NET 4、3.5の両方を使用して)コードを実行しようとしましたが、うまく機能しました。おそらく無効な文字を使用しますか?この質問を参照してください: http://stackoverflow.com/questions/1013473/what-are-the-valid-characters-for-registry-keys-and-valuenames – MichaelS

+0

@George、下の回答に私の編集を参照してください、私は別の可能な解決策を追加しました(UACに関して)。 – MichaelS

答えて

0

あなたがレジストリキーを作成するのに十分な権限を持っていないと思われるエラーから。

おそらく、あなたのコンピュータ上でのみ、管理者はレジストリの内容を変更することができます。 どちらか一方:

  1. は、キーを作成しようとする前に、スタートアップキーを設定するコードは、管理者権限、ログインしているユーザーのためのレジストリキーに
  2. 割り当て権限で実行する必要があります。

このリンクは役立つはず: http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.setaccesscontrol.aspx#Y100

編集:

あなたがレジストリに書き込むための十分な権限を持っていることを確認芸術場合は、その後、私は考えることができる最後のものはUACです。

disable the User Account Controlに連絡して問題が解決するかどうか確認してください。

+0

権限についてのご意見ありがとうございます。私は管理者としてマシンにログオンしており、コードをデバッグするときに管理者(右クリックの「管理者として実行」)としてVS2008を実行しています。しかし、私はまだエラーを取得しています。私はそれがどれほど上昇したかわからない。ジョージ –