5 out of 10 rated this helpful - Rate this topic

Win32_Share class

Applies to: desktop apps only

The Win32_Share class represents a shared resource on a computer system running Windows. This may be a disk drive, printer, interprocess communication, or other sharable device. For more information about retrieving WMI classes, see Retrieving a Class.

The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties. Properties and methods are in alphabetic order, not MOF order.

Syntax

class Win32_Share : CIM_LogicalElement
{
  uint32   AccessMask;
  boolean  AllowMaximum;
  string   Caption;
  string   Description;
  datetime InstallDate;
  uint32   MaximumAllowed;
  string   Name;
  string   Path;
  string   Status;
  uint32   Type;
};

Members

The Win32_Share class has these types of members:

Methods

The Win32_Share class has these methods.

MethodDescription
Create

Class method that initiates sharing for a server resource.

Delete

Class method that deletes a share name from a server's list of shared resources, disconnecting connections to the shared resource.

GetAccessMask

Returns the access rights to the share held by the user or group on whose behalf the instance is returned. You should use this method in place of the AccessMask property, which is always NULL.

Windows NT 4.0 and Windows Me/98/95:  This method is unavailable. Use the AccessMask property instead.
SetShareInfo

Class method that sets the parameters of a shared resource.

 

Properties

The Win32_Share class has these properties.

AccessMask
Data type: uint32
Access type: Read-only

This property is obsolete and is no longer used. Use the Win32_Share.GetAccessMask method instead. The value of the AccessMask property is set to null by WMI. For more information about setting access when a share is created, see the Create method.

Windows 2000 and Windows NT 4.0:  Bit array that represents the access rights that are required to access or perform specific operations on the file or directory. For bit values, see File and Directory Access Rights Constants.
Windows Me/98/95 on Windows 98/95 FAT volumes, AccessMask:  On Windows 98/95 FAT volumes, AccessMask is null.
AllowMaximum
Data type: boolean
Access type: Read-only

Number of concurrent users for this resource has been limited. If true, the value in the MaximumAllowed property is ignored.

Caption
Data type: string
Access type: Read-only

Short description of the object.

Description
Data type: string
Access type: Read-only

Description of the object.

InstallDate
Data type: datetime
Access type: Read-only

Object was installed. This property does not need a value to indicate that the object is installed.

MaximumAllowed
Data type: uint32
Access type: Read-only

Limit on the maximum number of users allowed to use this resource concurrently. The value is only valid if the AllowMaximum property is set to FALSE.

Name
Data type: string
Access type: Read-only
Qualifiers: Key

Alias given to a path set up as a share on a computer system running Windows.

Example: "public"

Path
Data type: string
Access type: Read-only

Local path of the Windows share.

Example: "C:\Program Files"

Status
Data type: string
Access type: Read-only

Current status of the object. Various operational and nonoperational statuses can be defined. Operational statuses include: "OK", "Degraded", and "Pred Fail" (an element, such as a SMART-enabled hard disk drive, may be functioning properly but predicting a failure in the near future). Nonoperational statuses include: "Error", "Starting", "Stopping", and "Service". The latter, "Service", could apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is online, yet the managed element is neither "OK" nor in one of the other states.

The values are:

"OK"
"Error"
"Degraded"
"Unknown"
"Pred Fail"
"Starting"
"Stopping"
"Service"
"Stressed"
"Nonrecover"
"NoContact"
"LostComm"
Type
Data type: uint32
Access type: Read-only

Type of resource being shared. Types include: disk drives, print queues, interprocess communications (IPC), and general devices.

ValueMeaning
0 (0x0)

Disk Drive

1 (0x1)

Print Queue

2 (0x2)

Device

3 (0x3)

IPC

2147483648 (0x80000000)

Disk Drive Admin

2147483649 (0x80000001)

Print Queue Admin

2147483650 (0x80000002)

Device Admin

2147483651 (0x80000003)

IPC Admin

 

Remarks

The Win32_Share class is derived from CIM_LogicalElement.

Examples

For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository.

For C++ code examples, see WMI C++ Application Examples.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Namespace

\root\CIMV2

MOF

Cimwin32.mof

DLL

Cimwin32.dll

See also

Operating System Classes

 

 

Send comments about this topic to Microsoft

Build date: 3/9/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Name property
Suppose I have a server named SERVER01 that has a share named SHARE01.
To get this share object in powershell use the command:

[wmi]"\\SERVER01\root\cimv2:Win32_Share.Name='SHARE01'"

This will also work for a Windows 2003 cluster where SERVER01 is the network name for a cluster group.
However, for a Windows 2008 cluster using CAP this will NOT work, because the Name property is now the UNC path to the share.
In such cases use:

[wmi]"\\SERVER01\root\cimv2:Win32_Share.Name='\\SERVER01\SHARE01'"

Actually for a cluster server the class name is Win32_ClusterShare which is a subclass of Win32_Share.

"Create" example for C#

using System.Management;

private static void makeShare(string servername, string filepath, string sharename)
{
try
{
// assemble the string so the scope represents the remote server
string scope = string.Format("\\\\{0}\\root\\cimv2", servername);
// connect to WMI on the remote server
ManagementScope ms = new ManagementScope(scope);
// create a new instance of the Win32_Share WMI object
ManagementClass cls = new ManagementClass("Win32_Share");
// set the scope of the new instance to that created above
cls.Scope = ms;
// assemble the arguments to be passed to the Create method
object[] methodargs = { filepath, sharename, "0" };
// invoke the Create method to create the share
object result = cls.InvokeMethod("Create", methodargs);
}
catch (SystemException e)
{
Console.WriteLine("Error attempting to create share {0}:", sharename);
Console.WriteLine(e.Message);
}
}

Properties null based on security
If the caller does not have appropriate rights, the AllowMaximum, MaximumAllowed, Path, and Type properties will always be returned as null.

I don't know if there is an ACL somewhere that controls this, but on a typical system only Power Users and Administrators will get all the property values.


Create Method is static, others are dynamic

The Create method in this class is a static method - the text does not make that clear. The Delete, GetAccessMask and SetShareInfo mthods, on the other hand are instance methods.

Filtered sample in PowerShell

A short appendix to Thomas' example:
Normally I would like to see only the useful shares, and filter serverside to limit the usage of bandwith. This can be done by

Get-WmiObject -Query "SELECT * FROM Win32_Share WHERE Name != 'ADMIN$' AND Name != 'IPC$'"

Using the GWMI alias the statement could be

gwmi -q "SELECT * FROM Win32_Share WHERE Name != 'ADMIN$' AND Name != 'IPC$'"
Sample for PowerShell
#Requires -Version 1
# wmi-win32_share.ps1
# gets active shares on a system.
$shares = Get-WMIObject -class Win32_share

#
# one-liner to print out a simple listing
#
"Shares on : {0}" -f $((gwmi win32_computersystem).name)
$shares | sort name | ft -auto
Sample for WSH

'Sample for WSH

' List of Shares

' Alexander Klimoff (http://winchanger.whatis.ru)

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Share")

For Each objItem in colItems
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Caption: " & objItem.Caption & "=" & objItem.Path
Next