Solved

Finding My Documents

Posted on 2013-01-08
5
243 Views
Last Modified: 2013-01-09
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
Comment
Question by:tetrauk
5 Comments
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
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
 
LVL 9

Expert Comment

by:dustock
Comment Utility
This might if you want to go the route of reading the registry key
http://www.robvanderwoude.com/ntregquery.php
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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
 
LVL 1

Author Closing Comment

by:tetrauk
Comment Utility
billprew...I think I love you.
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
:-), thanks, glad that was helpful.

~bp
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now