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 / C++ / MFC
  4. How to write registry after log in windows with mfc?

How to write registry after log in windows with mfc?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++windows-adminhelptutorial
9 Posts 4 Posters 0 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.
  • C Offline
    C Offline
    cedricvictor
    wrote on last edited by
    #1

    Dear all: I implement a application, when I log in windows, the application will auto start, and write registry in HKEY_CURRENT_USER, SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run. The context of registry is a wav file path. I put the wav file and the application in the same folder. My code show as below:

    HKEY hKey = HKEY_CURRENT_USER;

    TCHAR filePath[MAX_PATH];
    TCHAR dirPath[MAX_PATH];

    GetCurrentDirectory(MAX_PATH, dirPath);

    StringTruncate(filePath, dirPath, "\\Default.wav");

    //For ex: filePath may equal C:\abc\123\Default.wav, if my folder path
    //is C:\abc\123.

    WriteReg(hKey, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"), _T("Sound"), filePath);

    My question is: when I log in windows, the registry value always equal to C:\Windows\system32\Default.wav, Not my folder path. How can I write the right wav file path after windows log in? Thanks for your help, Victor.

    J D 2 Replies Last reply
    0
    • C cedricvictor

      Dear all: I implement a application, when I log in windows, the application will auto start, and write registry in HKEY_CURRENT_USER, SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run. The context of registry is a wav file path. I put the wav file and the application in the same folder. My code show as below:

      HKEY hKey = HKEY_CURRENT_USER;

      TCHAR filePath[MAX_PATH];
      TCHAR dirPath[MAX_PATH];

      GetCurrentDirectory(MAX_PATH, dirPath);

      StringTruncate(filePath, dirPath, "\\Default.wav");

      //For ex: filePath may equal C:\abc\123\Default.wav, if my folder path
      //is C:\abc\123.

      WriteReg(hKey, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"), _T("Sound"), filePath);

      My question is: when I log in windows, the registry value always equal to C:\Windows\system32\Default.wav, Not my folder path. How can I write the right wav file path after windows log in? Thanks for your help, Victor.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      Did you check that writing to the registry was successful?

      C 1 Reply Last reply
      0
      • J Jochen Arndt

        Did you check that writing to the registry was successful?

        C Offline
        C Offline
        cedricvictor
        wrote on last edited by
        #3

        Dear Jochen: I use the same code, but different condition. condition 1: windows run stable, it write the registry success with my folder. condition 2: after log in windows, it write the C:\Windows\system32 path. Thanks for your help, Victor.

        1 Reply Last reply
        0
        • C cedricvictor

          Dear all: I implement a application, when I log in windows, the application will auto start, and write registry in HKEY_CURRENT_USER, SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run. The context of registry is a wav file path. I put the wav file and the application in the same folder. My code show as below:

          HKEY hKey = HKEY_CURRENT_USER;

          TCHAR filePath[MAX_PATH];
          TCHAR dirPath[MAX_PATH];

          GetCurrentDirectory(MAX_PATH, dirPath);

          StringTruncate(filePath, dirPath, "\\Default.wav");

          //For ex: filePath may equal C:\abc\123\Default.wav, if my folder path
          //is C:\abc\123.

          WriteReg(hKey, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"), _T("Sound"), filePath);

          My question is: when I log in windows, the registry value always equal to C:\Windows\system32\Default.wav, Not my folder path. How can I write the right wav file path after windows log in? Thanks for your help, Victor.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          What is the value of filePath at the time of writing? Hint: it's not what you think it is.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          C 1 Reply Last reply
          0
          • D David Crow

            What is the value of filePath at the time of writing? Hint: it's not what you think it is.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            C Offline
            C Offline
            cedricvictor
            wrote on last edited by
            #5

            Dear David: I know the filePath equal to C:\Windows\system32. The value of registry which I write is different between log in windows and run windows stable. How can I write the same value in log in windows?

            D 1 Reply Last reply
            0
            • C cedricvictor

              Dear David: I know the filePath equal to C:\Windows\system32. The value of registry which I write is different between log in windows and run windows stable. How can I write the same value in log in windows?

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              cedricvictor wrote:

              I know the filePath equal to C:\Windows\system32.

              So then why continue to use it?

              cedricvictor wrote:

              The value of registry which I write is different between log in windows and run windows stable.

              Which has nothing to do with anything.

              cedricvictor wrote:

              How can I write the same value in log in windows?

              Why not just use:

              TCHAR filePath[MAX_PATH] = _T("C:\\abc\\123\\Default.wav");
              WriteReg(hKey, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), _T("Sound"), filePath);

              All that said, I suspect you are wanting to use ::GetModuleFileName(NULL, ...) instead.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              H 1 Reply Last reply
              0
              • D David Crow

                cedricvictor wrote:

                I know the filePath equal to C:\Windows\system32.

                So then why continue to use it?

                cedricvictor wrote:

                The value of registry which I write is different between log in windows and run windows stable.

                Which has nothing to do with anything.

                cedricvictor wrote:

                How can I write the same value in log in windows?

                Why not just use:

                TCHAR filePath[MAX_PATH] = _T("C:\\abc\\123\\Default.wav");
                WriteReg(hKey, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), _T("Sound"), filePath);

                All that said, I suspect you are wanting to use ::GetModuleFileName(NULL, ...) instead.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                H Offline
                H Offline
                Heng Xiangzhong
                wrote on last edited by
                #7

                It is right, Firstly, you should use ::GetModuleFileName(NULL, ...) to get the path of your application image, and then, get what you want by this path. If you set the path as const value, it's not convenient!

                D 1 Reply Last reply
                0
                • H Heng Xiangzhong

                  It is right, Firstly, you should use ::GetModuleFileName(NULL, ...) to get the path of your application image, and then, get what you want by this path. If you set the path as const value, it's not convenient!

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  I'm not sure why you replied to me with this (as opposed to cedricvictor), but thanks for the affirmation.

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                  H 1 Reply Last reply
                  0
                  • D David Crow

                    I'm not sure why you replied to me with this (as opposed to cedricvictor), but thanks for the affirmation.

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                    H Offline
                    H Offline
                    Heng Xiangzhong
                    wrote on last edited by
                    #9

                    Sorry, I just agree with your opinions, so I can't help myself to reply you. :laugh:

                    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