adding %userprofile% to a registry key

February 6, 2011 at 03:25:20
Specs: Windows 7 XP \vista, na
Hi all, I'm wanting to set up a batch file that alters the text in a registry key which will add the text "%userprofile%" but every time I try to run the batch, it uses the variable info and adds the current users profile into the key instead i.e. "c:\users\username\" etc. I literally want "%userprofile% to be planted in there...

any help would be greatfully received.

I am also looking into using the runonce key to start this batch back up once a specific program has been removed and the system has been restarted, it currently works, but the desktop doesn't load first. This batch has to have admin priveleges to work properly so I can't just have it in the startup folder.

Any clues?

See More: adding %userprofile% to a registry key

Report •

February 6, 2011 at 03:33:23
The percentage signs need to be doubled, I can't help with the second part....

Report •

February 6, 2011 at 03:37:31
that was very quick and very very efficient, many thanks... If I could ask, I never found my answer anywhere else, would you be able to tell me where you get your info from so I can ask less questions on here?

Report •

February 6, 2011 at 03:57:03
I just tried the doubling of the % signs. All i got was %c:\users\username% instead of %userprofile%

any further help on this?

Report •

Related Solutions

February 6, 2011 at 04:02:04
bah, I was testing that from inside a command prompt which is why it didn't work. from the batch the doubling worked fine.

many thanks

Report •

February 6, 2011 at 06:39:17
You can learn a lot from:

<command> /?

The rest is from the net and forums like this one.

Batch is full of annoying quirks that are less that obvious at first....

From the command prompt %'s need to be escaped with a caret (^%userprofile^%).

Report •

February 6, 2011 at 06:54:50
the ^ is something i've never used. I have used the /? many times but I do like to have a firm understanding of something before I start using it. The FOR /F was an utter pain for me to get around before I finally started understanding how the variables worked.


Report •

February 6, 2011 at 07:12:13

^ is pretty simple, it's the general escape character(like a backslash is in most languages). The purpose of course is so that characters(mainly "<>)^&|!") with special meaning can be used literally.

Of course batch being batch there is a catch.

If the characters are double quoted then they already are escaped so the carets will remain in the output, so you can't just blindly escape....

%' are a special case though, they must always be double inside a script, on the command line they must be escaped, if double quotes are involved the comes a catch:

rem only at the command prompt
echo %random%
echo "%random%"
echo ^%random^%
echo "^%random^%"

Ahh the joys....

I should have thought of:

echo ^"^%random^%^"

Report •

February 6, 2011 at 08:48:35
Yeah that makes sense, thanks for that.

I have a further problem though which I wouldn't mind help with, i've been trying to use the RUN / RUNONCE key to get the batch file to start after restarting.

Problem is, using the RUNONCE key, even though the batch file runs in admin mode, the desktop doesn't load until after the batch file exits.

Trying the same using just the RUN key, the batch file doesn't load at all...

Do you happen to know a work around for this?

many thanks for your time, you've been a great help today...

Report •

February 6, 2011 at 16:12:32

I haven't used RUNONCE so I'm just as much in the dark as you are.

Report •

Ask Question