Create Method of the Win32_Share Class

The CreateWMI class method initiates sharing for a server resource. Only members of the Administrators or Account Operators local group or those with Communication, Print, or Server operator group membership can successfully execute Create. The Print operator can only add printer queues. The Communication operator can only add communication device queues.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax

MOF
uint32 Create(
  [in]  string Path,
  [in]  string Name,
  [in]  uint32 Type,
  [in]  uint32 MaximumAllowed,
  [in]  string Description,
  [in]  string Password,
  [in]  Win32_SecurityDescriptor Access
);

Parameters

Path [in]

Local path of the Windows share.

Example, "C:\Program Files".

Name [in]

Passes the alias to a path set up as a share on a computer system running Windows.

Example, "public".

Type [in]

Passes the type of resource being shared. Types includes disk drives, print queues, interprocess communications (IPC), and general devices. Can be one of the following values.

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

 

MaximumAllowed [in]

Limit on the maximum number of users allowed to concurrently use this resource.

Example: 10. This parameter is optional.

Description [in]

Optional comment to describe the resource being shared. This parameter is optional.

Password [in]

Password (when the server is running with share-level security) for the shared resource. If the server is running with user-level security, this parameter is ignored. This parameter is optional.

Access [in]

Security descriptor for user level permissions. A security descriptor contains information about the permissions, owner, and access capabilities of the resource. If this parameter is not supplied or is NULL, then Everyone has read access to the share. For more information, see Win32_SecurityDescriptor and Changing Access Security on Securable Objects.

Return Value

Returns one of the values listed in the following table, or any other value to indicate an error.

Return codeDescription
0

Success

2

Access Denied

8

Unknown Failure

9

Invalid Name

10

Invalid Level

21

Invalid Parameter

22

Duplicate Share

23

Redirected Path

24

Unknown Device or Directory

25

Net Name Not Found

 

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 clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
MOFCimwin32.mof
DLLCimwin32.dll
Namespace\root\cimv2

See Also

Operating System Classes
Win32_Share

Send comments about this topic to Microsoft

Build date: 11/3/2009

Tags :


Community Content

Thomas Lee
Create a new Share with WMI and Powershell
# Create_Share.ps1
# Creates a share on the local computer using WMI and Create static method
# thomas lee - tfl@psp.co.uk

# create pointer to class
$comp=[WMICLASS]"Win32_share"

# create a new share
$comp.create("c:\","mynewshare",0)
  
# see results
gwmi win32_share


When run on my system results are as follows:

__GENUS          : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ReturnValue : 0


PS C:\foo> GWMI win32_share | ft name, path, description -auto

name path description
---- ---- -----------
ADMIN$ C:\Windows Remote Admin
C$ C:\ Default share
CertEnroll C:\Windows\system32\CertSrv\CertEnroll Active Directory Certificate Services share
E$ E:\ Default share
IPC$ Remote IPC
NETLOGON C:\Windows\SYSVOL\sysvol\gktrain.net\SCRIPTS Logon server share
newshare C:\
P$ P:\ Default share
SYSVOL C:\Windows\SYSVOL\sysvol Logon server share



Thomas Lee
Create Method is a STATIC method

The documentation is not clear here, but the Create Method is static.

With PowerShell, you can see this method using [wmiclass] type accellerator as follows:

PCS c:\foo>  [WMICLASS]'Win32_share' | get-member
TypeName: System.Management.ManagementClass#ROOT\cimv2\Win32_Share
  Name MemberType Definition 
---- ---------- ----------
Name AliasProperty Name = __Class
Create Method System.Management.ManagementBaseObject Create(System.String Path, System.String Name, System.UInt32 ...
__CLASS Property System.String __CLASS {get;set;}
__DERIVATION Property System.String[] __DERIVATION {get;set;}
__DYNASTY Property System.String __DYNASTY {get;set;}
__GENUS Property System.Int32 __GENUS {get;set;}
__NAMESPACE Property System.String __NAMESPACE {get;set;}
__PATH Property System.String __PATH {get;set;}
__PROPERTY_COUNT Property System.Int32 __PROPERTY_COUNT {get;set;}
__RELPATH Property System.String __RELPATH {get;set;}
__SERVER Property System.String __SERVER {get;set;}
__SUPERCLASS Property System.String __SUPERCLASS {get;set;}
ConvertFromDateTime ScriptMethod System.Object ConvertFromDateTime();
ConvertToDateTime ScriptMethod System.Object ConvertToDateTime();
Tags : contentbug

cc443
Create Share with cmd.exe and WMIC

cc443
Create Share with cmd.exe and WMIC

cc443
Create Share with cmd.exe and WMIC

cc443
Create Share with WMIC
Tags : contentbug

cc443
Create share with WMIC
Tags : contentbug

Page view tracker