|
-
Jun 17th, 2008, 09:37 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2008] Writing to registry
Ive been trying to get my application to write to the registry and no luck watsoever. I keep on getting "Access is Denied", ive tried multiple ways of writing to the registry but it seems my installer needs evelvation on vista. Is there a way to elevate my installer to run as admin?
Or is there a way to write to registry without needing elevation?
Im trying to create this key:
HKEY_LOCAL_MACHINE\SOFTWARE\*MySponsorsName*\*MyAppName*
HKEY_LOCAL_MACHINE\SOFTWARE\*MySponsorsName*\*MyAppName*\Install path (subkey)
-
Jun 17th, 2008, 09:53 AM
#2
Re: [2008] Writing to registry
its in Project-->Properties-->Application-->View UAC Settings--> app.manifest
there are instructions in the manifest file
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 17th, 2008, 09:56 AM
#3
Re: [2008] Writing to registry
Be aware that if you remove the line it tells you to remove in the app manifest to enable registry virtualization, that any settings written to HKLM, will be PER USER ACCOUNT on the PC, and not global to the system.
virtualization actually stores the values in the HKCU key, and virtualizes them for the given profile to make windows think its in HKLM. Same goes for file virtualization. The actual files sit in your user directory, even when they appear to be in program files.
-
Jun 17th, 2008, 10:00 AM
#4
Thread Starter
Hyperactive Member
Re: [2008] Writing to registry
Last edited by youngbucks; Jun 17th, 2008 at 10:28 AM.
-
Jun 17th, 2008, 10:29 AM
#5
Thread Starter
Hyperactive Member
Re: [2008] Writing to registry
Once again Its still failing to write:S
This is what im using:
Code:
'////////////////////////////////////////////////
'WRITING APP TO THE REGISTRY
'////////////////////////////////////////////////
InstallLog("Writing Game to Registry")
Dim regKey As RegistryKey
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
regKey.CreateSubKey("Pointblanc")
regKey.Close()
If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE", _
"Pointblanc", Nothing) Is Nothing Then
InstallLog("Failed to write to registry.")
Else
InstallLog("Writing to registry successfull.")
End If
-
Jun 17th, 2008, 10:30 AM
#6
Re: [2008] Writing to registry
what did you edit in the manifest file?
-
Jun 17th, 2008, 10:37 AM
#7
Thread Starter
Hyperactive Member
Re: [2008] Writing to registry
Sigh this is why i hate vista, i try this and it works fine on xp. I highlighted what i changed in red.
Code:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.
-->
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="custom" SameSite="site" />
</applicationRequestMinimum>
</security>
</trustInfo>
</asmv1:assembly>
-
Jun 17th, 2008, 10:38 AM
#8
Re: [2008] Writing to registry
you need this one
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 17th, 2008, 10:42 AM
#9
Re: [2008] Writing to registry
you can also remove it totally to use virtualization.
-
Jun 17th, 2008, 10:44 AM
#10
Thread Starter
Hyperactive Member
Re: [2008] Writing to registry
I tried that one also and still no luck. That was the first thing i put into my manifest.
Edit* Im trying to avoid having to remove that line knowing the consequences. Any other advice?
Last edited by youngbucks; Jun 17th, 2008 at 10:50 AM.
-
Jun 17th, 2008, 11:25 AM
#11
Thread Starter
Hyperactive Member
Re: [2008] Writing to registry
Ok its finally creating the subkey and now i have one last request. I need help creating a subkey that will point to the installation directory of my application.
-
Jun 17th, 2008, 11:34 AM
#12
Re: [2008] Writing to registry
are you writing this key as part of installation, or is this something your application does?
If it is your app, you can simply use Application.StartupPath to get the directory where the running exe is located. If it is during install time, I believe there is a variable that represents the install directory. I don't use MSI installers, so I am not 100% sure on that one.
-
Jun 17th, 2008, 11:36 AM
#13
Thread Starter
Hyperactive Member
Re: [2008] Writing to registry
Im making an installer for my game and i need to create a string value that will point to the installation directory so that when you go to add/remove programs you can uninstall it from there. It already created the subkey, i just want it to create one string value.
Last edited by youngbucks; Jun 17th, 2008 at 11:42 AM.
-
Jun 17th, 2008, 11:43 AM
#14
Re: [2008] Writing to registry
you want it to create one string value during installation? or as a part of your application?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 17th, 2008, 11:48 AM
#15
Thread Starter
Hyperactive Member
Re: [2008] Writing to registry
I want it to create on string value. Like this for example:
-
Jun 17th, 2008, 11:59 AM
#16
Re: [2008] Writing to registry
when do you want it to create the string value? during installation or not?
you can check if the string value exists in form load + write it if it doesn't.
if you want your installer project to write the string value, i'm not sure how you'd do that
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 17th, 2008, 12:02 PM
#17
Thread Starter
Hyperactive Member
Re: [2008] Writing to registry
I want the installer to create the string value during installation. This is how my installer works. It extracts the files it has compiled to c:\temp and copies them to c:\*MYgamename* and then it deletes the temporary files. What im trying to to is, during installation, get the installer to create a string value named "install path" that points to c:\*MyGameName* . I searched it up in google and these were my results http://www.google.ca/search?client=f...=Google+Search but i cant seem to get any of them to work.
-
Jun 17th, 2008, 01:10 PM
#18
Thread Starter
Hyperactive Member
Re: [2008] Writing to registry
I found the script i need, can someone help me write this to write the string value correctly please because im now having a migrane from this thing:
vb Code:
Dim objSubKey As RegistryKey Dim sException As String Dim objParentKey As RegistryKey Dim bAns As Boolean Try Select Case ParentKeyHive Case RegistryHive.ClassesRoot objParentKey = Registry.ClassesRoot Case RegistryHive.CurrentConfig objParentKey = Registry.CurrentConfig Case RegistryHive.CurrentUser objParentKey = Registry.CurrentUser Case RegistryHive.DynData objParentKey = Registry.DynData Case RegistryHive.LocalMachine objParentKey = Registry.LocalMachine Case RegistryHive.PerformanceData objParentKey = Registry.PerformanceData Case RegistryHive.Users objParentKey = Registry.Users End Select 'Open objSubKey = objParentKey.OpenSubKey(SubKeyName, True) 'create if doesn't exist If objSubKey Is Nothing Then objSubKey = objParentKey.CreateSubKey(SubKeyName) End If objSubKey.SetValue(ValueName, Value) bAns = True Catch ex As Exception bAns = False End Try Return True End Function
I only want the simplest part of it that will create the subkey and write the string value after.
-
Jun 17th, 2008, 01:35 PM
#19
Re: [2008] Writing to registry
Are you sure you are not going about this with a little TOO much thought?
To write a value to the key you mentioned, use this code:
Code:
Dim valueToWrite As String = "c:\program files\warrock"
'WRITE VALUE
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\Software\K2 Network\War Rock", "install path", valueToWrite)
substitue the valueToWrite variable with whatever method you use to get the given install path value. Then write it to the reg using the second line of code.
The reading the value is very similar:
Code:
'READ VALUE
Dim myValue As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\K2 Network\War Rock\", "install path", String.Empty).ToString
MessageBox.Show(myValue)
-
Jun 17th, 2008, 02:05 PM
#20
Thread Starter
Hyperactive Member
Re: [2008] Writing to registry
Thanks alot man it worked. I guess i was thinking about it too hard that the simplest solution didnt come to me.
-
Jun 17th, 2008, 02:50 PM
#21
Re: [RESOLVED] [2008] Writing to registry
The My namespace in VB provides a ton of common functionality for windows programming, all wrapped up in any easy to access library. It doesn't solve every problem, and sometimes it is easier to use standard framework classes, but when you can use the My namespace, it generally cuts down several lines of code you would have had to otherwise write.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|