Home All Groups Group Topic Archive Search About

Help needed on creating Shared Directory

Author
6 Feb 2006 7:53 PM
mkober
Can anyone help with the VB.net code needed to create a directory on a
PC and set the share to Everyone with Full Access rights?

I can create the directory, and also set security as desired, but can't
find how to set the share programmatically using framework 2.0.

Thanks in advance!

Here's what I've got (and works):

'Set Directory (using new VB My.Computer option):
    My.Computer.FileSystem.CreateDirectory("C:\LIMS")


'Set Security:

        Dim security As DirectorySecurity =
System.IO.Directory.GetAccessControl("C:\LIMS")

        ' Set rule for Everyone
        Dim ruleEveryone As FileSystemAccessRule = New
FileSystemAccessRule(New NTAccount("", "Everyone"),
(FileSystemRights.FullControl), (InheritanceFlags.ContainerInherit Or
InheritanceFlags.ObjectInherit), PropagationFlags.None,
AccessControlType.Allow)

        ' Add the rules to the existing security settings
        security.AddAccessRule(ruleEveryone)

        ' Persist the changes
        System.IO.Directory.SetAccessControl("C:\LIMS", security)

Author
6 Feb 2006 8:41 PM
Simon Verona
How about shell("net share sharename=directorypath")?

Regards
Simon

Show quoteHide quote
"mkober" <mko***@wi.rr.com> wrote in message
news:1139255585.520977.52650@g44g2000cwa.googlegroups.com...
> Can anyone help with the VB.net code needed to create a directory on a
> PC and set the share to Everyone with Full Access rights?
>
> I can create the directory, and also set security as desired, but can't
> find how to set the share programmatically using framework 2.0.
>
> Thanks in advance!
>
> Here's what I've got (and works):
>
> 'Set Directory (using new VB My.Computer option):
> My.Computer.FileSystem.CreateDirectory("C:\LIMS")
>
>
> 'Set Security:
>
>        Dim security As DirectorySecurity =
> System.IO.Directory.GetAccessControl("C:\LIMS")
>
>        ' Set rule for Everyone
>        Dim ruleEveryone As FileSystemAccessRule = New
> FileSystemAccessRule(New NTAccount("", "Everyone"),
> (FileSystemRights.FullControl), (InheritanceFlags.ContainerInherit Or
> InheritanceFlags.ObjectInherit), PropagationFlags.None,
> AccessControlType.Allow)
>
>        ' Add the rules to the existing security settings
>        security.AddAccessRule(ruleEveryone)
>
>        ' Persist the changes
>        System.IO.Directory.SetAccessControl("C:\LIMS", security)
>
Author
6 Feb 2006 9:16 PM
mkober
Isn't there a more accurate/specific dotnet way to do this, other than
shelling?

I could see the need to change the permission levels in the future from
ALL to specific domain/group accounts. If this were written at the
start for this purpose, it would make life a lot easier.
Author
6 Feb 2006 9:48 PM
Simon Verona
If there was a way to do this, then I'd love to know how!

I'm sure somebody better then us know's a way!!

Simon
Show quoteHide quote
"mkober" <mko***@wi.rr.com> wrote in message
news:1139260602.856650.88210@g43g2000cwa.googlegroups.com...
> Isn't there a more accurate/specific dotnet way to do this, other than
> shelling?
>
> I could see the need to change the permission levels in the future from
> ALL to specific domain/group accounts. If this were written at the
> start for this purpose, it would make life a lot easier.
>
Author
7 Feb 2006 4:01 PM
mkober
I did try the Shell("Net Share LIMS=C:\LIMS") option in DotNet and it
worked fine, did what I wanted.

It still bothers me that I can't find any DotNet way of doing so. I'm
still looking into this more.