ADSI share code acting strange

ADSI share code acting strange

Post by Dave » Fri, 19 Dec 2003 02:48:59


Hi,

I'm using 2 sub's to create and delete shares. They work great by
themselves.
The problem occurs when I try to rename a share.
To rename a share I call the deleteShare sub and then I call the createShare
sub.
The createShare sub throws an error (-2147463154, The directory object
exists.), but still the name change occurs.

for example: if I have 3 buttons and assign them to delete a share, create
a share and to rename a share,
the delete and create buttons work great by themselves. I can delete a
share and then create one right afterwards,
but the rename button always throws an error from the createShare sub.

Here's my code:

<start code>
Sub createShare(sharePath, shareName)
Dim shareObj As Object
On Error Resume Next
setUp

Set shareObj = serveObj.Create("fileshare", shareName)

If Err.Number <> 0 Then
MsgBox "An error has occurred!!!" & vbCrLf & Err.Number & ", " &
Err.Description, vbCritical
Exit Sub
End If

shareObj.path = sharePath
shareObj.SetInfo
Set shareObj = Nothing
cleanUp
End Sub

Sub deleteShare(shareName)
On Error Resume Next
setUp
serveObj.Delete "fileshare", shareName

If Err.Number <> 0 Then
MsgBox "An error has occurred!!!" & vbCrLf & Err.Number & ", " &
Err.Description, vbCritical
Exit Sub
End If

cleanUp
End Sub

Private Sub setUp()
Dim compName As String
Dim domainName As String

compName = Environ("computername")
domainName = Environ("userdomain")

Set serveObj = GetObject("WinNT://" & domainName & "/" & compName &
"/LANMANSERVER")
End Sub

Private Sub cleanUp()
Set serveObj = Nothing
End Sub
 
 
 

ADSI share code acting strange

Post by maxv » Sat, 20 Dec 2003 00:16:42

I would not user ADSI to create shares. I would use WMI.

The ADSI stuff for shares works great to read existing information, but
writing stuff with it has never been very reliable.

So, I would go to WMI, that is what it was designed for.

Sincerely,
Max Vaughn [MS]
Microsoft Developer Support


Disclaimer: This posting is provided "AS IS" with no warranties, and
confers no rights. You assume all risk for your use.

 
 
 

ADSI share code acting strange

Post by Dave » Sat, 20 Dec 2003 02:49:41

Thanks Max,

I'll take a look at it. I'm pretty new to ADSI so I'm kind of learning as I
go.

Dave
 
 
 

ADSI share code acting strange

Post by Dave » Sun, 21 Dec 2003 03:22:58

Found the problem finally.

Had an if statement a little screwed up and was hitting createShare twice.

Thanks!!!
Dave