Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 550 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Windows 10 Environmental Variable for Documents folder

#1
I am looking to write a batch file that copies a file to the user's Documents folder, but I cannot find the environment variable that indicates it. I can derive the Documents folder from the user profile path, but this is unreliable since Windows can move the Documents folder to any location, by selecting the Location tab + Move in the folder properties.

Anybody know how to find the folder?
Reply

#2
I don't see a perfectly reliable way to do this in batch. I know this is outside the request but I think this vbscript will work reliably.

Option explicit
Dim objShell
Dim strPath

Set objShell = Wscript.CreateObject("Wscript.Shell")
strPath = objShell.SpecialFolders("MyDocuments")
msgbox strPath
Reply

#3
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`](

[To see links please register here]

) constants you can enumerate using the `Shell.Application` COM object. The constant for the `Documents` Library is `0x05`. Here's a PowerShell command example:

<!-- language-all: lang-js -->

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 see links please register here]

) to his desired save location, defaulting to `0x05` for Documents.
Reply

#4
There is no environment variable for this. You can, instead, look in the Windows Registry in the place where it stores the name of the Documents folder, but even that is deprecated:

@echo off
for /f "tokens=3*" %%p in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Personal') do (
set DocumentsFolder=%%p %%q
)
echo %DocumentsFolder%

Note the implicit `%%q` variable which captures the remainder of the path if there are spaces.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through