Hi Christiaan
I have gone over the code I have from Steve on the vb.net forum. It's the shi_50 API which is used for W98/Me. Something in it does not work, but I don't know exactly what it is, apearently there is a problem with the buffer size.
And right now I also came up to this site on MSDN:
I notice, that they use slightly different declarations. So I post the code from Steve here and maybe you detect something. To me it's quite some levels above my understandings:
Option Strict On
Public Class SharesWin9x
Private Const NERR_SUCCESS As Integer = 0&
'share types
Private Const STYPE_ALL As Integer = -1 'note: my const
Private Const STYPE_DISKTREE As Integer = 0
Private Const STYPE_PRINTQ As Integer = 1
Private Const STYPE_DEVICE As Integer = 2
Private Const STYPE_IPC As Integer = 3
Private Const STYPE_SPECIAL As Integer = &H80000000
'permissions
Private Const ACCESS_READ As Integer = &H1
Private Const ACCESS_WRITE As Integer = &H2
Private Const ACCESS_CREATE As Integer = &H4
Private Const ACCESS_EXEC As Integer = &H8
Private Const ACCESS_DELETE As Integer = &H10
Private Const ACCESS_ATRIB As Integer = &H20
Private Const ACCESS_PERM As Integer = &H40
Private Const ACCESS_ALL As Integer = ACCESS_READ Or ACCESS_WRITE Or ACCESS_CREATE Or ACCESS_EXEC Or _
ACCESS_DELETE Or ACCESS_ATRIB Or ACCESS_PERM
Public Declare Function NetShareAdd9x Lib "svrapi.dll" Alias "NetShareAdd" ( _
ByVal servername As Object, _
ByVal slevel As Integer, _
ByRef buf As SHARE_INFO_50, _
ByVal cbbuf As Integer) As Integer
Structure SHARE_INFO_50
Dim shi50_netname As String
Dim shi50_type As Integer
Dim shi50_flags As Integer
Dim shi50_remark As String
Dim shi50_path As String
Dim shi50_rw_password As String
Dim shi50_ro_password As String
End Structure
Public Shared Function ShareAdd(ByVal sServer As String, ByVal sSharePath As String, _
ByVal sShareName As String, ByVal sShareRemark As String, _
ByVal sSharePw As String) As Integer
Dim dwServer As String
Dim dwNetname As String
Dim dwPath As String
Dim dwRemark As String
Dim dwPw As String
Dim parmerr As Integer
Dim si50 As SHARE_INFO_50
'obtain pointers to the server, share and path
dwServer = sServer
dwNetname = sShareName
dwPath = sSharePath
'if the remark or password specified,
'obtain pointer to those as well
If sShareRemark.Length > 0 Then dwRemark = sShareRemark
If sSharePw.Length > 0 Then dwPw = sSharePw
'prepare the SHARE_INFO_2 structure
With si50
.shi50_netname = dwNetname
.shi50_path = dwPath
.shi50_remark = dwRemark
.shi50_type = STYPE_DISKTREE
.shi50_ro_password = String.Empty
.shi50_rw_password = String.Empty
.shi50_flags = ACCESS_ALL
'//.shi50_permissions = ACCESS_ALL
'//.shi50_max_uses = -1
'//.shi50_passwd = dwPw
End With
'add the share
'//Return NetShareAdd9x(dwServer, 2, si50, parmerr)
'Return NetShareAdd9x(dwServer, 50, si50, parmerr)
'// oder:
Return NetShareAdd9x(0, 50, si50, parmerr) '// Müsstest du einmal testen
End Function
End Class
And the call:
Dim result As Integer = Shares.ShareAdd("\\" + System.Environment.MachineName, "C:\Freigabe", "my share", "my share", String.Empty)
Select Case result
Case 0 : MessageBox.Show("share created successfully!")
Case 2118 : MessageBox.Show("share name already exists")
Case Else : MessageBox.Show("create error " + result.ToString())
End Select
Btw, if you understand german, we had a long discussion already about the subject:
But as Steve did not have a Win98 machine to test it, the story didn't come to an end.
Well, that's a lot of stuff here, I still hope, there will be a solution.
Fritz