Code: Select all
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
^& "{impersonationLevel=impersonate}!\\" ^& strComputer ^& "\root\cimv2")
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")
For each objShare in colShares
Wscript.Echo objShare.Name ^& "/" ^& objShare.Path
Next
Then use this code (plus the RMTShare.exe" utility) to get permissions:
Code: Select all
SetLocal EnableDelayedExpansion
SET "buf= . . . "
REM FIX this to SORT output
FOR /F "usebackq tokens=1,* delims=/" %%a IN (`cscript //nologo "%ListNetShares%"`) DO (
@ECHO %%a %buf% %%b
SET "foundPrivs="
FOR /F "usebackq tokens=*" %%d IN (`RMTShare.exe \\%COMPUTERNAME%\"%%~a"`) DO (
IF DEFINED foundPrivs (
IF /I "%%d" neq "The command completed successfully." (
SET myGrp=%%d
@ECHO %buf% !myGrp:%COMPUTERNAME%\=!
)
)
IF /I "%%d"=="Permissions:" SET "foundPrivs=1"
IF /I "%%d"=="No permissions specified." @ECHO %buf% %%d
)
)
EndLocal
I noticed this code from b0gus here viewtopic.php?f=3&t=7011#p45720
Code: Select all
@echo off
setlocal
echo:...wait
for %%v in (wmic.exe) do if "%%~$path:v"=="" (echo:OS missing wmic.exe&pause&exit /b 1)
set "Name="
for /f %%v in ('2^>nul wmic.exe path Win32_Group where SID^="S-1-5-32-544" get name /Format:value^|more +2') do for /f "delims=" %%n in ("%%v") do (set %%n)
if NOT defined Name echo:OS missing group with SID=S-1-5-32-544&pause&exit /b 2
set "admins=" & set "x="
for /f "tokens=*" %%v in ('net localgroup %Name%') do call set "admins=%%admins%% "%%x%%"" & set "x=%%v"
cls
echo:users from localgroup "%Name%":
for %%v in (%admins:*-" =%) do echo: %%~v
pause
exit /b 0
It seemed pretty robust and the use of WMIC made me think you could do something similar with SHARES in addition to USERS or GROUPS.
So this is NOT a critical need for me - my current solution works and I wouldn't want anyone spending a lot of time working up a new solution. I'm just in learning mode now and looking to see how others have solved these issues to learn new techniques, etc.