I check first for the share name and when i find one i pass it to the function :ShareLocation that use a for command to retrive the location and set it to a variable name, and the problem is in this function, it doesn't work

This is the code:
Code: Select all
@ECHO OFF
REM =====[ Shared Resources ]========================================
::
:: Check for any existence of a shared folders in the system.
:: We do nothing if shared resources was not found.
Echo.
Echo [+] Scanning Shared Resources.
SETLOCAL EnableDelayedExpansion
FOR /F "skip=1 tokens=* delims=" %%A IN ('WMIC SHARE GET Name') DO (
SET "ShareName=%%A"
REM the following two if commands is for if sharname doesn't contain IPC$ in it and if wasn't empty
IF "!ShareName:~0,3!" NEQ "IPC" (
IF /I "!Sharename!" NEQ "" (
Echo.
Echo Shared Resources :
Echo * Share-Name: !ShareName!
Call :ShareLocation "!ShareName!" "ShareLocation"
Echo * Share-Location: !ShareLocation!
)
)
)
pause
exit /b
:ShareLocation <share_name> <variable_to_set_result_to>
SETLOCAL EnableDelayedExpansion
FOR /F "skip=1 tokens=* delims=" %%A IN ('WMIC SHARE where name^="%~1" GET Path') DO SET "%~2=%%A"
GOTO :EOF
I even tried not to set the result to a variable but just echo it instead it work fine if works alone without being in a for command
like this:
Code: Select all
@echo off
SETLOCAL EnableDelayedExpansion
Call :ShareLocation "a"
pause
exit
:ShareLocation
SETLOCAL EnableDelayedExpansion
FOR /F "skip=1 tokens=* delims=" %%A IN ('WMIC SHARE where name^="%~1" GET Path') DO echo %%A
GOTO :EOF
but in the previous for command "in the first code" it doesn't, any idea why?
Edit:
Also Tried This:
Code: Select all
@ECHO OFF
REM =====[ Shared Resources ]========================================
::
:: Check for any existance of a shared files/folders in the system.
:: We do nothing if shared resources was not found.
Echo.
Echo [+] Scanning Shared Resources.
SETLOCAL EnableDelayedExpansion
FOR /F "skip=1 tokens=* delims=" %%A IN ('WMIC SHARE GET Name') DO (
SET "ShareName=%%A"
REM if the line doesn't contain IPC$ in it and if the line wasn't empty
IF "!ShareName:~0,3!" NEQ "IPC" (
IF /I "!Sharename!" NEQ "" (
Echo.
Echo Shared Resources :
Echo * Share-Name: !ShareName!
FOR /F "skip=1 tokens=* delims=" %%A IN ('WMIC SHARE where name^="!ShareName!" GET Path') DO Echo * Share-Location: %%A
)
)
)
pause
exit /b
:ShareLocation
SETLOCAL EnableDelayedExpansion
FOR /F "skip=1 tokens=* delims=" %%A IN ('WMIC SHARE where name^="%~1" GET Path') DO <nul Set /p "= %%A"&Echo.
GOTO :EOF
The out put is:
Code: Select all
[+] Scanning Shared Resources.
Shared Resources :
* Share-Name: a
No Instance(s) Available.
Shared Resources :
* Share-Name: New Folder (2)
No Instance(s) Available.
Press any key to continue . . .
The Correct output should be:
Code: Select all
[+] Scanning Shared Resources.
Shared Resources :
* Share-Name: a
* Share-Loction: C:\Documents and Settings\admin\desktop\a
Shared Resources :
* Share-Name: New Folder (2)
* Share-Loction: C:\Documents and Settings\admin\desktop\New Folder (2)
Press any key to continue . . .