Hi all,
my first post and first question, hope i can help others as they hopefully gonna help me
the following code is working but i need it to be part of some more code
so it works untill i make it a sub, and can't figure out what argument i'm missing after it's a sub
If someone can help me to get it working in a sub routine it would be famtastic
'Sub adtoshare
Const read = 1179817
computer = "server1"
username = "SG-group-test-Citrix-Support"
share = "TAM-Share"
domain = CreateObject("WScript.Network").UserDomain
' copy existing ACEs
Set objLocator = CreateObject("wbemscripting.swbemlocator")
Set wmi = objLocator.ConnectServer(Computer) 'THIS IS THE NAME OF THE COMPUTER YOU ARE SETTING PERMISSIONS ON
wmi.security_.impersonationlevel = 3
wmi.security_.privileges.AddAsString("SeSecurityPrivilege")
set shareSec = wmi.Get("Win32_LogicalShareSecuritySetting.Name='" & Share & "'")
rc = shareSec.GetSecurityDescriptor(sd)
flags = sd.ControlFlags
ReDim acl(UBound(sd.DACL)+1) '+1 for the new ACL we're going to add
For i = 0 To UBound(sd.DACL)
Set acl(i) = sd.DACL(i)
Next
Set sd = Nothing
' add new ACE
Set acl(UBound(acl)) = NewACE(NewTrustee(username, domain), Read)
' prepare new security descriptor
Set sd = wmi.Get("Win32_SecurityDescriptor").SpawnInstance_
sd.ControlFlags = flags
sd.DACL = acl
' assign new security descriptor
rc = shareSec.SetSecurityDescriptor(sd)
'End Sub 'adtoshare
Function NewTrustee(name, domain)
Dim trustee, account
set shareSec = wmi.Get("Win32_LogicalShareSecuritySetting.Name='" & Share & "'")
Set trustee = wmi.Get("Win32_Trustee").SpawnInstance_
trustee.Name = name
trustee.Domain = domain
set account = getObject("Winmgmts:{impersonationlevel=impersonate}!root/cimv2:Win32_Account.Name='" & Name & "',Domain='" & Domain &"'")
trustee.Properties_.Item("SID") = wmi.Get("Win32_SID.SID='" & account.SID _
& "'").BinaryRepresentation
Set NewTrustee = trustee
End Function
Function NewACE(trustee, permissions)
Dim ace1 : Set ace1 = wmi.Get("Win32_Ace").SpawnInstance_
ace1.Properties_.Item("AccessMask") = 1179817
ace1.Properties_.Item("AceFlags") = 3
ace1.Properties_.Item("AceType") = 0
ace1.Properties_.Item("Trustee") = trustee
Set NewACE = ace1
End Function
my first post and first question, hope i can help others as they hopefully gonna help me
the following code is working but i need it to be part of some more code
so it works untill i make it a sub, and can't figure out what argument i'm missing after it's a sub
If someone can help me to get it working in a sub routine it would be famtastic
'Sub adtoshare
Const read = 1179817
computer = "server1"
username = "SG-group-test-Citrix-Support"
share = "TAM-Share"
domain = CreateObject("WScript.Network").UserDomain
' copy existing ACEs
Set objLocator = CreateObject("wbemscripting.swbemlocator")
Set wmi = objLocator.ConnectServer(Computer) 'THIS IS THE NAME OF THE COMPUTER YOU ARE SETTING PERMISSIONS ON
wmi.security_.impersonationlevel = 3
wmi.security_.privileges.AddAsString("SeSecurityPrivilege")
set shareSec = wmi.Get("Win32_LogicalShareSecuritySetting.Name='" & Share & "'")
rc = shareSec.GetSecurityDescriptor(sd)
flags = sd.ControlFlags
ReDim acl(UBound(sd.DACL)+1) '+1 for the new ACL we're going to add
For i = 0 To UBound(sd.DACL)
Set acl(i) = sd.DACL(i)
Next
Set sd = Nothing
' add new ACE
Set acl(UBound(acl)) = NewACE(NewTrustee(username, domain), Read)
' prepare new security descriptor
Set sd = wmi.Get("Win32_SecurityDescriptor").SpawnInstance_
sd.ControlFlags = flags
sd.DACL = acl
' assign new security descriptor
rc = shareSec.SetSecurityDescriptor(sd)
'End Sub 'adtoshare
Function NewTrustee(name, domain)
Dim trustee, account
set shareSec = wmi.Get("Win32_LogicalShareSecuritySetting.Name='" & Share & "'")
Set trustee = wmi.Get("Win32_Trustee").SpawnInstance_
trustee.Name = name
trustee.Domain = domain
set account = getObject("Winmgmts:{impersonationlevel=impersonate}!root/cimv2:Win32_Account.Name='" & Name & "',Domain='" & Domain &"'")
trustee.Properties_.Item("SID") = wmi.Get("Win32_SID.SID='" & account.SID _
& "'").BinaryRepresentation
Set NewTrustee = trustee
End Function
Function NewACE(trustee, permissions)
Dim ace1 : Set ace1 = wmi.Get("Win32_Ace").SpawnInstance_
ace1.Properties_.Item("AccessMask") = 1179817
ace1.Properties_.Item("AceFlags") = 3
ace1.Properties_.Item("AceType") = 0
ace1.Properties_.Item("Trustee") = trustee
Set NewACE = ace1
End Function