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. Default path to Desktop with vista

Default path to Desktop with vista

Scheduled Pinned Locked Moved C / C++ / MFC
workspace
7 Posts 5 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.
  • D Offline
    D Offline
    dbell07
    wrote on last edited by
    #1

    Hi everyone. I'm a newbee that's exhausted the Internet already, so I joined the forum. I'm attempting to create a file on the Desktop under the Vista environment, which is not user dependent. e.g ofstream file; file.open("c:\\%userprofile%\\Desktop\\report.txt"); if (!file){ cerr <<"Unable to open file report.txt"; exit(1); } but cannot seem to make this happen on the c drive (desktop). Thanks in advance.

    C 1 Reply Last reply
    0
    • D dbell07

      Hi everyone. I'm a newbee that's exhausted the Internet already, so I joined the forum. I'm attempting to create a file on the Desktop under the Vista environment, which is not user dependent. e.g ofstream file; file.open("c:\\%userprofile%\\Desktop\\report.txt"); if (!file){ cerr <<"Unable to open file report.txt"; exit(1); } but cannot seem to make this happen on the c drive (desktop). Thanks in advance.

      C Offline
      C Offline
      CoderGirl42
      wrote on last edited by
      #2

      You should be able to just call %userprofile%\desktop without having the c:\ at the front. if you open your command prompt and type in %userprofile% it'll then give you an error message but it will expand the %userprofile% to it's actual value. Hope that helps

      D D 3 Replies Last reply
      0
      • C CoderGirl42

        You should be able to just call %userprofile%\desktop without having the c:\ at the front. if you open your command prompt and type in %userprofile% it'll then give you an error message but it will expand the %userprofile% to it's actual value. Hope that helps

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

        CoderGirl42 wrote:

        ...but it will expand the %userprofile% to it's actual value.

        Unless it contains spaces.

        "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

        1 Reply Last reply
        0
        • C CoderGirl42

          You should be able to just call %userprofile%\desktop without having the c:\ at the front. if you open your command prompt and type in %userprofile% it'll then give you an error message but it will expand the %userprofile% to it's actual value. Hope that helps

          D Offline
          D Offline
          dbell07
          wrote on last edited by
          #4

          I see the expansion in which you are speaking of from the cmd window. However, since %userprofile% yields the msg. "...' is not recognized as an internal or external command, operable program or batch file.", I'm wondering if this is the same reason %userprofile% does not work from within my program. I'm beginning to think it's the vista platform :((

          1 Reply Last reply
          0
          • C CoderGirl42

            You should be able to just call %userprofile%\desktop without having the c:\ at the front. if you open your command prompt and type in %userprofile% it'll then give you an error message but it will expand the %userprofile% to it's actual value. Hope that helps

            D Offline
            D Offline
            dbell07
            wrote on last edited by
            #5

            Yes, I've tried various forms... e.g. without c:\ without success...

            R 1 Reply Last reply
            0
            • D dbell07

              Yes, I've tried various forms... e.g. without c:\ without success...

              R Offline
              R Offline
              Rozis
              wrote on last edited by
              #6

              Maybe stupid but if you open a DOS-window and type in SET (enter) is your userprofile there? Rozis

              S 1 Reply Last reply
              0
              • R Rozis

                Maybe stupid but if you open a DOS-window and type in SET (enter) is your userprofile there? Rozis

                S Offline
                S Offline
                Spawn Melmac
                wrote on last edited by
                #7

                Sorry to say this but I believe you are misunderstanding the use of environment variables. Apart from the fact that the string you are using is wrong ( the variable already contains the drive letter and as already pointed out may contain spaces) do you know the call you are making with apply environment variable expansion? I prefer not to leave things to chance by either calling, ExpandEnvironmentStringsForUser - "http://msdn.microsoft.com/en-us/library/bb762275(VS.85).aspx" or SHGetFolderPath - "http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx" Alan

                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