Reputation: 1098
I'm trying to derive an absolute or full local path from a network path of a folder on a PC drive on LAN using WMIC or similar network tool run from a batch. A few threads devoted to similar tasks on this site when tested don't offer working solution in Win 10.
For example, when running a suggested in one answer query in Win 10 Cmd, I got:
C:\WINDOWS\system32>wmic share where "name='\\Laptop\Data'" get path
Node - OFFICE
ERROR:
Description = Invalid query
C:\WINDOWS\system32>wmic share where "name='Data'" get path
No Instance(s) Available.
I need this result: K:\Data , where K:\ is a hard drive of the remote PC on LAN, and Data is shared folder on that drive.
Can someone suggest a working query & batch for that task? WMIC documentation is way too extensive to derive a working query by trial-and-error without significant experience in using the tool.
Upvotes: 0
Views: 5128
Reputation: 1098
Suggested in the thread techniques worked with certain additional actions.
When using WMIC, I had to add local admin account to WMI Control Security property. As well, by running GPEDIT.msc enabled "Allow inbound remote administration exceptions" to Firewall rules, despite Firewall was disabled. The proper query is below, processing it's output required a batch file similar in approach to PsExec batch:
wmic /user:[username] /password:[password] /node:"PC-ID" share get
@echo off
setlocal EnableExtensions EnableDelayedExpansion
for /f "tokens=1,2 skip=1 delims=:" %%u in ('wmic /user:[username] /password:[password] /node:"Laptop" share get') do @(
set "var1=%%u" & set "var2=%%v"
set "var1.1=!var1:~89,-1!" & set "var2=!var2:~0,33!" & set "var1.2=!var1:~97!" & set "var1.3=!var1.1:~0,4!"
if not "!var1.3!"=="IPC$" if not "!var1.1!"=="" echo \\Laptop\!var1.1! = !var1.2!:!var2!)
exit /b
::Output
\\Laptop\ADMIN$ = C:\WINDOWS
\\Laptop\C$ = C:\
\\Laptop\D$ = D:\
\\Laptop\Data = K:\
\\Laptop\K$ = K:\
\\Laptop\Docs = K:\Other\Docs
\\Laptop\print$ = C:\windows\system32\spool\drivers
When using PsExec instead of WMIC, I had to install it first, then add an extra key LocalAccountTokenFilterPolicy in Registry, then modify the command posted earlier:
@echo off
for /f "tokens=1,2" %%u in ('psexec64 -u [username] -p [password] \\Laptop cmd /c net share 2^>nul') do @(
for /f "tokens=1,2 delims=:" %%x in ("%%u %%v") do @(
if not "%%y"=="" echo \\Laptop\%%u = %%v ) )
exit /b
::Output
\\Laptop\C$ = C:\
\\Laptop\D$ = D:\
\\Laptop\print$ = C:\windows\system32\spool\drivers
\\Laptop\K$ = K:\
\\Laptop\ADMIN$ = C:\WINDOWS
\\Laptop\Data = K:\
\\Laptop\Docs = K:\Other\Docs
Upvotes: 0
Reputation: 17648
The following lists the drive letters mapped on the local machine to the (currently connected) remote shares.
C:\etc>for /f "tokens=1-3" %x in ('net use') do @if /i "%x" equ "ok" echo %z = %y
\\laptop\x$ = P:
\\laptop\data = Q:
net share
usage]
I need this result: K:\Data , where K:\ is a hard drive of the remote PC on LAN, and Data is shared folder on that drive.
If you need the K:
drive letter assigned on the remote machine to the drive containing the shared directory, then you could run net share
remotely using PsExec or similar (provided you have an account with enough rights on the remote machine).
For example, assuming \\laptop
is another machine on the LAN, the following will list the share names and (remote) directories on \\laptop
.
C:\etc>for /f "tokens=1,2" %u in ('psexec \\laptop cmd /c net share 2^>nul') do @(
for /f "tokens=1,2 delims=:" %x in ("%u %v") do @(
if not "%y"=="" echo "\\laptop\%u" = "%v" ) )
"\\laptop\C$" = "C:\"
"\\laptop\ADMIN$" = "C:\Windows"
"\\laptop\DATA" = "K:\Data"
Upvotes: 1
Reputation:
wmic share where name='C$' get path
Works here (as only one test doesn't need double quotes). So does
wmic share where "name='C$'" get path
What you posted says you don't have a share called data
.
wmic share get /format:list
Shows you what you have.
C:\Users\User>wmic share get
AccessMask AllowMaximum Caption Description InstallDate MaximumAllowed Name Path Status Type
TRUE Remote Admin Remote Admin ADMIN$ C:\Windows OK 2147483648
TRUE Default share Default share C$ C:\ OK 2147483648
TRUE Default share Default share D$ D:\ OK 2147483648
TRUE fred fred C:\Intel OK 0
TRUE Default share Default share G$ G:\ OK 2147483648
TRUE Remote IPC Remote IPC IPC$ OK 2147483651
TRUE TestC TestC C:\ OK 0
As usual wmic /?
, wmic share /?
, wmic share call /?
, wmic share get /?
, wmic /format /?
.
For remote computers you have to connect to that computer (see wmic /node /?
).
wmic /node:127.0.0.1 share get
Upvotes: 1