VBScript WSHell.运行多个进程
有谁知道我如何才能完成以下任务: 我有一个脚本,它将运行并获取 AD 中分配了 homedir 的所有用户,并重置此文件夹及其下所有内容的权限。问题是,它需要很长时间才能完成,如果我不将 .run 变量设置为 Wait on return to true,我最终会运行数千个 cacls 进程。我想将进程数量限制为 50 个,一旦一个进程完成,就继续处理下一个用户。该脚本非常简单:
' Get Users Home Directories from AD
' Then grant Administrators FULL CONTROL and the USER MODIFY ONLY
'
Set WshShell = WScript.CreateObject("WScript.Shell")
'
' Get users with home directories
WScript.Echo "Retrieving user account names and home directories from active directory. . ."
Set objWMIService = GetObject("winmgmts:root\directory\ldap")
Set colItems = objWMIService.ExecQuery("Select ds_sAMAccountName, ds_homeDirectory From ds_user WHERE ds_homeDirectory IS NOT NULL")
WScript.Echo ""
' Loop through users setting permissions
For Each oUser in colItems
WScript.Echo "Setting permissions for " & oUser.ds_sAMAccountName & " Directory " & oUser.ds_homeDirectory
WshShell.Run "xcacls " & oUser.ds_homeDirectory & " /y /t /g Administrators:F", 0, True
WshShell.Run "xcacls " & oUser.ds_homeDirectory & " /e /t /g " & oUser.ds_sAMAccountName & ":C", 0, True
Next
有人知道我该怎么做吗?
谢谢
编辑:::: 我想我已经弄清楚了...
For Each oUser in colItems
numrunning = HowMany
while numrunning > 25
WScript.Echo "Waiting for other processes to finish"
WScript.Sleep 10000
numrunning = HowManyRunning
wend
WScript.Echo "Setting permissions for " & oUser.ds_sAMAccountName & " Directory " & oUser.ds_homeDirectory
WshShell.Run "xcacls " & oUser.ds_homeDirectory & " /y /t /g Administrators:F", 0, False
WshShell.Run "xcacls " & oUser.ds_homeDirectory & " /e /t /g " & oUser.ds_sAMAccountName & ":C", 0, False
Next
Function HowManyRunning()
Dim Proc1,Proc2,Proc3
Set Proc1 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set Proc2 = Proc1.ExecQuery("select * from win32_process" )
HowMany=0
For Each Proc3 in Proc2
If LCase(Proc3.Caption) = "xcacls.exe" Then
HowMany=HowMany + 1
End If
Next
End Function
Does anyone know how I can accomplish the following:
I have a script that will run and get all users from AD with a homedir assigned and reset the permissions on this folder and everything under it. The problem is, it takes a very long time to complete and if I don't set the .run variable for Wait on return to true, I end up with thousands of cacls processes running. I want to limit the number of processes to say 50, and once one process finishes, move on to the next user. The script is really simple:
' Get Users Home Directories from AD
' Then grant Administrators FULL CONTROL and the USER MODIFY ONLY
'
Set WshShell = WScript.CreateObject("WScript.Shell")
'
' Get users with home directories
WScript.Echo "Retrieving user account names and home directories from active directory. . ."
Set objWMIService = GetObject("winmgmts:root\directory\ldap")
Set colItems = objWMIService.ExecQuery("Select ds_sAMAccountName, ds_homeDirectory From ds_user WHERE ds_homeDirectory IS NOT NULL")
WScript.Echo ""
' Loop through users setting permissions
For Each oUser in colItems
WScript.Echo "Setting permissions for " & oUser.ds_sAMAccountName & " Directory " & oUser.ds_homeDirectory
WshShell.Run "xcacls " & oUser.ds_homeDirectory & " /y /t /g Administrators:F", 0, True
WshShell.Run "xcacls " & oUser.ds_homeDirectory & " /e /t /g " & oUser.ds_sAMAccountName & ":C", 0, True
Next
Does anyone have any idea how I can do this?
Thanks
Edit::::
I think i got it figured out...
For Each oUser in colItems
numrunning = HowMany
while numrunning > 25
WScript.Echo "Waiting for other processes to finish"
WScript.Sleep 10000
numrunning = HowManyRunning
wend
WScript.Echo "Setting permissions for " & oUser.ds_sAMAccountName & " Directory " & oUser.ds_homeDirectory
WshShell.Run "xcacls " & oUser.ds_homeDirectory & " /y /t /g Administrators:F", 0, False
WshShell.Run "xcacls " & oUser.ds_homeDirectory & " /e /t /g " & oUser.ds_sAMAccountName & ":C", 0, False
Next
Function HowManyRunning()
Dim Proc1,Proc2,Proc3
Set Proc1 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set Proc2 = Proc1.ExecQuery("select * from win32_process" )
HowMany=0
For Each Proc3 in Proc2
If LCase(Proc3.Caption) = "xcacls.exe" Then
HowMany=HowMany + 1
End If
Next
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论