Tuesday, March 12, 2013

How to Find Desktop from Batch File

Sometimes it is necessary to operate with some files on desktop. It is easy to find a desktop itself :), but how to get the path to from a batch script? Here is a small bath script that might help you with this task.
ECHO chcp 1251 > 11.cmd
FOR /f "skip=4 tokens=2,*" %%i in ('reg query "HKCU\software\microsoft\windows\currentversion\explorer\shell folders" /v desktop') do ECHO set desktop=%%j >> 11.cmd
ECHO chcp 866 >> 11.cmd
CALL 11.cmd
ECHO %desktop%

As far as you can see, we retrieve the desktop location from Windows registry. The only trick is to process characters in different encodings, thus we need to create a temporary batch file.
We kindly remind that Dr.Batcher is the best program to create batch file, try it if haven't tried it yet.

No comments:

Post a Comment

Translate