Instead of: set "docs=%%b"
use: call set "docs=%%b"
sample:
------------------------------------------------
@echo off
Set "RegKey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
\ProfileList"
rem Set "RegItem=ProfilesDirectory"
Set "RegItem=ProfileImagePath" & Set "strUser=Administrator"
Set strPttrn=/riec:"%strUser%" /ric:"%strUser%\.[0-9]*$"
for /f "tokens=2* delims= " %%a in (
'reg.exe query "%RegKey%" /s ^|(
find.exe /i "%RegItem%" ^|findstr.exe %strPttrn%^)'
) do Call Set "UserProfilePath=%%b"
:: test
set UserProfilePath & pause
------------------------------------------------
\Rems
>> than the result is the following
>> %docs% = %systemdrive%\docs
>> actually the path is correct but it contains not expanded variable
>
> Instead of: set "docs=%%b"
> use: call set "docs=%%b"
>
>
> sample:
> ------------------------------------------------
>
> @echo off
>
> Set "RegKey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
> \ProfileList"
> rem Set "RegItem=ProfilesDirectory"
>
> Set "RegItem=ProfileImagePath"& Set "strUser=Administrator"
>
> Set strPttrn=/riec:"%strUser%" /ric:"%strUser%\.[0-9]*$"
> for /f "tokens=2* delims= " %%a in (
> 'reg.exe query "%RegKey%" /s ^|(
> find.exe /i "%RegItem%" ^|findstr.exe %strPttrn%^)'
> ) do Call Set "UserProfilePath=%%b"
>
> :: test
> set UserProfilePath& pause
>
> ------------------------------------------------
This shows that adding a separate statement after the set command will
help. It also uses call.
@echo off
set docs=%%systemdrive%%\docs
echo %docs%
call set "docs=%docs%"
echo %docs%
pause
--
Regards,
Mic
thank you bro.
do you know is that possible somehow without using of "call". i mean
does alternative variant exist?
p.s. if it is interesting i can explain why its impossible to use
calling in many cases...
see full version of script at
http://groups.google.com/group/alt.msdos.batch.nt/browse_thread/thread/f0daad06d9b89ddb#
Just curious why you could not use CALL SET in the batch.
The batch is CALLing an *internal command*, it is not calling an
external batch here or a subroutine. The CALL does one substitution of
the variable (use CALL CALL... for multiple substitutions).
You can use "CALL SET" when Command Extensions are enabled <= is
enabled by Default.
else, use SETLOCAL ENABLEEXTENSIONS in the batch to enable it.
Command Extensions are only available on Windows machines running the
32 bit command line (cmd.exe)
Actually there is a workaround,
<...cut...>
For /f "delims=" %%* in (
'echo.%docs% ^|find "%docs:~-1%"') Do set "docs=%%*"
echo %docs% & pause
\Rems