我需要创建一个 .VBS 脚本来重置一大群计算机上的 Windows 本地管理员密码。我的问题是,出于安全原因,我们的一些网站已重命名管理员帐户。有没有人有一个脚本可以根据原始管理员帐户的 SID 更改管理员帐户的密码?

有帮助吗?

解决方案

使用的事实,本地管理的SID总是与-500结束时:

strComputer="."    ' local computer by default   
Set objUser=GetObject("WinNT://" & strComputer & "/" & GetAdminName & ",user")     
objUser.SetPassword "New local admin password"     
objUser.SetInfo 

Function GetAdminName   
  'This function was written using information from Table J.1 from the Windows XP resource Kit
  'http://www.microsoft.com/resources/documentation/Windows/XP/all/reskit/en-us/Default.asp?url=/resources/documentation/Windows/XP/all/reskit/en-us/prnc_sid_cids.asp

  Set objNetwork = CreateObject("Wscript.Network") 'get the current computer name 
  objComputerName = objNetwork.ComputerName    
  Set objwmi = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & objComputerName)

  qry = "SELECT * FROM Win32_Account where Domain = '" & cstr(objComputerName) & "'" 
  'set query, making sure to only look at local computer

  For Each Admin in objwmi.ExecQuery(qry)   
    if (left(admin.sid, 6) = "S-1-5-" and right(admin.sid,4) = "-500") then 'look for admin sid
       GetAdminName = admin.name
    end if   
  next    
end Function

其他提示

有漂浮的地方称为LookupAccountName工具(与来源!),鉴于内置adminitrator的SID会给你它的名字。

您很可能会落得写C ++代码来完成这件事还算不错。

就像 Joshua 所说,我认为你不能只使用 Windows 脚本主机来做到这一点,你可以使用它下载一些东西并执行它:

  • 调用 LookupAccountSid(S-1-5-domain-500 SID 或枚举管理员组)+NetUserSetInfo 来重置密码的自定义应用程序(需要以管理员身份运行)
  • http://home.eunet.no/pnordahl/ntpasswd/ (开机时重置)
  • 转储 SAM 哈希值并破解密码(Cain、John the Ripper、L0phtCrack 等)

@ DmitryK的回答是好,我不知道任何东西。但我知道,这样的事情通常是在PowerShell的清洁,所以我把它移植。

例如,整个GetAdminName函数可以写成:

$adminName = (gwmi win32_account | ? { $.SID.StartsWith( 'S-1-5-' ) -and $.SID.EndsWith( '-500' ) }).Name

(添加-ComputerName选项将gwmi呼叫要做到这一点的服务器上。)

的其余部分变为:

$user = ([ADSI]"WinNT://$($env:COMPUTERNAME)/$adminName,User")
$user.SetPassword( 'xxx' )
$user.SetInfo()

(应用根据需要当然,适当的计算机的名称。)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top