473,383 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Creating a Shared Folder

Hi -

I understand how to create a directory folder, but how can I programatically
create a _shared_ directory folder and set its permissions?? (I'm using
VB.NET.)

Thanks for your help.

- Jeff
Nov 20 '05 #1
6 14804
you can create a shared folder by shelling out to the shell command "net"

ie shell("net share sharename=c:\directoryname")

there are some basic options for permissions on this command. try net share
/? for details..

As for going any further than that with permissions, I'm afraid I can't
help..

regards

simon

"Jeff" <je*********@eNetPortals.com> wrote in message
news:hx****************@newsread3.news.atl.earthli nk.net...
Hi -

I understand how to create a directory folder, but how can I programatically create a _shared_ directory folder and set its permissions?? (I'm using
VB.NET.)

Thanks for your help.

- Jeff

Nov 20 '05 #2
Thanks, Simon -

I'm still looking for a ".NET" way to create a shared directory, and share
net doesn't appear to solve the permissions problem.

Any other ideas?? Anyone?

- Jeff
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:u%****************@TK2MSFTNGP11.phx.gbl...
you can create a shared folder by shelling out to the shell command "net"

ie shell("net share sharename=c:\directoryname")

there are some basic options for permissions on this command. try net share /? for details..

As for going any further than that with permissions, I'm afraid I can't
help..

regards

simon

"Jeff" <je*********@eNetPortals.com> wrote in message
news:hx****************@newsread3.news.atl.earthli nk.net...
Hi -

I understand how to create a directory folder, but how can I

programatically
create a _shared_ directory folder and set its permissions?? (I'm using
VB.NET.)

Thanks for your help.

- Jeff


Nov 20 '05 #3
Hi Jeff,

I think you may try to use the WMI approach to do the job.
Here is a useful google link you may take a look.
http://groups.google.com/groups?hl=z...0F8E6.1BF1456A
%40hydro.com

In .net we can use the System.Management to manipulate the WMI.
Code: Finding the Amount of Disk Space Available (Visual Basic)
http://msdn.microsoft.com/library/de...us/dv_vbcode/h
tml/vbtskCodeFindingAmountOfDiskSpaceAvailableVisualBa sic.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #4
Hi -

This post is in response to Peter Huang's request for feedback on his
response to my question.

First, Peter, thank you for your response. But my issue remains unresolved.
The difficulty I'm having with your response may be that you perhaps
provided too much(!) information. I can't use some of it, but I'm having to
wade through all of it to find the useful bits. (My comments on the
specific links that you provided are below.)

I had thought that my initial question was straightforward: I need to
create a shared folder and set its permissions using VB.NET. It seems that,
to do so, I must learn a whole new technology (wmi). While I'm willing to
do that, it's taking some time. Wmi documentation is not all that
intuitive, and I've found a few tantalizingly-but-not-exactly relevant
examples that I haven't yet been able to get to work from VB.NET. I was
hoping for a more straightforward answer or example when I posted my
question.

My further research has alerted me to some additional issues that may be
relevant. So, in the interest of clarifying/focusing my question:

- I'm creating a commercial VB.NET application
- I need to synchronize two databases, one SQL2K database on a desktop or
network, and one SQLCE database on a pocket pc handheld
- To accomplish that synchronization, I need to use SQL's merge replication
- To implement that merge replication, I need to create a shared folder and
set its permissions
- I will not have access to users' computers, so all of this must be done by
my app
- I'm trying to hide as much complexity as possible from the user
- Users may be using a variety (I have no control over this) of Windows
versions
- Users can be single users trying to synchronize their desktop with their
PDA (I'll need to distribute and install MSDE for these users)
- Users also can be corporate users, synchronizing many PDAs with a
corporate SQL database.

Your response provided links to two web pages:

1.
http://groups.google.com/groups?hl=z...6A%40hydro.com
2.
http://msdn.microsoft.com/library/de...dv_vbcode/html _

/vbtskCodeFindingAmountOfDiskSpaceAvailableVisualBa sic.asp

The second link is an MSDN Library page discussing how to use wmi to find
available disk space. While that code seems to work, it doesn't address my
search for a way to create a share and set permissions. Since there are
other MSDN Library articles that more closely approach those issues, I'm not
sure why you suggested I look at the finding disk space article instead of
more relevant articles.

The first link was to a forum post about setting file share permissions
using a script. That page didn't answer the question, but it provided links
to 14 other sites/pages:

a) http://www.microsoft.com/technet/scr...er/scrff33.asp
b)
http://msdn.microsoft.com/library/en...descriptor.asp
c)
http://groups.google.com/groups?hl=e...13%40hydro.com
d)
http://msdn.microsoft.com/library/en...descriptor.asp
e)
http://groups.google.com/groups?selm....microsoft.com
f) http://groups.google.com/groups?selm....microsoft.com
g) http://www.jsiinc.com/asp/reghacks.asp?tipnumb=6353
h)
http://www.microsoft.com/windows2000...pporttools.asp
i) http://www.somarsoft.com/
j) http://www.microsoft.com/technet/scr...er/scrff13.asp
k) http://www.windows2000faq.com/Articl...rticleID=14459
l) http://www.windows2000faq.com/Articl...rticleID=14842
m) http://setacl.sourceforge.net/
n) http://www.microsoft.com/technet/scriptcenter

While I may have misread or misunderstood some of these, my
experience/reaction to each of these links follows:

Link (a) was to a technet script center, which I'm working my way through.
Link (b) 404 Location Cannot Be Found
Link (c) was to a forum thread re Enumerating Share Permissions. While that
may be useful for other purposes, it doesn't tell me how to set those
permissions in the first place (or how to create the share).
Link (d) 404 Location Cannot Be Found
Link (e) was to a forum thread from 2001 re using wmi to add a user to a
share folder. While this might be useful to me (and answers a question that
perhaps I should have asked), it doesn't address how to implement the
approach in VB.NET.
Link (f) was to a forum post re Setting security on all shares. While
perhaps relevant, again it's not VB.NET.
Link (g) was to a page linking to a download of Microsoft's public domain
RMTShar.exe for remotely sharing a number of resources. I'm not sure I need
the remote part of this, and I need to set up the share and permissions from
within my VB.NET program.
Link (h) was to a page for Win2K Support Tools. I haven't tried these yet,
but my impression was that they don't address my need to do this from within
my VB.NET program.
Link (i) was to a product page for a free utility to dump security settings.
I don't currently need to do that. There also was a link on that page to a
product page for a (non-free) utility that may do what I need, but not from
within my VB.NET program.
Link (j) linked me to the same technet script center I found from link (a)
Link (k) was to a forum post suggesting how to use RMTShar.exe (see link
(g)) to do what I need, but from a command line. Is it really necessary (or
simpler) to shell out to a command line program to get this done??
Link (l) was to a forum post suggesting a way to create a share from the
command line, again not from a VB.NET program.
Link (m) was to a product page for SETACL, a tool to manage permissions.
While I can probably figure out how to use this from a VB.NET program, I
scanned their documentation and was unable to find a way to create a share.
(I might have missed something.)
Link (n) again linked me to the same technet script center I found from link
(a) and link (j)

- Jeff
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:V8**************@cpmsftngxa10.phx.gbl...
Hi Jeff,

I think you may try to use the WMI approach to do the job.
Here is a useful google link you may take a look.
http://groups.google.com/groups?hl=z...0F8E6.1BF1456A %40hydro.com

In .net we can use the System.Management to manipulate the WMI.
Code: Finding the Amount of Disk Space Available (Visual Basic)
http://msdn.microsoft.com/library/de...us/dv_vbcode/h tml/vbtskCodeFindingAmountOfDiskSpaceAvailableVisualBa sic.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #5
Hi Jeff,

I am sorry if I have made any confusion.
Here goes the code. Please take a look at the comments in the code.
Basically we need to read the links below to achieve the job.

How to use the Win32_Share to create network share
Win32_Share
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
win32_share.asp
Create Method of the Win32_Share Class
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
create_method_in_class_win32_share.asp

How to set the security account
Win32_ACE
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
win32_ace.asp
Win32_Trustee
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
win32_trustee.asp

How to locate a user account by ldap path
LDAP ADsPath
http://msdn.microsoft.com/library/de...us/adsi/adsi/l
dap_adspath.asp
<code>
Imports System.Management
Imports System.DirectoryServices
Module Module1
Sub Main()
Dim serverName, UserName, AdminName, UserAcct As String
Dim Ace1 As Management.ManagementObject
serverName = "TestServer"
Dim scope As New
Management.ManagementScope("\\serverName\root\cimv 2")
'Win32_Share

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi
/win32_share.asp
Dim wmiShare As New Management.ManagementClass(scope, New
Management.ManagementPath("Win32_Share"), Nothing)
'Define the LDAP path to the desired user account.
'LDAP ADsPath

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/
ldap_adspath.asp
UserAcct = "CN=Jeff Smith,CN=users,DC=fabrikam,DC=com"
'Get the user's information from the Active Directory
Dim UserNamePath As String = "LDAP://" & UserAcct
Dim DirEnt As New DirectoryServices.DirectoryEntry(UserNamePath)
'Get the User's SID and samAccountname. It will be used when
creating the DACL
UserName = DirEnt.Properties("samaccountname")(0)
Dim UserSID As Byte() = DirEnt.Properties("objectsid")(0)
DirEnt.Dispose()

'Set an ACE for the user
Ace1 = SetAce(scope, 2032127, 3, 0, SetTrustee(scope, serverName,
UserName, UserSID))

'Place the aces into a Win32_SecurityDescriptor
Dim secDescriptor As Management.ManagementObject
secDescriptor = New Management.ManagementClass(scope, New
Management.ManagementPath("Win32_SecurityDescripto r"),
Nothing).CreateInstance()
secDescriptor("ControlFlags") = 4
secDescriptor("DACL") = New Management.ManagementObject() {Ace1}

'Prepare to invoke the CREATE method on Win32_Share by specifying
the parameters
Dim inParams As Management.ManagementBaseObject
inParams = wmiShare.GetMethodParameters("Create")
inParams("Access") = secDescriptor
inParams("Path") = "C:\TestFolder"
inParams("Name") = "TestFolder"
inParams("Type") = 0
inParams("Description") = "FolderDescriptionHere"
Dim outParams As Management.ManagementBaseObject
'Invoke the CREATE method and create the share.
'Create Method of the Win32_Share Class

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi
/create_method_in_class_win32_share.asp
outParams = wmiShare.InvokeMethod("Create", inParams, Nothing)
End Sub

Function SetTrustee(ByVal scope As Management.ManagementScope, ByVal
domain As String, ByVal name As String, ByVal UserSid As Byte()) As
Management.ManagementObject
Dim wmiTrustee As Management.ManagementObject
'Win32_Trustee

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi
/win32_trustee.asp
wmiTrustee = New Management.ManagementClass(scope, New
Management.ManagementPath("Win32_Trustee"), Nothing).CreateInstance()
wmiTrustee("Domain") = domain
wmiTrustee("Name") = name
wmiTrustee("SID") = UserSid
Return wmiTrustee
End Function

Function SetAce(ByVal scope As Management.ManagementScope, ByVal
accessMask As Integer, ByVal aceFlags As Integer, ByVal aceType As Integer,
ByVal wmiTrustee As Management.ManagementObject) As
Management.ManagementObject
Dim wmiAce As Management.ManagementObject
'Win32_ACE

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi
/win32_ace.asp
wmiAce = New Management.ManagementClass(scope, New
Management.ManagementPath("Win32_ACE"), Nothing).CreateInstance()
wmiAce("AccessMask") = accessMask
wmiAce("AceFlags") = aceFlags
wmiAce("AceType") = aceType
wmiAce("Trustee") = wmiTrustee
Return wmiAce
End Function
End Module

</code>

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #6
For starters, the code sample is great. I was looking for the same
information myself. Now, I was wondering if you could shed a little
light on something. I need to apply permissions to a share but not
for a specific user. I need to assign "Full Access" to the
"Authenticated Users" group. I can assign permisions to a specific
user without issues, but I think "Authenticated Users" is a special
case. I was able to get it to work with "Everyone" but not
"Authenticated Users".

Can you help out?

Thanks
v-******@online.microsoft.com ("Peter Huang") wrote in message news:<cl*************@cpmsftngxa10.phx.gbl>...
Hi Jeff,

I am sorry if I have made any confusion.
Here goes the code. Please take a look at the comments in the code.
Basically we need to read the links below to achieve the job.

How to use the Win32_Share to create network share
Win32_Share
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
win32_share.asp
Create Method of the Win32_Share Class
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
create_method_in_class_win32_share.asp

How to set the security account
Win32_ACE
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
win32_ace.asp
Win32_Trustee
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
win32_trustee.asp

How to locate a user account by ldap path
LDAP ADsPath
http://msdn.microsoft.com/library/de...us/adsi/adsi/l
dap_adspath.asp
<code>
Imports System.Management
Imports System.DirectoryServices
Module Module1
Sub Main()
Dim serverName, UserName, AdminName, UserAcct As String
Dim Ace1 As Management.ManagementObject
serverName = "TestServer"
Dim scope As New
Management.ManagementScope("\\serverName\root\cimv 2")
'Win32_Share

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi
/win32_share.asp
Dim wmiShare As New Management.ManagementClass(scope, New
Management.ManagementPath("Win32_Share"), Nothing)
'Define the LDAP path to the desired user account.
'LDAP ADsPath

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/
ldap_adspath.asp
UserAcct = "CN=Jeff Smith,CN=users,DC=fabrikam,DC=com"
'Get the user's information from the Active Directory
Dim UserNamePath As String = "LDAP://" & UserAcct
Dim DirEnt As New DirectoryServices.DirectoryEntry(UserNamePath)
'Get the User's SID and samAccountname. It will be used when
creating the DACL
UserName = DirEnt.Properties("samaccountname")(0)
Dim UserSID As Byte() = DirEnt.Properties("objectsid")(0)
DirEnt.Dispose()

'Set an ACE for the user
Ace1 = SetAce(scope, 2032127, 3, 0, SetTrustee(scope, serverName,
UserName, UserSID))

'Place the aces into a Win32_SecurityDescriptor
Dim secDescriptor As Management.ManagementObject
secDescriptor = New Management.ManagementClass(scope, New
Management.ManagementPath("Win32_SecurityDescripto r"),
Nothing).CreateInstance()
secDescriptor("ControlFlags") = 4
secDescriptor("DACL") = New Management.ManagementObject() {Ace1}

'Prepare to invoke the CREATE method on Win32_Share by specifying
the parameters
Dim inParams As Management.ManagementBaseObject
inParams = wmiShare.GetMethodParameters("Create")
inParams("Access") = secDescriptor
inParams("Path") = "C:\TestFolder"
inParams("Name") = "TestFolder"
inParams("Type") = 0
inParams("Description") = "FolderDescriptionHere"
Dim outParams As Management.ManagementBaseObject
'Invoke the CREATE method and create the share.
'Create Method of the Win32_Share Class

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi
/create_method_in_class_win32_share.asp
outParams = wmiShare.InvokeMethod("Create", inParams, Nothing)
End Sub

Function SetTrustee(ByVal scope As Management.ManagementScope, ByVal
domain As String, ByVal name As String, ByVal UserSid As Byte()) As
Management.ManagementObject
Dim wmiTrustee As Management.ManagementObject
'Win32_Trustee

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi
/win32_trustee.asp
wmiTrustee = New Management.ManagementClass(scope, New
Management.ManagementPath("Win32_Trustee"), Nothing).CreateInstance()
wmiTrustee("Domain") = domain
wmiTrustee("Name") = name
wmiTrustee("SID") = UserSid
Return wmiTrustee
End Function

Function SetAce(ByVal scope As Management.ManagementScope, ByVal
accessMask As Integer, ByVal aceFlags As Integer, ByVal aceType As Integer,
ByVal wmiTrustee As Management.ManagementObject) As
Management.ManagementObject
Dim wmiAce As Management.ManagementObject
'Win32_ACE

'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi
/win32_ace.asp
wmiAce = New Management.ManagementClass(scope, New
Management.ManagementPath("Win32_ACE"), Nothing).CreateInstance()
wmiAce("AccessMask") = accessMask
wmiAce("AceFlags") = aceFlags
wmiAce("AceType") = aceType
wmiAce("Trustee") = wmiTrustee
Return wmiAce
End Function
End Module

</code>

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Keith Smith | last post by:
Are there any alternatives to sharing a database without creating a shared folder? I guess I could create a client/server app, but I'm trying to avoid that. On the other hand, I am also trying to...
2
by: Dan Baker | last post by:
I'm relatively new to the .cs world. I would like to have some "shared" .cs files, which several solutions can use. I don't want to place these in a ..dll, I simply want them included into...
2
by: baldwin | last post by:
Hello, We are going to have a web application that will be load balanced. Uploading documents into the same server is not an option. So we need to create a shared folder in a different machine...
6
by: jzdeng | last post by:
Hi, All I use VS 2005 to create a web service. The web service is used to create a sheared folder. It works fine we I run it from VS 2005. But, when I move it to inetpub, it does not work...
7
by: Zeb | last post by:
Hi all I've developed a shopping cart in C# and to allow moderators to upload product images, news images and downloadable PDFs, the app creates a folder for each product. I start out with the...
2
by: Daniel Knöpfel | last post by:
Hi In my application i need to do the following things concerning shared folders: - check if a folder is shared - share a folder - unshare a folder It seems to me that .net does not...
0
by: =?Utf-8?B?TGlhbSBNYWM=?= | last post by:
Hi Folks, I have embeded WMI scripting within a Visual Basic application to create remote shares and set permissions, I'm now moving to vb.net environment and having trouble getting my scripting...
1
by: twdo | last post by:
OK. I am totally frustrated here. I have a setup project within Visual Studio. That setup project is calling a class library project by the use of Custom Actions. Within that class library (my...
1
by: Alan Zaitchik | last post by:
I need to create a shared folder on a Windows 2003 Server platform. I have seen some VB scripts that do this, but I have to do this from within PHP (v 5.2). Also, the folder must be restricted to...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.