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
  1. Home
  2. General Programming
  3. C#
  4. Changing Windows registry with C#

Changing Windows registry with C#

Scheduled Pinned Locked Moved C#
csharpvisual-studiowindows-adminhelpquestion
22 Posts 4 Posters 2 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.
  • I Ismael_1999

    Hi, OriginalGriff. I used the code you wrote in your article, but I received an error message. First see a snipet of my code:

        public static Guid AppGuid
        {
            get
            {
                Assembly asm = Assembly.GetEntryAssembly();
                object\[\] attr = (asm.GetCustomAttributes(typeof(GuidAttribute), true));
                return new Guid((attr\[0\] as GuidAttribute).Value);
            }
        }
    

    This is in fact your code. The error is on the line of the return: "System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'" Do you know what causes this error? Thanks.

    D Offline
    D Offline
    Dave Kreskowiak
    wrote on last edited by
    #9

    That's because your app doesn't have a GuidAttribute. Go into your project Properties, click on the Application tab, then Assembly Information button. You'll find a GUID box in the dialog that pops up. That box is empty. That's where you have to put your GUID.

    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
    Dave Kreskowiak

    OriginalGriffO 1 Reply Last reply
    0
    • D Dave Kreskowiak

      That's because your app doesn't have a GuidAttribute. Go into your project Properties, click on the Application tab, then Assembly Information button. You'll find a GUID box in the dialog that pops up. That box is empty. That's where you have to put your GUID.

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #10

      Normally, that is filled in by VS when it creates the project template. Dunno what he used to do that ... :laugh:

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      D 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Normally, that is filled in by VS when it creates the project template. Dunno what he used to do that ... :laugh:

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #11

        Under the .NET Framework projects (4.8 at least), it's filled in by the Windows Forms template, but not the WPF template. I haven't tried any of the others. On .NET Core projects, the "Assembly Information" option doesn't even exist. The assembly info is automatically generated at compile time, but is controllable in the .csproj file. I haven't spent very much time looking at this because I don't expose much to COM, so YMMV.

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
        Dave Kreskowiak

        I 1 Reply Last reply
        0
        • D Dave Kreskowiak

          Under the .NET Framework projects (4.8 at least), it's filled in by the Windows Forms template, but not the WPF template. I haven't tried any of the others. On .NET Core projects, the "Assembly Information" option doesn't even exist. The assembly info is automatically generated at compile time, but is controllable in the .csproj file. I haven't spent very much time looking at this because I don't expose much to COM, so YMMV.

          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
          Dave Kreskowiak

          I Offline
          I Offline
          Ismael_1999
          wrote on last edited by
          #12

          Hi, Dave. I tried here, but didn't get it. I use VS Community 2022 in portuguese. In my superior menu there is "Tools" and then "Create GUID". Next appears a small form with many options (1 - IMPLEMENT_OLECREATE(...) 2 - DEFINE_GUID(...) and others). Menu says I must copy and paste the chosen option in my source code. But I don't understand what I should do. Have you seen this? Can you help me? Thanks again.

          D 1 Reply Last reply
          0
          • I Ismael_1999

            Hi, Dave. I tried here, but didn't get it. I use VS Community 2022 in portuguese. In my superior menu there is "Tools" and then "Create GUID". Next appears a small form with many options (1 - IMPLEMENT_OLECREATE(...) 2 - DEFINE_GUID(...) and others). Menu says I must copy and paste the chosen option in my source code. But I don't understand what I should do. Have you seen this? Can you help me? Thanks again.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #13

            Pick Registry format, click the Copy button, then you go back into the Project Properties, ..., and paste that value into the GUID box and click OK.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            I 1 Reply Last reply
            0
            • D Dave Kreskowiak

              Pick Registry format, click the Copy button, then you go back into the Project Properties, ..., and paste that value into the GUID box and click OK.

              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
              Dave Kreskowiak

              I Offline
              I Offline
              Ismael_1999
              wrote on last edited by
              #14

              Dave. For me there is no GUID box. But I'll tell yu my original problem, and maybe you can give another tip. I'll install a desktop application for a client and need to store the instalation folder somewhere. Inicially I thougt of using windows registry, but the local available was CURRENTUSER, and I didn't like it. Then I read OriginalGriff's article and thougt of a text file anywhere I can find and the ALLUSERS folder appeared to be good for me. Then these problems arouse. Do you have any suggestion? Thanks a lot.

              D L 2 Replies Last reply
              0
              • I Ismael_1999

                Dave. For me there is no GUID box. But I'll tell yu my original problem, and maybe you can give another tip. I'll install a desktop application for a client and need to store the instalation folder somewhere. Inicially I thougt of using windows registry, but the local available was CURRENTUSER, and I didn't like it. Then I read OriginalGriff's article and thougt of a text file anywhere I can find and the ALLUSERS folder appeared to be good for me. Then these problems arouse. Do you have any suggestion? Thanks a lot.

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #15

                What type of app are you writing, which version of .NET or the .NET Framework are you writing this code against, and are you exposing any components in your app to COM?

                Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                Dave Kreskowiak

                I 1 Reply Last reply
                0
                • I Ismael_1999

                  Dave. For me there is no GUID box. But I'll tell yu my original problem, and maybe you can give another tip. I'll install a desktop application for a client and need to store the instalation folder somewhere. Inicially I thougt of using windows registry, but the local available was CURRENTUSER, and I didn't like it. Then I read OriginalGriff's article and thougt of a text file anywhere I can find and the ALLUSERS folder appeared to be good for me. Then these problems arouse. Do you have any suggestion? Thanks a lot.

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

                  You do not need to store that. You can get that info at runtime.

                  Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                  I 1 Reply Last reply
                  0
                  • L Lost User

                    You do not need to store that. You can get that info at runtime.

                    Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                    I Offline
                    I Offline
                    Ismael_1999
                    wrote on last edited by
                    #17

                    Hi, Eddy. How can I obtain the installation folder of an application? Note that I need it from another application, not the one running at this moment. Thanks.

                    L 1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      What type of app are you writing, which version of .NET or the .NET Framework are you writing this code against, and are you exposing any components in your app to COM?

                      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                      Dave Kreskowiak

                      I Offline
                      I Offline
                      Ismael_1999
                      wrote on last edited by
                      #18

                      I'm writing a program to control incomes and expenses of a small company. .NET Framework version 4.8.04084. Microsoft Visual Studio Community 2022 Version 17.2.6 Is this what you wanted?

                      D 1 Reply Last reply
                      0
                      • I Ismael_1999

                        I'm writing a program to control incomes and expenses of a small company. .NET Framework version 4.8.04084. Microsoft Visual Studio Community 2022 Version 17.2.6 Is this what you wanted?

                        D Offline
                        D Offline
                        Dave Kreskowiak
                        wrote on last edited by
                        #19

                        OK, so you're writing either a Windows Forms app, or WPF, for some accounting function. You have no reason at all to be saving anything to HKEY_LOCAL_MACHINE. Follow the advice of Griff. As for the Guid of the app, you really have no use for it so why are you interested in it?

                        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                        Dave Kreskowiak

                        I 1 Reply Last reply
                        0
                        • I Ismael_1999

                          Hi, Eddy. How can I obtain the installation folder of an application? Note that I need it from another application, not the one running at this moment. Thanks.

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

                          And it's prolly not an application that you launched, so it is a running app that you did not launch? Does the app have a windows handle? Then you can get the executables location. https://www.autohotkey.com/boards/viewtopic.php?t=69925[^]

                          Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                          1 Reply Last reply
                          0
                          • D Dave Kreskowiak

                            OK, so you're writing either a Windows Forms app, or WPF, for some accounting function. You have no reason at all to be saving anything to HKEY_LOCAL_MACHINE. Follow the advice of Griff. As for the Guid of the app, you really have no use for it so why are you interested in it?

                            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                            Dave Kreskowiak

                            I Offline
                            I Offline
                            Ismael_1999
                            wrote on last edited by
                            #21

                            Hi, Dave. I changed my approach. Now I get a special folder path and will use it to store a text file containing the installation folder of my app. The command is:

                                    string caminho = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData).ToString();
                            

                            I think it will solve my problem. Thanks for your help and interest!

                            D 1 Reply Last reply
                            0
                            • I Ismael_1999

                              Hi, Dave. I changed my approach. Now I get a special folder path and will use it to store a text file containing the installation folder of my app. The command is:

                                      string caminho = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData).ToString();
                              

                              I think it will solve my problem. Thanks for your help and interest!

                              D Offline
                              D Offline
                              Dave Kreskowiak
                              wrote on last edited by
                              #22

                              GetFolderPath always returns a string, so why are you calling .ToString() on a string?

                              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                              Dave Kreskowiak

                              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