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

Add group or user to share via vbscript almost there but...

Status
Not open for further replies.

DvZ73

IS-IT--Management
Nov 3, 2013
16
NL
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
 
What happens when you make it a sub ?
Any error message ?
BTW, are you sure your main script call the Sub ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
what happens nothing happens, no error or something
Just the group mentioned is not added to the remote share
and when i run this script without sub it does add the group to the remote share

Somewhere when i make it a sub it loses arguments it needs in the function is my gueass but can;t figure out how to fix it
 
Again, are you sure the main script calls the Sub ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes, it's called
the script works standalone as i copied it here

but when i uncomment the "sub adtoshare" and Call adtoshare()
or when i run it standalone with the sub and call directly in it, it doesn't work
 
What is sd ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You set me thinking, and i was in the wrong way ansd place
it had to do with calling the sub
i called it without the correct parameters
needed to set computer while computer was set after the sub

thx for the help and getting me in the right direction PHV
Fantastic :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top