Create method of the Win32_Share Class
Applies to: desktop apps only
The Create WMI 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
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.
Value Meaning - 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
| Return code | Description |
|---|---|
|
Success |
|
Access Denied |
|
Unknown Failure |
|
Invalid Name |
|
Invalid Level |
|
Invalid Parameter |
|
Duplicate Share |
|
Redirected Path |
|
Unknown Device or Directory |
|
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 client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Namespace |
\root\CIMV2 |
|
MOF |
|
|
DLL |
|
See also
Send comments about this topic to Microsoft
Build date: 3/9/2012
- 10/21/2010
- Shogun.Net
# 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
- 1/27/2008
- Thomas Lee
- 8/11/2009
- Thomas Lee
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();
- 12/27/2008
- Thomas Lee
- 12/27/2008
- Thomas Lee