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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating share in Win98 / Me is ReadOnly

Status
Not open for further replies.

Frihi

Programmer
Jun 24, 2001
48
CH
I'm creating a share for my appfolder, using WMI:

Dim apath As String = IO.Directory.GetCurrentDirectory()
Dim Share_Info As String() = {apath, "MyApp", 0}
Dim Win_Shares As ManagementClass = New ManagementClass("Win32_Share")
Try
Win_Shares.InvokeMethod("Create", Share_Info)
Catch ex As System.Management.ManagementException
MessageBox.Show(ex.ToString)
Return
Finally
Win_Shares.Dispose()
End Try
MessageBox.Show("Share: " + Share_Info(0) + " success!")

This works perfect for Win2000/XP. But for Win98/Me the share is readonly.
Have tried with API functions also - same result or worse.

It's driving me nuts. I just can't figure out, what parameter to declare readwrite access to the folder.

Fritz
 
Well, it really looks like nobody knows a solution. I've spent a lot of time and energy on this already. Just want to ask one more time if somebody had an idea. It's a bit silly, if everything works fine except for such a detail. But it really seems to be rather dificult...

Fritz
 
Sorry, we couldn't be of any assistance but I have noticed a lot of anomalies in win98 with the framework. They didn't do their homework.

Did you try the ADSI SDK (Active directory service interrface). Their is a small change that this could resolve the solution.



Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Thanks for your answer.

ADSI. Actually that's the only thing I haven't really tried yet, but I remember I have seen some ADSI code and it did not look different from the others (WMI, API). Occasionally you know some link to ADSI method? I don't remember right now where I have seen it. I think I will check that once more.

Really strange, because if you call the fileproperties dialogue in W98/Me there IS an option 'readwrite'. So I just think there must be a way to do it by code also. The newer OS's though don't have this specific option at all, only password protection and maximum permissions.

Or did Microsoft really not do it's homework?

Fritz
 
Perhaps the fileatributes could help.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
try this thread for that

thread796-924273


Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
try this thread

thread796-924273

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 

Dim f As System.IO.File
f.SetAttributes(pfad, IO.FileAttributes.ReadOnly)

Don't see any accessibility to the ReadWrite permission. Have been trying around with that already. Think the FileAttributes don't have much to do with the network permissions.

Up to now I found kind a workaround by calling the fileproperties dialog with SHELLEXECUTEINFO which I adapted from vb6 code. Like this at least mr. user must not search for the directory. But it's not satisfying neither and it only works from within another app, because I'm using a module.

Fritz
 
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
 
Well, the above code seems to have a problem in the declare function:

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

If I put 'servername As Object' it gives an error:

Object reference is not set to an instance

If I put 'servername As Integer' it says:

error 2123 (Buffer too small)

So far up to now I can't even say if the code can make a share, I don't know what to do about this buffer.
And the next step then will be to set the ReadWrite permission, if possible.

Beside of that i have found this site with an example in C++, which looks quite fine, but I have NULL experience with C++:


Would really apreciate any help!

Fritz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top