Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Folder Security

74 views
Skip to first unread message

Thomas Dehm

unread,
Jun 12, 2002, 3:51:40 AM6/12/02
to
Hello,

I have found an german article in the "Microsoft Knowledge Base" about WMI.
(articlenumber D44834)
I use in my VB-project a part of this article. But my problem is that when I
have set a share the security settings are set on everyone. But I whant set
the security settings only on the current user. Who can help me?

Thanks, Thomas Dehm


The code is de original Code. For my projekt I have modified it.

Private Sub cmdAddShare_Click()

Dim objLocator As SWbemLocator
Dim objServices As SWbemServices
Dim objShare As SWbemObject
Dim lRet As Long

Set objLocator = New WbemScripting.SWbemLocator
Set objServices = objLocator.ConnectServer(txtPCName.Text)

Set objShare = objServices.Get("Win32_Share")

' Parameter der Create-Methode wie im WMI SDK beschrieben:
' 1. lokaler Pfad des freizugebenden Ordners
' 2. Freigabename
' 3. Art der Freigabe (0 = Disk)
' 4. Anzahl max. gleichzeitig verbundener Benutzer
' 5. Beschreibung des Shares

lRet = objShare.Create(txtPath.Text, txtShare.Text, 0, 5, "TestShare,
angelegt per WMI")
If lRet = 0 Then
Debug.Print "Success"
Else
Debug.Print "Error " & lRet
End If

Set objShare = Nothing
Set objServices = Nothing
Set objLocator = Nothing

End Sub


[MS] Tim Chen

unread,
Jun 12, 2002, 8:17:28 PM6/12/02
to
You need to construct a win32_securitydescriptor object and fill the
"Access" parameter of the Create method.

-Tim

This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"Thomas Dehm" <atd...@ulm.siemens.de> wrote in message
news:1023868301.663404@nbgm66x...

Thomas Dehm

unread,
Jun 13, 2002, 5:04:14 AM6/13/02
to
Hello Tim

Thank you for your posting. But I don't know how I can do this. Can you give
me an example or description how I can do this?

Thomas


"[MS] Tim Chen" <timch...@hotmail.com> schrieb im Newsbeitrag
news:3d07e497$1...@news.microsoft.com...

[MS] Tim Chen

unread,
Jun 13, 2002, 4:00:20 PM6/13/02
to
Here is a script that sets security setting on all shares on a computer.
it's not exactly what you need but most of the code is the same.

-Tim

This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Set objLocator = CreateObject("wbemscripting.swbemlocator")

'THIS IS THE NAME OF THE COMPUTER YOU ARE SETTING PERMISSIONS ON:
Set objServices = objLocator.ConnectServer("machinename")

'Get all the shares on the machine...
Set objShares = objServices.ExecQuery("SELECT Name FROM Win32_Share")

'Set permissions for each...

On Error Resume Next

for each objShare in objShares

set objShareSecSetting =
objServices.Get("Win32_LogicalShareSecuritySetting.Name='" & objShare.Name &
"'")


Set objSecDescriptor =
GetObject("Winmgmts:{impersonationlevel=impersonate}!root/cimv2:Win32_Securi
tyDescriptor").Spawninstance_()


'THE ARRAYS OF NUMBERS APPEARING BELOW ARE BINARY REPRESENTATIONS OF THE
ACCOUNT'S SID

objSecDescriptor.ControlFlags = 32772


set ACE1 = SetACE(2032127, _ '2032127 corresponds to full control for
shares
0, _
0, _
SetTrustee("MYCOMPUTER", _
"ADMINISTRATORS", _

Array(1,5,0,0,0,0,0,5,21,0,0,0,240,111,316,512,110,75,86,195,175,17,135,112,
137,232,0,0)))


set ACE2 = SetACE(1441961, _ '1441961 corresponds to read only for
shares
0, _
0, _
SetTrustee(NULL, _
"EVERYONE", _
Array(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)))

objSecDescriptor.DACL = Array(ACE1,ACE2)


returnval = objShareSecSetting.SetSecurityDescriptor(objSecDescriptor)

wscript.echo "Finished setting descriptor. Return code: " & returnval

next

wscript.echo "Done!"

'***************************************************************************
***************************************
Function SetTrustee(strDomain, strName, SID)
set objTrustee =
getObject("Winmgmts:{impersonationlevel=impersonate}!root/cimv2:Win32_Truste
e").Spawninstance_
objTrustee.Domain = strDomain
objTrustee.Name = strName
objTrustee.SID = SID
set SetTrustee = objTrustee
End Function

Function SetACE(AccessMask, AceFlags, AceType, objTrustee)
set objACE =
getObject("Winmgmts:{impersonationlevel=impersonate}!root/cimv2:Win32_Ace").
Spawninstance_
objACE.AccessMask = AccessMask
objACE.AceFlags = AceFlags
objACE.AceType = AceType
objACE.Trustee = objTrustee
set SetACE = objACE
End Function
'***************************************************************************
***************************************

"Thomas Dehm" <atd...@ulm.siemens.de> wrote in message

news:1023959054.874347@nbgm66x...

0 new messages