Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a share folder using VBS?

Status
Not open for further replies.

dannydanny

IS-IT--Management
Oct 9, 2002
109
0
0
DK
Hi,

I have about 50 folders for each of my users. I wrote a VBS script to automate the creation of the folder, now I`m looking for a VBS method to take each folder and set it so it is shared.

Is the Dos command "net share" my only option?

Thanks for any info,
Danny
 
Try this:

Function MapDriveIfMember (ByVal Drive, ByVal Path, ByVal Group)

'
' Return Values:
' 0 = Not Member of Group
' 1 = Group Member and Drive Mapped
' 2 = Drive not mapped due to error
'

On Error Resume Next

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oGroup = GetObject("WinNT://" & WshNetwork.UserDomain & "/" & Group)

MapDriveIfMember = 0

If oGroup.IsMember("WinNT://" & WshNetwork.UserDomain & "/" & WshNetwork.UserName) Then

Set oDrives = WshNetwork.EnumNetworkDrives
For i = 0 to oDrives.Count -1
if oDrives.Item(i) = Drive then WshNetwork.RemoveNetworkDrive Drive, -1, -1
Next
WshNetwork.MapNetworkDrive Drive, Path

MapDriveIfMember = 1

End If

If Not Err.Number = 0 Then MapDriveIfMember = 2 : WshShell.LogEvent 4, "Map by Group Function - User: " & WshNetwork.Username & " failed to Drive " & Drive & " to " & Path : Err.Clear

End Function
 
Use the Create method of the WMI Win32_Share class, or use the Create method of the ADSI IADsFileService class.

Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top