Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

get shell folders values to vars, write shell folders values to ini file

114 views
Skip to first unread message

alexsupra

unread,
Nov 20, 2010, 11:02:14 AM11/20/10
to
:: usetools.net command shell script
:: get shell folders values to vars
:: write shell folders values to ini file
::
@echo off
::
:: CURRENT USER
set hkcushell=hkcu\software\microsoft\windows\currentversion\explorer
\shell folders
::set hkcushell=hkcu\software\microsoft\windows\currentversion\explorer
\user shell folders
for /f "tokens=3*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"Local AppData"') do set "localappdata=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"Desktop"') do set "desktop=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"Personal"') do set "mydocs=%%b"
for /f "tokens=3*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"Start Menu"') do set "startmenu=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"Programs"') do set "programs=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"Startup"') do set "startup=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"SendTo"') do set "sendto=%%b"
:: next values are simply less important
::for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"Favorites"') do set "favorites=%%b"
::for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"Cache"') do set "cache=%%b"
::for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"Cookies"') do set "cookies=%%b"
::for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"History"') do set "history=%%b"
::for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"Templates"') do set "templates=%%b"
::for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i
"Recent"') do set "recent=%%b"
set qlaunch=%appdata%\microsoft\internet explorer\quick launch
if "%1"=="-q" goto end
::
:: DEFAULT USER
set curdir=%cd%
cd /d "%homedrive%%homepath%\.."
set docs=%cd%
cd /d "%curdir%"
::for /f "tokens=2*" %%a in ('reg query "hklm\software\microsoft
\windows nt\currentversion\profilelist" /s ^|find /i
"ProfilesDirectory"') do set "docs=%%b"
for /f "tokens=2*" %%a in ('reg query "hklm\software\microsoft\windows
nt\currentversion\profilelist" /s ^|find /i "DefaultUserProfile"') do
set "defaultuserprofile=%%b"
set defaultuser=%docs%\%defaultuserprofile%
:: next values are not fetched from registry cause when values are
returned from hkud they are linked to %currentuser%
set defaultappdata=%defaultuser%\application data
set defaultlocalappdata=%defaultuser%\local settings\application data
set defaultsendto=%defaultuser%\sendto
set defaultqlaunch=%defaultappdata%\microsoft\internet explorer\quick
launch
::
:: ALL USERS
set hklmshell=hklm\software\microsoft\windows\currentversion\explorer
\shell folders
::set hklmshell=hklm\software\microsoft\windows\currentversion\explorer
\user shell folders
for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common AppData"') do set "allappdata=%%b"
for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Desktop"') do set "alldesktop=%%b"
for /f "tokens=4*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Start Menu"') do set "allstartmenu=%%b"
for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Programs"') do set "allprograms=%%b"
for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Startup"') do set "allstartup=%%b"
for /f "tokens=4*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Administrative Tools"') do set "alladmintools=%%b"
:: next values need to be tested on different systems
::for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Documents"') do set "alldocs=%%b"
::for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Favorites"') do set "allfavorites=%%b"
::
:: MAKE INI FILE
:makeini
set shellgetini=%userprofile%\shellget.ini
echo ; %~nx0 --- %date% %time% --- >"%shellgetini%"
echo [user]>>"%shellgetini%"
echo localappdata=%localappdata%>>"%shellgetini%"
echo desktop=%desktop%>>"%shellgetini%"
echo mydocs=%mydocs%>>"%shellgetini%"
echo startmenu=%startmenu%>>"%shellgetini%"
echo programs=%programs%>>"%shellgetini%"
echo startup=%startup%>>"%shellgetini%"
echo sendto=%sendto%>>"%shellgetini%"
echo qlaunch=%qlaunch%>>"%shellgetini%"
echo [default]>>"%shellgetini%"
echo docs=%docs%>>"%shellgetini%"
echo defaultuser=%defaultuser%>>"%shellgetini%"
echo defaultappdata=%defaultappdata%>>"%shellgetini%"
echo defaultlocalappdata=%defaultlocalappdata%>>"%shellgetini%"
echo defaultsendto=%defaultsendto%>>"%shellgetini%"
echo defaultqlaunch=%defaultqlaunch%>>"%shellgetini%"
echo [allusers]>>"%shellgetini%"
echo allappdata=%allappdata%>>"%shellgetini%"
echo alldesktop=%alldesktop%>>"%shellgetini%"
echo allstartmenu=%allstartmenu%>>"%shellgetini%"
echo allprograms=%allprograms%>>"%shellgetini%"
echo allstartup=%allstartup%>>"%shellgetini%"
echo alladmintools=%alladmintools%>>"%shellgetini%"
::
:end
::
:: do you have an idea how to make it better?

foxidrive

unread,
Nov 20, 2010, 9:28:02 PM11/20/10
to
On 21/11/2010 03:02, alexsupra wrote:
> :: usetools.net command shell script
> :: get shell folders values to vars
> :: write shell folders values to ini file
> ::
> @echo off
[snip]

> :end
> ::
> :: do you have an idea how to make it better?


This line needs some looking at:

programs=REG_SZ C:\Documents and Settings\USER\Start
Menu\Programs\Administrative Tools


Are you keen to make it a batch file only utility? There are some tools
around that return all sorts of data - SIW is one that has command line
switches.

System Information for Windows 2010 (build 0714a) Freeware Version

--
Regards,
Mic

alexsupra

unread,
Nov 20, 2010, 11:57:08 PM11/20/10
to

http://usetools.net/dvl/cmd/shellget.cmd

shellget.cmd is highly universal, fast and smart script-tool written
on Windows NT operating system built-in command interpreter which is
console shell (text terminal).
this code was tested thousents times on plenty of hardware
configurations range: P2/K6-2 120mb ram - P4/Xeon 4gb ram; various
form factors like pc tower/desktop, laptop, notebook, netbook, eeepc,
etc.
its made for still the most wide-spread in the world os NT 5.1 i.e.
Windows XP SP2-SP3 and can be easily adopted for the later products of
wellknown company.
this script is one piece of integrated installation, configuration and
administration toolset (i can tell more than everything about that in
detail but not this time). but it is independent, doesnt require
anything besides it self and built-in system components, cause i
specially cut it as separate module for doing rather useful thing
which is absent in cmd (maybe it sounds stupid in some extance but
there in cmd is no %localappdata% and %desktop% built-in by default,
isnt it?). it can be used for variaty of possible tasks like
installation, backup, clean-up, fix-up, etc. by the way i implemented
only the first part of features which i planned for getshell.cmd
a lot of practical experiments showed that cmd is excellent solution
for Windows service, installation, administration, system control,
etc. it runs very FAST and SAFE, very lightwait source which is ready
to run and can be modified on the go.
naturally additional tools is the second power of enviroment in case
it is configured properly. thus such multifunctional tools as NirCmd
or Comandiux and others are great for many tasks and we use them very
often in scripts. this concrete procedure of getting shell enviroment
was checked by many versions of tools combinations and finally pure
cmd is winner. but if you can show better alternative we will get the
new knoledge together. anyway.
by the way SIW is my old friend, we collect system hardware info
together via cmd script packed there http://usetools.net/softpacks/fastpack
SIW is too large utility for such task and it is not basic function,
it just can use win api, but cmd should catch faster from registry.
one more serious problem is that SIW can hang (on my practice is took
place several times on some cheap SiS mobo) and far important tasks it
is total failure. sorry, great anecdote! =)

alexsupra

unread,
Nov 21, 2010, 12:17:13 AM11/21/10
to
> together via cmd script packed therehttp://usetools.net/softpacks/fastpack

> SIW is too large utility for such task and it is not basic function,
> it just can use win api, but cmd should catch faster from registry.
> one more serious problem is that SIW can hang (on my practice is took
> place several times on some cheap SiS mobo) and far important tasks it
> is total failure. sorry, great anecdote! =)

> by the way SIW is my old friend
actually SIW was my old friend but i excluded it from package cause of
bugs, the latest was that SIW couldnt start in one directory with
pcidevs.txt and other similar hwid database files. they make it mad,
thats enadequate. (and it has limited export features, shows less
useful software tab by default that couldnt be changed, it even doesnt
allow to copy-paste info about some unknown devices and boards without
problems, offers payd version) but SIV has the real power of logging
various information about system and it uses pcidevs.txt database like
other full-featured gui and console tools.

foxidrive

unread,
Nov 21, 2010, 6:07:46 AM11/21/10
to
On 21/11/2010 13:28, foxidrive wrote:
> On 21/11/2010 03:02, alexsupra wrote:
>> :: usetools.net command shell script
>> :: get shell folders values to vars
>> :: write shell folders values to ini file
>> ::
>> @echo off
> [snip]
>> :end
>> ::
>> :: do you have an idea how to make it better?
>
>
> This line needs some looking at:
>
> programs=REG_SZ C:\Documents and Settings\USER\Start
> Menu\Programs\Administrative Tools

This is a little more robust. It uses GNUsed

@echo off
:: CURRENT USER
set
hkcushell=hkcu\software\microsoft\windows\currentversion\explorer\shell
folders

for /f "skip=3 tokens=1,* delims=|" %%a in (
'reg query "%hkcushell%" /s ^|sed "s/\x09REG_SZ\x09/|/"'
) do set "%%a=%%b"
set
pause

--
Regards,
Mic

alexsupra

unread,
Nov 21, 2010, 7:09:23 PM11/21/10
to

thank you, its very interesting code. i tested it and got such screen
output: http://i.imgur.com/yL1Ao.png
so i think that these are all currently existing enviroment variables
and their values i.e. system and users enviroment output.
i think its extremely useful cause i usually use special separate cmd
tool for this task.
did i miss smth?
and its rather sad but i havent any experience with sed.
would you mind to explain a little bit this magic for cycle with
sed?.. (if it is not very difficult for you)

foxidrive

unread,
Nov 21, 2010, 9:27:47 PM11/21/10
to
On 22/11/2010 11:09, alexsupra wrote:
> On Nov 21, 2:07 pm, foxidrive<foxidr...@gotcha.woohoo.invalid> wrote:
>> On 21/11/2010 13:28, foxidrive wrote:
>>
>>
>>
>>> On 21/11/2010 03:02, alexsupra wrote:
>>>> :: usetools.net command shell script
>>>> :: get shell folders values to vars
>>>> :: write shell folders values to ini file
>>>> ::

@echo off


:: CURRENT USER
set
hkcushell=hkcu\software\microsoft\windows\currentversion\explorer\shell
folders
for /f "skip=3 tokens=1,* delims=|" %%a in (
'reg query "%hkcushell%" /s ^|sed "s/\x09REG_SZ\x09/|/"'

) do set "zzz %%a=%%b"
set zzz
pause

The above addition will show only the variables defined, filtering for "zzz"


> thank you, its very interesting code. i tested it and got such screen
> output: http://i.imgur.com/yL1Ao.png
> so i think that these are all currently existing enviroment variables
> and their values i.e. system and users enviroment output.

Yes, it's the current environment. See above for a method to only list
the variables that are set by the code.

> i think its extremely useful cause i usually use special separate cmd
> tool for this task.
> did i miss smth?
> and its rather sad but i havent any experience with sed.
> would you mind to explain a little bit this magic for cycle with
> sed?.. (if it is not very difficult for you)

sed in the case above uses the "s/find/replace/" syntax and it replaces
TABREG_SZTAB with a pipe character | where tab is ascii character HEX 09
and is represented by \x09 in gnused.

The for in do then skips the top three lines of the registry code and
splits the rest of the lines into the "category name" and "the path"
(using the pipe character) into %%a and %%b

--
Regards,
Mic

alexsupra

unread,
Nov 22, 2010, 2:35:37 PM11/22/10
to

thank you again, i will update the script with adding of your code as
soon as possible. =)

alexsupra

unread,
Nov 25, 2010, 8:08:21 AM11/25/10
to
On Nov 22, 5:27 am, foxidrive <foxidr...@gotcha.woohoo.invalid> wrote:

:: usetools.net command shell script
:: allows to get shell folders values to vars, write shell folders
values and all enviroment vars to ini file


::
@echo off
::
:: CURRENT USER
set hkcushell=hkcu\software\microsoft\windows\currentversion\explorer
\shell folders

set hklmshell=hklm\software\microsoft\windows\currentversion\explorer
\shell folders
::set hklmshell=hklm\software\microsoft\windows\currentversion\explorer
\user shell folders


for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common AppData"') do set "allappdata=%%b"
for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Desktop"') do set "alldesktop=%%b"
for /f "tokens=4*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Start Menu"') do set "allstartmenu=%%b"
for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Programs"') do set "allprograms=%%b"
for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Startup"') do set "allstartup=%%b"
for /f "tokens=4*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Administrative Tools"') do set "alladmintools=%%b"
:: next values need to be tested on different systems
::for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Documents"') do set "alldocs=%%b"
::for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i
"Common Favorites"') do set "allfavorites=%%b"
::
:: MAKE INI FILE
:makeini
set shellgetini=%userprofile%\shellget.ini
echo ; %~nx0 --- %date% %time% --- >"%shellgetini%"

echo [shellget]>>"%shellgetini%"


for /f "skip=3 tokens=1,* delims=|" %%a in (
'reg query "%hkcushell%" /s ^|sed "s/\x09REG_SZ\x09/|/"'

) do set "%%a=%%b"
set>>"%shellgetini%"
::
::echo [shellget]>>"%shellgetini%"


::echo localappdata=%localappdata%>>"%shellgetini%"
::echo desktop=%desktop%>>"%shellgetini%"
::echo mydocs=%mydocs%>>"%shellgetini%"
::echo startmenu=%startmenu%>>"%shellgetini%"
::echo programs=%programs%>>"%shellgetini%"
::echo startup=%startup%>>"%shellgetini%"
::echo sendto=%sendto%>>"%shellgetini%"
::echo qlaunch=%qlaunch%>>"%shellgetini%"

::echo docs=%docs%>>"%shellgetini%"


::echo defaultuser=%defaultuser%>>"%shellgetini%"
::echo defaultappdata=%defaultappdata%>>"%shellgetini%"
::echo defaultlocalappdata=%defaultlocalappdata%>>"%shellgetini%"
::echo defaultsendto=%defaultsendto%>>"%shellgetini%"
::echo defaultqlaunch=%defaultqlaunch%>>"%shellgetini%"

::echo allappdata=%allappdata%>>"%shellgetini%"


::echo alldesktop=%alldesktop%>>"%shellgetini%"
::echo allstartmenu=%allstartmenu%>>"%shellgetini%"
::echo allprograms=%allprograms%>>"%shellgetini%"
::echo allstartup=%allstartup%>>"%shellgetini%"
::echo alladmintools=%alladmintools%>>"%shellgetini%"
::
:end

:: http://usetools.net/dvl/cmd/shellget.cmd
:: http://groups.google.com/group/alt.msdos.batch.nt/browse_thread/thread/f0daad06d9b89ddb
::

alexsupra

unread,
Dec 8, 2010, 3:46:34 PM12/8/10
to alt.msdos...@googlegroups.com
:: usetools.net command shell script
:: allows to get shell folders values to vars, write shell folders values and all enviroment vars to ini file
::
@echo off
title %processor_architecture%%sessionname% [%~nx0] %*
::
:: SYSTEM
:: that script was tested on Windows XP SP2/SP3 but locations of some system registry entires may differ on newer products.
:: thus there is helpful system detection code. it can be used for creation of corresponding sections for different versions of NT.
for /f "tokens=2*" %%a in ('reg query "hklm\software\microsoft\windows nt\currentversion" /v CurrentVersion') do set "nt=%%b"
for /f "tokens=2*" %%a in ('reg query "hklm\software\microsoft\windows nt\currentversion" /v CSDVersion') do set "ntsp=%%b"
for /f "tokens=3*" %%a in ('reg query "hklm\software\microsoft\windows nt\currentversion" /v ProductName') do set "ntname=%%b"
for /f "tokens=2*" %%a in ('reg query "hklm\system\currentcontrolset\control\nls\language" /s ^|find /i "InstallLanguage"') do set "ntlang=%%b"
for /f "tokens=2*" %%a in ('reg query "hklm\software\microsoft\windows nt\currentversion\winlogon" /v shell') do set "shell=%%b"
::
:: CURRENT USER
for /f "tokens=1-2 delims=\" %%a in ('%homepath%') do set "docs=%%b"

set hkcushell=hkcu\software\microsoft\windows\currentversion\explorer\shell folders
::set hkcushell=hkcu\software\microsoft\windows\currentversion\explorer\user shell folders
for /f "tokens=3*" %%a in ('reg query "%hkcushell%" /s ^|find /i "Local AppData"') do set "shell_localappdata=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i "Desktop"') do set "shell_desktop=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i "Personal"') do set "shell_mydocs=%%b"
for /f "tokens=3*" %%a in ('reg query "%hkcushell%" /s ^|find /i "Start Menu"') do set "shell_startmenu=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i "Programs"') do set "shell_programs=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i "Startup"') do set "shell_startup=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i "SendTo"') do set "shell_sendto=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i "Templates"') do set "shell_templates=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i "Recent"') do set "shell_recent=%%b"

if "%1"=="-q" goto end
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i "Favorites"') do set "ie_favorites=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i "Cache"') do set "ie_cache=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i "Cookies"') do set "ie_cookies=%%b"
for /f "tokens=2*" %%a in ('reg query "%hkcushell%" /s ^|find /i "History"') do set "ie_history=%%b"
::for /f "skip=3 tokens=1,* delims=|" %%a in (

::    'reg query "%hkcushell%" /s ^|sed "s/\x09REG_SZ\x09/|/"'
::) do set "%%a=%%b"
set shell_qlaunch=%appdata%\microsoft\internet explorer\quick launch
::
:: DEFAULT USER

for /f "tokens=2*" %%a in ('reg query "hklm\software\microsoft\windows nt\currentversion\profilelist" /s ^|find /i "DefaultUserProfile"') do set "defaultuserprofile=%%b"
set defaultuser=%docs%\%defaultuserprofile%
:: next values are not fetched from registry cause when values are returned from hkud they are linked to %currentuser% (or not? than what?)

set defaultappdata=%defaultuser%\application data
set defaultlocalappdata=%defaultuser%\local settings\application data
set defaultsendto=%defaultuser%\sendto
set defaultqlaunch=%defaultappdata%\microsoft\internet explorer\quick launch
::
:: ALL USERS
set hklmshell=hklm\software\microsoft\windows\currentversion\explorer\shell folders
::set hklmshell=hklm\software\microsoft\windows\currentversion\explorer\user shell folders
for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i "Common AppData"') do set "shell_allappdata=%%b"
for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i "Common Desktop"') do set "shell_alldesktop=%%b"
for /f "tokens=4*" %%a in ('reg query "%hklmshell%" /s ^|find /i "Common Start Menu"') do set "shell_allstartmenu=%%b"
for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i "Common Programs"') do set "shell_allprograms=%%b"
for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i "Common Startup"') do set "shell_allstartup=%%b"
for /f "tokens=4*" %%a in ('reg query "%hklmshell%" /s ^|find /i "Common Administrative Tools"') do set "shell_alladmintools=%%b"
:: next values need to be tested on different system installations
::for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i "Common Documents"') do set "shell_alldocs=%%b"
::for /f "tokens=3*" %%a in ('reg query "%hklmshell%" /s ^|find /i "Common Favorites"') do set "ie_allfavorites=%%b"
::
:: MAKE INI FILE
:makeini
if "%1"=="-n" goto end
set shellgetini=%userprofile%\shellget.ini
echo ; %~nx0 %* --- %date% %time% --- >"%shellgetini%"
echo [shellget]>>"%shellgetini%"
set shell>>"%shellgetini%"
set ie>>"%shellgetini%"
::
:end
pause
:: http://usetools.net/dvl/cmd/shellget.cmd
:: http://groups.google.com/group/alt.msdos.batch.nt/browse_thread/thread/f0daad06d9b89ddb
::

shellget.7z
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages