Create a NT Share
Create a share in a windows environment without using DOS commands. This code was based on information learned in WMI Scripting Primer: Part 3 on the MSDN
This code can easily be converted to VB.NET...
Original Author: Rick Casady
Code
'
' Purpose: Create a network share for NT users. You will
' need to have correct permision to do this and it can be
' done to remote computers.
' We pass in the folder name, path of the folder and
' description of the share folder.
Private Sub CreateShare(strShareName, strPath, strDescription)
Dim objSWbemServices as object
Dim objSWbemObject as object
Dim colSWbemObject as object
Dim intRet as integer
Dim blnExists as boolean
Dim objSWbem as object
' Next we call the standard GetObject function for
' returning COM objects and pass it the connection
' string for connecting to the WMI.
set objSWbemServices = GetObject("winmgmts:\.
ootcimv2")
' This same line can be executed on a remote computer
' with a differnt connection string like this:
' objSWbemServices = GetObject("winmgmts:\" & strComputer & "
ootcimv2")
' Now we enumrate the Shares on the target computer and
' return it to a collection
set colSWbemObject = objSWbemServices.InstancesOf("Win32_Share")
' Loop through each share on the machine to see if it already exists
For each objSWbem in colSWbemObject
If(objSWbem.name = strShareName)Then
blnShareExists = True
Exit For
Else
blnShareExists = False
End If
Next
' if the share didnt exisit our boolean will be false
' and we can try to add it.
If (blnShareExists = False)Then
' Create the share
' Now we need to get
set objSWbemObject = objSWbemServices.Get("Win32_Share")
' Last we call the create passing our pathg, name,
' description and 10 is for max number of users
intRet = objSWbemObject.Create(strPath, strShareName, , 10, strDescription)
Else
msgbox("Folder aready shared")
End If
End Sub
'
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.