Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Using WMI to determine if directory is shared

Aug
1,933
71
Hi,
I wanted to see if the current directory is enabled as a shared folder in 4NT8 under XP.

Having never used the WMI (Windows Management Instrumentation), I decided to use this for determining if the current directory is enabled as a shared folder in 4NT8.

I came up with the following .BTM

Code:
@setlocal
@if %_echo eq 1 @echo off
if defined thisdir unset thisdir
set thisdir=%@wmi[root\cimv2,"select Name from Win32_Share Where Path = '%@replace[\,\\,%_cwd]'"]
if defined thisdir echo %_cwd is shared as %thisdir
if not defined thisdir echo %_cwd is not shared
endlocal
I learned quite a bit about WMI for this task.

Note the Path = '%@replace[\,\\,%_cwd]'"

Since Path is not a Key, I have to use double-backslashes in the directory name. So,

C:\utils\example becomes

C:\\utils\\example

The Path property indicates the local path of the Win32 share.

The Win32_Share class has methods which allow you to create a share, delete a share, determine the access rights to the share, and to set share info. Each method also has qualifiers to obtain more information in regards to the share.

As noted in the 4NT8 help file, download the "WMI Code Creator" from Microsoft. This is a GUI front-end for WMI, that creates code for C#, Visual Basic .NET, and Visual Basic Script, and was quite useful in learning about WMI.

Joe
 

Similar threads

Back
Top