Delete share on remote server

  • Thread starter Thread starter Jack
  • Start date Start date
J

Jack

I'm trying to create a fuction to delete shares on a remote server
using WMI's win32_share. I've gotten the create method to work but
having difficulty with the delete method. If someone could post an
example using the delete method it would be greatly appreciated.

Thanks
Jack
 
could you post an example of the way you are doing it?
both methods, Maybe I can figure it out...
you can mail me offlist if you'd like.
 
Shadowboxer, here's my working code to share a directory

Private Function ShareDir(ByVal Server As String, ByVal path As
String, ByVal sharename As String, ByVal description As String) As
String
Dim wmiScope As ManagementScope
Dim wmiShare As ManagementClass
Dim inParams As ManagementBaseObject
Dim outParams As ManagementBaseObject

wmiScope = New Management.ManagementScope("\\" & Server &
"\root\cimv2")
wmiScope.Connect()
wmiShare = New ManagementClass(wmiScope, New
ManagementPath("Win32_Share"), Nothing)
inParams = wmiShare.GetMethodParameters("Create")
inParams("Path") = path
inParams("Name") = sharename
inParams("Type") = 0
inParams("MaximumAllowed") = Nothing
inParams("Description") = description
outParams = wmiShare.InvokeMethod("Create", inParams, Nothing)
'Catch e As Exception
Return "Complete"
End Function

And my attempt at deleting a share...

Private Function DelShare(ByVal Server As String, ByVal path As
String, ByVal sharename As String, ByVal description As String) As
String
Dim wmiScope As ManagementScope
Dim wmiShare As ManagementClass
Dim inParams As ManagementBaseObject
Dim outParams As ManagementBaseObject

wmiScope = New Management.ManagementScope("\\" & Server &
"\root\cimv2")
wmiShare = New ManagementClass(wmiScope, New
ManagementPath("Win32_Share"), Nothing)
wmiShare.Delete()

End Function

Thanks in advance...
 
Back
Top