Search Tools Links Login

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
'

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 97 times

Categories

ASP/ HTML

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.