Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to autostart up my vb application inside the system registry without "The specified RegistryKeyPermissionCheck value is invalid" [modified]

How to autostart up my vb application inside the system registry without "The specified RegistryKeyPermissionCheck value is invalid" [modified]

Scheduled Pinned Locked Moved Visual Basic
windows-adminsecurityhelptutorialquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vbDiggerz
    wrote on last edited by
    #1

    How to autostart up my vb application inside the system registry without "The specified RegistryKeyPermissionCheck value is invalid" i have created and experimenting a vb2005 win application which i need to auto start up when windows run.. so programmatically i have a code communicating in the system registry?? i can read from HK_LocalMachine SubKey's and KeyName and KeyValue's but then when my application attempt to create/write a KeyName with it's corresponding KeyValue?? this give an error like this: The specified RegistryKeyPermissionCheck value is invalid Parameter name: mode microsoft.win32.registrykey.validatekeymode(registrykeypermissioncheckmode) '********** here's my experiment vb code reading and creating KeyName/KeyValue in the windows start up... i've just learned this from other post... '****************** Imports System.IO Imports Microsoft.Win32 Imports System.Security.Permissions Public Class MySampleApplication Private Sub CreateKey() Dim regKey As RegistryKey Dim KeyName As String = "MySampleApplication" Dim KeyValue As String = "C:\MySampleApplicationFolder" regKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True, Security.AccessControl.RegistryRights.SetValue) If regKey.GetValue(KeyName) = Nothing Then 'if there's no KeyName yet? then create and set it's value MsgBox("No value found") regKey.SetValue(KeyName, KeyValue, RegistryValueKind.String) MsgBox("key " & KeyName & " has been created") Else 'if KeyName is already existing? then verified it KeyValue MsgBox("Value Found") If regKey.GetValue(KeyName) = KeyValue Then 'if KeyName is already existing and KeyValue is the same? DO NOTHING MsgBox("value equal") Else 'if KeyName is already existing but the KeyValue is diff from the original? then remodified to it's original path.. MsgBox("value not equal") regKey.SetValue(KeyName, KeyValue, RegistryValueKind.String) MsgBox("key " & KeyName & " value has been remodified and back to its original application path") End If End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub End Class

    L 1 Reply Last reply
    0
    • V vbDiggerz

      How to autostart up my vb application inside the system registry without "The specified RegistryKeyPermissionCheck value is invalid" i have created and experimenting a vb2005 win application which i need to auto start up when windows run.. so programmatically i have a code communicating in the system registry?? i can read from HK_LocalMachine SubKey's and KeyName and KeyValue's but then when my application attempt to create/write a KeyName with it's corresponding KeyValue?? this give an error like this: The specified RegistryKeyPermissionCheck value is invalid Parameter name: mode microsoft.win32.registrykey.validatekeymode(registrykeypermissioncheckmode) '********** here's my experiment vb code reading and creating KeyName/KeyValue in the windows start up... i've just learned this from other post... '****************** Imports System.IO Imports Microsoft.Win32 Imports System.Security.Permissions Public Class MySampleApplication Private Sub CreateKey() Dim regKey As RegistryKey Dim KeyName As String = "MySampleApplication" Dim KeyValue As String = "C:\MySampleApplicationFolder" regKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True, Security.AccessControl.RegistryRights.SetValue) If regKey.GetValue(KeyName) = Nothing Then 'if there's no KeyName yet? then create and set it's value MsgBox("No value found") regKey.SetValue(KeyName, KeyValue, RegistryValueKind.String) MsgBox("key " & KeyName & " has been created") Else 'if KeyName is already existing? then verified it KeyValue MsgBox("Value Found") If regKey.GetValue(KeyName) = KeyValue Then 'if KeyName is already existing and KeyValue is the same? DO NOTHING MsgBox("value equal") Else 'if KeyName is already existing but the KeyValue is diff from the original? then remodified to it's original path.. MsgBox("value not equal") regKey.SetValue(KeyName, KeyValue, RegistryValueKind.String) MsgBox("key " & KeyName & " value has been remodified and back to its original application path") End If End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub End Class

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Leave off the Security.AccessControl.RegistryRights.SetValue in the regKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True, Security.AccessControl.RegistryRights.SetValue) line. Please don't say it's urgent. It's a given because everyone thinks their question is urgent.

      S V 2 Replies Last reply
      0
      • L Lost User

        Leave off the Security.AccessControl.RegistryRights.SetValue in the regKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True, Security.AccessControl.RegistryRights.SetValue) line. Please don't say it's urgent. It's a given because everyone thinks their question is urgent.

        S Offline
        S Offline
        schrader fsu edu
        wrote on last edited by
        #3

        I have a question about your code. I inserted it into a project of mine (using Visual Studio 2008) and it refused to compile "until there was an 'Opening Try' statement." I've scanned your code and in fact don't find a *Try* statement. Where, in your code, did you or do you plan to place the *Try* statement? David

        V 1 Reply Last reply
        0
        • S schrader fsu edu

          I have a question about your code. I inserted it into a project of mine (using Visual Studio 2008) and it refused to compile "until there was an 'Opening Try' statement." I've scanned your code and in fact don't find a *Try* statement. Where, in your code, did you or do you plan to place the *Try* statement? David

          V Offline
          V Offline
          vbDiggerz
          wrote on last edited by
          #4

          '****i used to be put it like this example...*** '*************** Private Sub mySubFunctionName() try '****youre code statement goes here***** Catch ex As Exception MsgBox(ex.ToString) End Try End Sub

          1 Reply Last reply
          0
          • L Lost User

            Leave off the Security.AccessControl.RegistryRights.SetValue in the regKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True, Security.AccessControl.RegistryRights.SetValue) line. Please don't say it's urgent. It's a given because everyone thinks their question is urgent.

            V Offline
            V Offline
            vbDiggerz
            wrote on last edited by
            #5

            Excuse me "The JZ" thanks for the reply.. i really appreciate your effort.. :) but i've try it before, before i've post this thread.. NOTE!!!!!!!! i forgot to say that this code work good in Windows 2000!! but does not work on "XP Pro SP3" or higher like "Vista".. and i want it to work with this OS platform... you can try my code and let me know if it will work on XP Pro SP2 anybody there got a good possible solution?? regKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True) but this still gives me a security exception error like this... X| System.UnauthorizedAccessExeption: Attempted to perform an unauthorized operation. at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str) at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind value kind) but just like i've said before from the very first of my thread? my code can only read but can't write on the registry... how am i suppose to write in the registry using Microsoft.Win32??? without having security exception error... my user account is already an administrator and i already set my application as a full trust application in PROJECT PROPERTIES/SECURITY/ENABLE CLICKONCE SECURITY SETTINGS as FULL TRUST APPLICATION of my WINDOW PROJECT IDE VS2005.... '*********** please review my code******** '***********this is my real actual code a little differ in my fisrt code which i just simplified before**** Imports System.IO Imports Microsoft.Win32 Public Class myApplicationName Private Sub CreateAutoRegistryKey() Try Dim regKey As RegistryKey 'NOte: appKeyName will be look like this "myApplicationName.exe" Dim appKeyName As String = FileIO.FileSystem.GetName(Application.ExecutablePath) 'Note: then appKeyName will now look like this "myApplicationName" appKeyName = appKeyName.Remove(appKeyName.IndexOf("."), 4) regKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True) If regKey.GetValue(appKeyName) = Nothing Then MsgBox("No value found") regKey.SetValue(appKeyName, Application.ExecutablePath, RegistryValueKind.String) MsgBox("key " & appKeyName & " has been created") Else MsgBox("Value Found") If regKey.GetValue(appKeyName) = Application.ExecutablePath Then

            L 1 Reply Last reply
            0
            • V vbDiggerz

              Excuse me "The JZ" thanks for the reply.. i really appreciate your effort.. :) but i've try it before, before i've post this thread.. NOTE!!!!!!!! i forgot to say that this code work good in Windows 2000!! but does not work on "XP Pro SP3" or higher like "Vista".. and i want it to work with this OS platform... you can try my code and let me know if it will work on XP Pro SP2 anybody there got a good possible solution?? regKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True) but this still gives me a security exception error like this... X| System.UnauthorizedAccessExeption: Attempted to perform an unauthorized operation. at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str) at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind value kind) but just like i've said before from the very first of my thread? my code can only read but can't write on the registry... how am i suppose to write in the registry using Microsoft.Win32??? without having security exception error... my user account is already an administrator and i already set my application as a full trust application in PROJECT PROPERTIES/SECURITY/ENABLE CLICKONCE SECURITY SETTINGS as FULL TRUST APPLICATION of my WINDOW PROJECT IDE VS2005.... '*********** please review my code******** '***********this is my real actual code a little differ in my fisrt code which i just simplified before**** Imports System.IO Imports Microsoft.Win32 Public Class myApplicationName Private Sub CreateAutoRegistryKey() Try Dim regKey As RegistryKey 'NOte: appKeyName will be look like this "myApplicationName.exe" Dim appKeyName As String = FileIO.FileSystem.GetName(Application.ExecutablePath) 'Note: then appKeyName will now look like this "myApplicationName" appKeyName = appKeyName.Remove(appKeyName.IndexOf("."), 4) regKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True) If regKey.GetValue(appKeyName) = Nothing Then MsgBox("No value found") regKey.SetValue(appKeyName, Application.ExecutablePath, RegistryValueKind.String) MsgBox("key " & appKeyName & " has been created") Else MsgBox("Value Found") If regKey.GetValue(appKeyName) = Application.ExecutablePath Then

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Hmmm. Does your user account have permissions to write to HKEY_LOCAL_MACHINE?

              V 2 Replies Last reply
              0
              • L Lost User

                Hmmm. Does your user account have permissions to write to HKEY_LOCAL_MACHINE?

                V Offline
                V Offline
                vbDiggerz
                wrote on last edited by
                #7

                Yes! my user account is an administrators account... that's why im pretty confuse... why this can't work well.. and there's another... i forgot to say that my code, work well in Windows 2000!! but does not work on "XP Pro SP3" or higher like "Vista".. and i want it to work with this OS platform... you can try my code and let me know if it will work on XP Pro SP2 because i dont have XP Pro SP2 anymore... anybody there got a good possible solution make this work on the other OS platform?? i've already expected that my code will not work on Vista cause of its very high security features... but i wonder how to make it work in XP SP2 or neither XP SP3 which is my point of platform to run my application.. and also... Thanks to "The JZ" for giving attention in this thread.. i really appreciate a lot.. :) and im really glad if any body there will share their good idea... please???

                1 Reply Last reply
                0
                • L Lost User

                  Hmmm. Does your user account have permissions to write to HKEY_LOCAL_MACHINE?

                  V Offline
                  V Offline
                  vbDiggerz
                  wrote on last edited by
                  #8

                  Oppzzzz!!! Sorry to bother... im confuse... my user account is one of administrators account type and has no restriction.... i wonder why my application code does'nt work well until??? until i use the computer fixed/real administrator account when the OS first installed... which means??? all other administrators acount type.. dosn't really a fully administrator account??? Hey... "The JZ" thanks for the great help!!! youre a lot of help.. thanks again... :)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups