安全权限的脚本

时间:2011-12-12 15:31:28

标签: vbscript batch-file cmd

我想编写两个脚本,它们可以是vbs或ms-dos命令。

首先是设置文件夹的用户权限(相当于:右键单击文件夹,属性,安全性,编辑,添加,NT AUTHORITY\NETWORK SERVICE)。

其次是设置permision作为服务运行,等效点击是:Control Panel / Administrative Tools / Local Security Policy;左侧:Local Policies / User Rights Assignment;右侧:Log on as a service -> add Network Service作为拥有权利的用户。

请问有人帮我这么做吗?

2 个答案:

答案 0 :(得分:1)

ms dos命令:

文件夹权限:

CACLS path_of_folder /E /T /C /G "userName":F

cacls command details

以服务权限登录:

ntrights -u "userName" +r SeServiceLogonRight

ntrights command details

答案 1 :(得分:0)

令人沮丧的是,我们没有适用于Windows Server 2008及更高版本的ntrights工具。我已经提出了一个有效的vbscript。

Username = <domain\username>
Dim oShell 
Set oShell = CreateObject ("WScript.Shell")
oShell.Run "secedit /export /cfg config.inf", 0, true 
oShell.Run "secedit /import /cfg config.inf /db database.sdb", 0, true

FileName = "config.inf"
OrgStr = "SeServiceLogonRight ="
RepStr = "SeServiceLogonRight = " & Username & ","
Set inputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile("config.inf", 1,1,-1)
strInputFile = inputFile.ReadAll
inputFile.Close
Set inputFile = Nothing

Set outputFile =   CreateObject("Scripting.FileSystemObject").OpenTextFile("config.inf",2,1,-1)
outputFile.Write (Replace(strInputFile,OrgStr,RepStr))
outputFile.Close
Set outputFile = Nothing

oShell.Run "secedit /configure /db database.sdb /cfg config.inf",0,true
set oShell= Nothing

Set obj = CreateObject("Scripting.FileSystemObject")
obj.DeleteFile("config.inf") 
obj.DeleteFile("database.sdb")