所以我对VBS完全不熟悉,从未使用它。我正在尝试创建多个共享,我发现可以执行此操作的Microsoft VBS脚本(http://gallery.technet.microsoft.com/scriptcenter/6309d93b-fcc3-4586-b102-a71415244712)我的问题是,此脚本仅允许添加一个域组或用户以获取我需要添加的权限一对具有不同权限的人(弄明白了)下面是我根据需要修改的脚本,但只需要在第二组中添加其他权限。如果有更简单的方法,请告诉我。
'ShareSetup.vbs
'==========================================================================
Option Explicit
Const FILE_SHARE = 0
Const MAXIMUM_CONNECTIONS = 25
Dim strComputer
Dim objWMIService
Dim objNewShare
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewShare = objWMIService.Get("Win32_Share")
Call sharesec ("C:\Published Apps\Logs01", "Logs01", "Log01", "Support")
Call sharesec2 ("C:\Published Apps\Logs01", "Logs01", "Log01", "Domain Admins")
Sub sharesec(Fname,shr,info,account)
'Fname = Folder path, shr = Share name, info = Share Description, account = account or group you are assigning share permissions to
Dim FSO
Dim Services
Dim SecDescClass
Dim SecDesc
Dim Trustee
Dim ACE
Dim Share
Dim InParam
Dim Network
Dim FolderName
Dim AdminServer
Dim ShareName
FolderName = Fname
AdminServer = "\\" & strComputer
ShareName = shr
Set Services = GetObject("WINMGMTS:{impersonationLevel=impersonate,(Security)}!" & AdminServer & "\ROOT\CIMV2")
Set SecDescClass = Services.Get("Win32_SecurityDescriptor")
Set SecDesc = SecDescClass.SpawnInstance_()
'Set Trustee = Services.Get("Win32_Trustee").SpawnInstance_
'Trustee.Domain = Null
'Trustee.Name = "EVERYONE"
'Trustee.Properties_.Item("SID") = Array(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
Set Trustee = SetGroupTrustee("domain", account) 'Replace ACME with your domain name.
'To assign permissions to individual accounts use SetAccountTrustee rather than SetGroupTrustee
Set ACE = Services.Get("Win32_Ace").SpawnInstance_
ACE.Properties_.Item("AccessMask") = 1179817
ACE.Properties_.Item("AceFlags") = 3
ACE.Properties_.Item("AceType") = 0
ACE.Properties_.Item("Trustee") = Trustee
SecDesc.Properties_.Item("DACL") = Array(ACE)
Set Share = Services.Get("Win32_Share")
Set InParam = Share.Methods_("Create").InParameters.SpawnInstance_()
InParam.Properties_.Item("Access") = SecDesc
InParam.Properties_.Item("Description") = "Public Share"
InParam.Properties_.Item("Name") = ShareName
InParam.Properties_.Item("Path") = FolderName
InParam.Properties_.Item("Type") = 0
Share.ExecMethod_ "Create", InParam
End Sub
Sub sharesec2(Fname,shr,info,account)
'Fname = Folder path, shr = Share name, info = Share Description, account = account or group you are assigning share permissions to
Dim FSO
Dim Services
Dim SecDescClass
Dim SecDesc
Dim Trustee
Dim ACE2
Dim Share
Dim InParam
Dim Network
Dim FolderName
Dim AdminServer
Dim ShareName
FolderName = Fname
AdminServer = "\\" & strComputer
ShareName = shr
Set Services = GetObject("WINMGMTS:{impersonationLevel=impersonate,(Security)}!" & AdminServer & "\ROOT\CIMV2")
Set SecDescClass = Services.Get("Win32_SecurityDescriptor")
Set SecDesc = SecDescClass.SpawnInstance_()
'Set Trustee = Services.Get("Win32_Trustee").SpawnInstance_
'Trustee.Domain = Null
'Trustee.Name = "EVERYONE"
'Trustee.Properties_.Item("SID") = Array(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
Set Trustee = SetGroupTrustee("domain", account) 'Replace ACME with your domain name.
'To assign permissions to individual accounts use SetAccountTrustee rather than SetGroupTrustee
Set ACE2 = Services.Get("Win32_Ace").SpawnInstance_
ACE2.Properties_.Item("AccessMask") = 1179817
ACE2.Properties_.Item("AceFlags") = 3
ACE2.Properties_.Item("AceType") = 0
ACE2.Properties_.Item("Trustee") = Trustee
SecDesc.Properties_.Item("DACL") = Array(ACE2)
End Sub
Function SetAccountTrustee(strDomain, strName)
set objTrustee = getObject("Winmgmts: {impersonationlevel=impersonate}!root/cimv2:Win32_Trustee").Spawninstance_
set account = getObject("Winmgmts: {impersonationlevel=impersonate}!root/cimv2:Win32_Account.Name='" & strName & "',Domain='" & strDomain &"'")
set accountSID = getObject("Winmgmts: {impersonationlevel=impersonate}!root/cimv2:Win32_SID.SID='" & account.SID &"'")
objTrustee.Domain = strDomain
objTrustee.Name = strName
objTrustee.Properties_.item("SID") = accountSID.BinaryRepresentation
set accountSID = nothing
set account = nothing
set SetAccountTrustee = objTrustee
End Function
Function SetGroupTrustee(strDomain, strName)
Dim objTrustee
Dim account
Dim accountSID
set objTrustee = getObject("Winmgmts: {impersonationlevel=impersonate}!root/cimv2:Win32_Trustee").Spawninstance_
set account = getObject("Winmgmts:{impersonationlevel=impersonate}!root/cimv2:Win32_Group.Name='" & strName & "',Domain='" & strDomain &"'")
set accountSID = getObject("Winmgmts: {impersonationlevel=impersonate}!root/cimv2:Win32_SID.SID='" & account.SID &"'")
objTrustee.Domain = strDomain
objTrustee.Name = strName
objTrustee.Properties_.item("SID") = accountSID.BinaryRepresentation
set accountSID = nothing
set account = nothing
set SetGroupTrustee = objTrustee
End Function
答案 0 :(得分:1)
我认为您会发现使用icacls而不是在共享级别使用VBS编写NTFS级别的权限更容易,并且只需在VBScript中为所有用户分配完全访问权限。
您可能还希望使用PowerShell来创建共享,这里有一些指导:http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/16/how-to-use-powershell-to-create-shared-folders-in-windows-7.aspx
将来我们可以使用cmdlet new-smbshare在powershell中执行此操作:-) http://technet.microsoft.com/en-us/library/jj635726.aspx
答案 1 :(得分:1)
Call sharesec ("C:\Published Apps\Logs01", "Logs01", "Log01", "Support")
Call sharesec2 ("C:\Published Apps\Logs01", "Logs01", "Log01", "Domain Admins")
由于某些原因,我假设您出于某些奇怪的原因创建了额外的函数sharesec2
,但这是错误的。您基本上是尝试两次创建共享。这没有意义。复制该功能无效。
你真正需要做的是重新开始这项功能。例如,您可以更改sharesec
的第四个参数,以便它接受一个数组。然后,您需要遍历阵列并为共享构建自主访问控制列表(DACL)。每个用户/组有一个访问控制条目(ACE)。
我不会为你编写代码,因为我厌恶VBS,但是这部分会想要遍历这一部分并构建DACL。
' loop over the list of users
` create ACE for single user/group
Set Trustee = SetGroupTrustee("domain", account) 'Replace ACME with your domain name.
'To assign permissions to individual accounts use SetAccountTrustee rather than SetGroupTrustee
Set ACE2 = Services.Get("Win32_Ace").SpawnInstance_
ACE2.Properties_.Item("AccessMask") = 1179817
ACE2.Properties_.Item("AceFlags") = 3
ACE2.Properties_.Item("AceType") = 0
ACE2.Properties_.Item("Trustee") = Trustee
` add ace to an array that represents the dacl
` end loop
` add the DACL_array
SecDesc.Properties_.Item("DACL") = DACL_array
无论如何,我强烈建议你看看Powershell。