| Subject: Error trying to access registry. |
| Group: microsoft.public.vstudio.general |
| Date: 7/22/2008 2:53:34 AM |
| From: "Michel Vanderbeke" [Email Address Protection] |
Hello, When running my program on XP, everything works fine. When running it on Vista, I get an error on the following line: My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\Software\Kassasysteem\Gegevenslocatie", "Gegevenspad", IO.Path.GetDirectoryName(.FileName) & "\") The error is: System.UnauthorizedAccessException occurred Message="Toegang tot de registersleutel HKEY_LOCAL_MACHINE\Software\Kassasysteem\Gegevenslocatie is geweigerd." (Access to registry key denied) Source="mscorlib" StackTrace: bij Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str) bij Microsoft.Win32.RegistryKey.CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck, RegistrySecurity registrySecurity) bij Microsoft.Win32.RegistryKey.CreateSubKey(String subkey) bij Microsoft.Win32.Registry.SetValue(String keyName, String valueName, Object value, RegistryValueKind valueKind) bij Microsoft.VisualBasic.MyServices.RegistryProxy.SetValue(String keyName, String valueName, Object value) bij Kassasysteem.MDIKassasysteem.MDIKassasysteem_Load(Object sender, EventArgs e) in C:\Kassasysteem\MDIKassasysteem.vb:regel 175 InnerException: So it seems that I cannot acces the registry, even when I am administrator. Can someone please help me with this matter? Many thanks and greetings from Brugge (Bruges - Belgium), Michel |
| Back |
| Subject: Re: Error trying to access registry. |
| Group: microsoft.public.vstudio.general |
| Date: 7/22/2008 6:34:09 AM |
| From: Kevin [Email Address Protection] |
did you right click on your exe and do "run as administrator" ? |
| Back |
| Subject: Re: Error trying to access registry. |
| Group: microsoft.public.vstudio.general |
| Date: 7/22/2008 7:58:52 AM |
| From: "Michel Vanderbeke" [Email Address Protection] |
Hello, "Kevin" <medicalsounds@hotmail.com> schreef in bericht news:1a3ed34a-6664-46a6-9675-923283166af1@k13g2000hse.googlegroups.com... >>When running my program on XP, everything works fine. >>When running it on Vista, I get an error on the following line: >>My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\Software\Kassasysteem\Gegevenslocatie", >>"Gegevenspad", IO.Path.GetDirectoryName(.FileName) & "\") >>The error is: >>System.UnauthorizedAccessException occurred >> Message="Toegang tot de registersleutel >>HKEY_LOCAL_MACHINE\Software\Kassasysteem\Gegevenslocatie is geweigerd." >>(Access to registry key denied) >> Source="mscorlib" >> StackTrace: >> bij Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String >>str) >> bij Microsoft.Win32.RegistryKey.CreateSubKey(String subkey, >>RegistryKeyPermissionCheck permissionCheck, RegistrySecurity >>registrySecurity) >> bij Microsoft.Win32.RegistryKey.CreateSubKey(String subkey) >> bij Microsoft.Win32.Registry.SetValue(String keyName, String >>valueName, Object value, RegistryValueKind valueKind) >> bij Microsoft.VisualBasic.MyServices.RegistryProxy.SetValue(String >>keyName, String valueName, Object value) >> bij Kassasysteem.MDIKassasysteem.MDIKassasysteem_Load(Object >> sender, >>EventArgs e) in C:\Kassasysteem\MDIKassasysteem.vb:regel 175 >> InnerException: >>So it seems that I cannot acces the registry, even when I am >>administrator. >>Can someone please help me with this matter? > did you right click on your exe and do "run as administrator" ? Thank you for responding. The error does occur when I start my program in Visual Studio. It has not been distributed yet and is still in programming phase. What can I do to avoid this error? Many thanks and greetings, Michel |
| Back |
| Subject: Re: Error trying to access registry. |
| Group: microsoft.public.vstudio.general |
| Date: 7/22/2008 8:12:27 AM |
| From: David Wilkinson [Email Address Protection] |
Michel Vanderbeke wrote: > Thank you for responding. > The error does occur when I start my program in Visual Studio. It has > not been distributed yet and is still in programming phase. > > What can I do to avoid this error? Michel: Don't let your program write to program Files or to the HKLM registry. You should not have been doing this in XP either. On XP, your program will not run as a standard user (it only worked for an administrator). -- David Wilkinson Visual C++ MVP |
| Back |
| Subject: Re: Error trying to access registry. |
| Group: microsoft.public.vstudio.general |
| Date: 7/22/2008 9:02:29 AM |
| From: "Michel Vanderbeke" [Email Address Protection] |
----- Original Message ----- From: "David Wilkinson" <no-reply@effisols.com> Newsgroups: microsoft.public.vstudio.general Sent: Tuesday, July 22, 2008 5:12 PM Subject: Re: Error trying to access registry. > Michel Vanderbeke wrote: >> Thank you for responding. >> The error does occur when I start my program in Visual Studio. It has >> not been distributed yet and is still in programming phase. >> >> What can I do to avoid this error? > > Michel: > > Don't let your program write to program Files or to the HKLM registry. You > should not have been doing this in XP either. On XP, your program will not > run as a standard user (it only worked for an administrator). > > -- > David Wilkinson > Visual C++ MVP Can you please inform me about an alternative? I want to save some settings like the location where the program is used, the amount of articles to be dispalyed on screen, etc. ... These are not the same for every PC that is running the program. Many thanks and greetings from Brugge (Bruges - Belgium), Michel |
| Back |
| Subject: Re: Error trying to access registry. |
| Group: microsoft.public.vstudio.general |
| Date: 7/22/2008 9:52:52 AM |
| From: David Wilkinson [Email Address Protection] |
Michel Vanderbeke wrote: > Can you please inform me about an alternative? I want to save some settings > like the location where the program is used, the amount of articles to be > dispalyed on screen, etc. ... > These are not the same for every PC that is running the program. Michel: Normally such settings are per-user, and so should be saved in the HKCU registry. Any user can write to the HKCU registry. It is almost always a mistake for a program to write to HKLM. Only Setup programs should write to HKLM. -- David Wilkinson Visual C++ MVP |
| Back |
| Subject: Re: Error trying to access registry. |
| Group: microsoft.public.vstudio.general |
| Date: 7/22/2008 10:57:55 AM |
| From: "Michel Vanderbeke" [Email Address Protection] |
Hello, "David Wilkinson" <no-reply@effisols.com> schreef in bericht news:%23IZSjtB7IHA.1204@TK2MSFTNGP04.phx.gbl... > Michel Vanderbeke wrote: >> Can you please inform me about an alternative? I want to save some >> settings >> like the location where the program is used, the amount of articles to be >> dispalyed on screen, etc. ... >> These are not the same for every PC that is running the program. > Normally such settings are per-user, and so should be saved in the HKCU > registry. Any user can write to the HKCU registry. > > It is almost always a mistake for a program to write to HKLM. Only Setup > programs should write to HKLM. Then my question still stays: There are a few items that need to be set after setup, like the location of the database, the location where the program is running and a few other items. These settings are all the same for all users on a particular location, but can be different for every location. Where can I put those settings? They need only to be set once after the program is installed on every computer. Many thanks and greetings, Michel |
| Back |
| Subject: Re: Error trying to access registry. |
| Group: microsoft.public.vstudio.general |
| Date: 7/22/2008 11:15:16 AM |
| From: David Wilkinson [Email Address Protection] |
Michel Vanderbeke wrote: > Then my question still stays: There are a few items that need to be set > after setup, like the location of the database, the location where the > program is running and a few other items. > These settings are all the same for all users on a particular location, > but can be different for every location. > Where can I put those settings? > They need only to be set once after the program is installed on every > computer. Michel: 1. Why can the setup program not make these entries? 2. If not possible, would it be a disaster if each user had a copy of these items in HKCU? Why is your program different from any other? -- David Wilkinson Visual C++ MVP |
| Back |
| Subject: Re: Error trying to access registry. |
| Group: microsoft.public.vstudio.general |
| Date: 7/22/2008 11:16:31 AM |
| From: David Lowndes [Email Address Protection] |
>Then my question still stays: There are a few items that need to be set >after setup, like the location of the database, the location where the >program is running and a few other items. In that case you probably need to have a separate exe that's has just that functionality. It will need to be marked to explicitly run elevated so that (under Vista) it automatically prompts. Dave |
| Back |
| Subject: Re: Error trying to access registry. |
| Group: microsoft.public.vstudio.general |
| Date: 7/22/2008 11:32:08 AM |
| From: "Mark Salsbery [MVP]" [Email Address Protection] |
"Michel Vanderbeke" <michel.vanderbeke@skynet.be> wrote in message news:48861fa9$0$2864$ba620e4c@news.skynet.be... > Hello, > > "David Wilkinson" <no-reply@effisols.com> schreef in bericht > news:%23IZSjtB7IHA.1204@TK2MSFTNGP04.phx.gbl... >> Michel Vanderbeke wrote: >>> Can you please inform me about an alternative? I want to save some >>> settings >>> like the location where the program is used, the amount of articles to >>> be >>> dispalyed on screen, etc. ... >>> These are not the same for every PC that is running the program. > >> Normally such settings are per-user, and so should be saved in the HKCU >> registry. Any user can write to the HKCU registry. >> >> It is almost always a mistake for a program to write to HKLM. Only Setup >> programs should write to HKLM. > > Then my question still stays: There are a few items that need to be set > after setup, like the location of the database, the location where the > program is running and a few other items. > These settings are all the same for all users on a particular location, > but can be different for every location. > Where can I put those settings? The recommended place for this type of application data is in a folder %ProgramData%\Company\Product\Version\ where %ProgramData% is obtained from the OS, e.g. using SHGetKnownFolderPath(FOLDERID_ProgramData). Your app's installer should create the %ProgramData%\Company\Product\Version folder and give it the appropriate access permissions. I personally use XML configuration files stored there. Mark -- Mark Salsbery Microsoft MVP - Visual C++ > They need only to be set once after the program is installed on every > computer. > > Many thanks and greetings, > > Michel > > |
| Back |