• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

Finding My Documents

How do I find the path to users my documents and use that in a bat file?

The users have the my documents folder in different locations, some on the local machine, some held in offline files on a server that hasn't been around for a long while, some in their profile path of the roaming profile and very few in the correct location on the server.

Now I know the my documents folder location is specified in the registry in
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders

But how do I get and use this value in a bat file to sort out all these users?

Regards
0
tetrauk
Asked:
tetrauk
1 Solution
 
pony10usCommented:
Is this for a domain or local account?  I would start by looking at the environment variable %HOMEPATH% and checking the Documents folder there.  

dir %homepath%\Documents
0
 
dustockCommented:
This might if you want to go the route of reading the registry key
http://www.robvanderwoude.com/ntregquery.php
0
 
Bill PrewCommented:
Here's a small example of getting that value from the registry and placing in in a variable. Then you can use the variable as needed.

@echo off
setlocal

REM Define constants
set Key=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
set Value=Personal

REM Query the registry for the key and value we need
for /F "tokens=2*" %%A in ('reg query "%Key%" /V "%Value%" 2^>nul ^|find /I "REG_"') do call set MyDir=%%~B
ECHO "%MyDir%"

Open in new window

~bp
0
 
tetraukAuthor Commented:
billprew...I think I love you.
0
 
Bill PrewCommented:
:-), thanks, glad that was helpful.

~bp
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now