Results 1 to 21 of 21

Thread: [RESOLVED] [2008] Writing to registry

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Resolved [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)

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2008] Writing to registry

    its in Project-->Properties-->Application-->View UAC Settings--> app.manifest

    there are instructions in the manifest file

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: [2008] Writing to registry

    Thanks =)
    Last edited by youngbucks; Jun 17th, 2008 at 10:28 AM.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    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

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] Writing to registry

    what did you edit in the manifest file?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    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>
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2008] Writing to registry

    you need this one

    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] Writing to registry

    you can also remove it totally to use virtualization.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    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.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    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.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  12. #12
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    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.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  14. #14
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2008] Writing to registry

    you want it to create one string value during installation? or as a part of your application?

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    Re: [2008] Writing to registry

    I want it to create on string value. Like this for example:
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  16. #16
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    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

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    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.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    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:
    1. Dim objSubKey As RegistryKey
    2.         Dim sException As String
    3.         Dim objParentKey As RegistryKey
    4.         Dim bAns As Boolean
    5.  
    6.  
    7.         Try
    8.  
    9.             Select Case ParentKeyHive
    10.                 Case RegistryHive.ClassesRoot
    11.                     objParentKey = Registry.ClassesRoot
    12.                 Case RegistryHive.CurrentConfig
    13.                     objParentKey = Registry.CurrentConfig
    14.                 Case RegistryHive.CurrentUser
    15.                     objParentKey = Registry.CurrentUser
    16.                 Case RegistryHive.DynData
    17.                     objParentKey = Registry.DynData
    18.                 Case RegistryHive.LocalMachine
    19.                     objParentKey = Registry.LocalMachine
    20.                 Case RegistryHive.PerformanceData
    21.                     objParentKey = Registry.PerformanceData
    22.                 Case RegistryHive.Users
    23.                     objParentKey = Registry.Users
    24.  
    25.             End Select
    26.  
    27.  
    28.             'Open
    29.             objSubKey = objParentKey.OpenSubKey(SubKeyName, True)
    30.             'create if doesn't exist
    31.             If objSubKey Is Nothing Then
    32.                 objSubKey = objParentKey.CreateSubKey(SubKeyName)
    33.             End If
    34.  
    35.  
    36.             objSubKey.SetValue(ValueName, Value)
    37.             bAns = True
    38.         Catch ex As Exception
    39.             bAns = False
    40.  
    41.         End Try
    42.  
    43.         Return True
    44.  
    45.     End Function

    I only want the simplest part of it that will create the subkey and write the string value after.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  19. #19
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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)

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Location
    Nowhere
    Posts
    427

    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.
    "Programming is like sex. One mistake and you have to support it for the rest of your life." ~Michael Sinz


    Code Snippets/Usefull Links:
    WinRAR DLL|Vista Style Form|Krypton Component Library|Windows Form Aero|Parsing XML files|Calculate File's CRC 32|Download a list of files.

  21. #21
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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
  •  



Click Here to Expand Forum to Full Width