Creare una share di rete tramite WMI

Tramite il seguente codice è possibile creare una share di rete senza fare ricorso alle Api (ovviamente con performance minori rispetto a quest’ultime).
I sistemi operativi supportati sono:

  • Windows Server 2003
  • Windows XP
  • Windows 2000 Professional/Server
  • Windows NT Workstation/Server 4.0 SP4 e successivi

Dim path As New System.Management.ManagementPath(“Win32_Share”)
Dim share As New System.Management.ManagementClass(Nothing, path, Nothing)

Dim inArgs As System.Management.ManagementBaseObject
inArgs = share.GetMethodParameters(“Create”)
inArgs(“Path”) = “C:\MyFolder”
inArgs(“Name”) = “ShareName”
‘”ShareName$” for hide share
inArgs(“Type”) = 0
inArgs(“MaximumAllowed”) =
Nothing
inArgs(“Description”) = Nothing

Dim outArgs As System.Management.ManagementBaseObject
outArgs = share.InvokeMethod(“Create”, inArgs,
Nothing)

inArgs.Dispose() : inArgs = Nothing
outArgs.Dispose() : outArgs = Nothing
share.Dispose() : share = Nothing
path = Nothing

Per maggiori info sul metodo create della Win32_Share:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/create_method_in_class_win32_share.asp

Per uno script:
http://www.microsoft.com/technet/scriptcenter/scripts/storage/shares/stshvb01.mspx