【问题标题】:Scripts for security permissions安全权限脚本
【发布时间】:2011-12-12 15:31:28
【问题描述】:

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

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

第二个是设置权限作为服务运行,相当于点击点击是:Control Panel / Administrative Tools / Local Security Policy;左侧:Local Policies / User Rights Assignment;右侧:Log on as a service -> add Network Service 作为有权限的用户。

有人能帮我做吗?

【问题讨论】:

    标签: vbscript batch-file cmd


    【解决方案1】:

    ms dos 命令:

    文件夹权限:

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

    cacls command details

    作为服务登录权限:

    ntrights -u "userName" +r SeServiceLogonRight
    

    ntrights command details

    【讨论】:

    • 我会推荐 icacls 而不是 cacls,因为它还能够处理继承和更改所有权。
    【解决方案2】:

    这太令人沮丧了,我们没有适用于 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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-25
      • 2012-06-07
      • 1970-01-01
      • 2011-10-02
      • 2011-05-24
      • 1970-01-01
      • 2014-08-04
      • 2021-09-24
      相关资源
      最近更新 更多