473,799 Members | 3,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to write to registry

I am a newbie with .NET, trying to step up from VB6. I have a need to write
to and read from the registry. Config files will not be acceptable due to
their lack of security. The registry entry will have to do with the proper
registration and purchase of the program. I have the following code in my
program:

Public Sub SetRegValue(ByV al ValueName As String, ByVal TestValue As
Boolean)

Dim f As New RegistryPermiss ion(RegistryPer missionAccess.R ead Or
RegistryPermiss ionAccess.Write , "HKEY_LOCAL_MAC HINE\Software")

Application.Com monAppDataRegis try.SetValue(Va lueName, TestValue)

End Sub

I receive the following error whenever I try to run the program:
Unhandled Exception: System.Security .SecurityExcept ion: Request for the
permission of type System.Security .Permissions.Re gistryPermissio n, mscorlib,
Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9 failed.

I am an administrator on my computer, so that can't be the problem. What am
I doing wrong?
Nov 21 '05 #1
7 5517
if you just want to write strings, use the "Savesettin g" and "getsetting "
features

ex:

SaveSetting("Pr ogram", "Section", "Key", "Setting")

Dim temp as string
temp = GetSetting("Pro gram", "Section", "Key")
Nov 21 '05 #2
Vernon,

Why are you trying to set the hardware settings for a program.

Setting things in the curren user part of the registry is very easy with
VBNet.

http://msdn.microsoft.com/library/de...classtopic.asp

The only difficult thing is to find the format of the stringarray. However
you are using plain strings, so using this link you would be able to handle
your problem in my opinion.

I hope this helps,

Cor
Nov 21 '05 #3
I am not trying to set hardware settings. I need program settings for
whomever is using the machine. HKCU is different for each user. I would
have to set the program security features for each user when he accessed it
the first time. The program will be sold on the Internet, and will allow a
demo mode for thirty days. After that the program must be purchased and
registered, or it quits working. I need to store the registration data in a
secure place where it can be accessed by all users. HKLM is the proper
place for that kind of data.

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:u$******** ******@TK2MSFTN GP14.phx.gbl...
Vernon,

Why are you trying to set the hardware settings for a program.

Setting things in the curren user part of the registry is very easy with
VBNet.

http://msdn.microsoft.com/library/de...classtopic.asp
The only difficult thing is to find the format of the stringarray. However
you are using plain strings, so using this link you would be able to handle your problem in my opinion.

I hope this helps,

Cor

Nov 21 '05 #4
Savesetting and Getsetting saves everything in the VB and VBA key. Besides,
that doesn't solve my prolbem with registry permissions. That's what I need
help on.

"iwdu15" <iw****@discuss ions.microsoft. com> wrote in message
news:47******** *************** ***********@mic rosoft.com...
if you just want to write strings, use the "Savesettin g" and "getsetting "
features

ex:

SaveSetting("Pr ogram", "Section", "Key", "Setting")

Dim temp as string
temp = GetSetting("Pro gram", "Section", "Key")

Nov 21 '05 #5
As i continue to work, I find that I not only can not set permissions for
registry access, I can't set permissions for file IO. Someone please help
me with this permissions problem.

"Vernon Peppers" <pr*****@commun ity.nospam> wrote in message
news:eY******** ********@tk2msf tngp13.phx.gbl. ..
I am a newbie with .NET, trying to step up from VB6. I have a need to write to and read from the registry. Config files will not be acceptable due to
their lack of security. The registry entry will have to do with the proper registration and purchase of the program. I have the following code in my
program:

Public Sub SetRegValue(ByV al ValueName As String, ByVal TestValue As
Boolean)

Dim f As New RegistryPermiss ion(RegistryPer missionAccess.R ead Or
RegistryPermiss ionAccess.Write , "HKEY_LOCAL_MAC HINE\Software")

Application.Com monAppDataRegis try.SetValue(Va lueName, TestValue)

End Sub

I receive the following error whenever I try to run the program:
Unhandled Exception: System.Security .SecurityExcept ion: Request for the
permission of type System.Security .Permissions.Re gistryPermissio n, mscorlib, Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9 failed.
I am an administrator on my computer, so that can't be the problem. What am I doing wrong?

Nov 21 '05 #6
Vernon,
I am not trying to set hardware settings. I need program settings for
whomever is using the machine.


What do you want to protect the machine or the software. The last has to be
set in the software part from either the current or the default user. I gave
you all the information in that link how to do that, what is your problem
than.

I have the idea that you did not even look for it, do you really want help.

Cor
Nov 21 '05 #7
Hi

Based on my test, the code below will create a subkey under HKLM/Software
under the account with administrator rights.
You may have a try.
Sub Main()
Dim test9999 As RegistryKey =
Registry.LocalM achine.OpenSubK ey("SOFTWARE", True)
Dim test8888 As RegistryKey = test9999.Create SubKey("MyTest" )
test8888.SetVal ue("Test", "Hello World")
End Sub

Also the RegistryPermiss ion and FileIOPermissio n is used to control how
code access to the registry/file(known as Code Access Security).

For code access security, I think you may try to take a look at the link
below as a start.
Code Access Security
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconcodeaccess security.asp
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
20683
by: Peter Gomis | last post by:
I have encountered a situation where I am unable to remove a .NET assembly from the GAC. The message I receive is "Assembly 'assemblyname' could not be uninstalled because it is required by other applications." Although I have seen this before when trying to remove .NET assemblies that have been installed via an MSI package, I now get this message while trying to remove any assembly I've added to the GAC. Using gacutil does not work...
2
6409
by: Carlos G Benevides | last post by:
I have a ASP.Net web application that has two assemblies that run under com+. Under Windows 2000 the two assemblies are added to com+ automatically when instantiated from the web site. For this to happen we had to change the context in which asp.net runs from machine to SYSTEM by modifying the machine.config file. Under Windows 2003 no matter how asp.net is set to run as either machine or system. I get the following error: ...
0
800
by: Maciek | last post by:
Hi When I set Session state mode to StateServer (IIS 6.0; windows2003; .NET 2.0) in my application, I have recived this message: ----------------------------------------------------------------------------------------------------------------- Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a...
2
1655
by: Robert Rotstein | last post by:
I’m running an ASP.NET web service which dynamically creates a registry key, stores some values in it, then, on a subsequent call to another method in the service, attempts to delete the key. The problem is, the delete operation always fails with the error message “Cannot write to the registry key”. The program tries to create the key under HKEY_CURRENT_USER\some_name\<some GUID value>, but for some reason, it gets created instead under...
1
3464
by: Marek Murin | last post by:
Hi all, I have created vb.net user control that has to be used by vb6 form. Everything goes well with putting the vb.net user control on the VB6 form until I want to receive any event from my control. The event handler is displayed on VB6 IDE combo and you can create a sub for it as usual, but when I run the vb6 form to test it, it won't work. I have spent too much time til now with that without finding solution. Can anybody help me ?
0
755
by: bazzer | last post by:
hey, i am using visual basic.net 2003 and have an ASP.NET webform application thats accessing a microsoft access 2003 database. i kept getting the following error when i tried to run it: ERROR General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR Driver's SQLSetConnectAttr failed ERROR General error Unable to open registry key 'Temporary (volatile) Jet DSN...
0
12069
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in '/CinemaBookingSystem' Application. -------------------------------------------------------------------------------- ERROR General error Unable to open registry key 'Temporary (volatile) Jet DSN for process
2
4687
by: letibal | last post by:
Hello, I have written a windows service and created an installer for it. The service runs under the system accounts. When started, it launches a GUI. By default, the InteractiveProcess property of the service is not set (this can be checked by right-clicking on the service in the Services window (Admin tools>Services), choosing Properties, LogOn tab). In order to enable my service to launch a GUI at startup, I added the following lines...
0
1463
by: anibakore | last post by:
Hi All, I am using product.xml for vs2005 pre-requisites. I am using <RegistryCheckinside <InstallCheck>. I am trying to read one registry value of installed software. I can see it through regedit. I have logged in as administrator. But, in the log file I could see following error Unable to read registry value
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10249
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10219
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10025
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.