Well, what you're asking isn't fool proof. What you're referring to is Libraries. And the problem with Libraries is that there can be more than one folder included in a Library.
However, there is a reasonable way to get what you want. Windows provides ShellSpecialFolder
constants you can enumerate using the Shell.Application
COM object. The constant for the Documents
Library is 0x05
. Here's a PowerShell command example:
powershell "(new-object -COM Shell.Application).Namespace(0x05).Self.Path"
My home computer has a 120GB SSD boot drive and a 2TB D: drive. So I have my Documents library pointing to D:\Documents
. The command above prints D:\Documents
as you'd hope it would.
If you're prefer Windows Script Host over PowerShell (as WSH is much faster), you can write a hybrid batch + JScript script to accomplish the same task.
@if (@CodeSection == @Batch) @then
@echo off & setlocal
rem // cscript re-evaluates this script with the JScript interpreter
cscript /nologo /e:JScript "%~f0"
goto :EOF
@end // end Batch / begin JScript hybrid chimera
WSH.Echo(WSH.CreateObject('Shell.Application').Namespace(0x05).Self.Path);
You might also consider letting the user browse to his desired save location, defaulting to 0x05
for Documents.