我的任务是创建一个vbs来执行以下操作: 如果存在NewAdmin,则为NewAdmin设置密码并禁用本地管理员帐户 否则将本地管理员帐户重命名为NewAdmin并设置密码。
再次感谢您的快速回复。我已经相应地更改了下面的代码,现在我正在尝试使用Windows脚本编码器来混淆密码。我知道仍然存在风险,因为这可以解码,但脚本不会存储在用户的计算机上,因此不会构成太大的威胁。
现在,代码显示了Windows脚本编码器执行此任务所需的三行,但我无法使其工作。我从命令行运行以下命令:
screnc / l vbscript admin_script.vbs admin_script.vbe
它成功创建了admin_script.vbe。但是当我尝试运行编码脚本时,它会显示以下错误消息:
Script: C:\...\admin_script.vbe
Line: 2
Char: 1
Error: Expected Statement
Code: 800A0400
Source: Microsoft VBscript compilation error
未编码的脚本运行没有问题。我已经尝试了另一种使用位于网上的vbscript来编码数据的方法,但它做了同样的事情......模糊了数据,但脚本没有工作。我还读到它可能是一个编码问题,我需要将vbs保存为没有BOM的UTF-8,但这也不起作用。
如果有人知道如何使这个Windows脚本编码器工作,我将非常感激。此外,如果有另一种加密/混淆代码的方法,欢迎提出任何建议。我会说我不是从VBS创建可执行文件的忠实粉丝,但如果有必要,我会采取这种做法。
<SCRIPT LANGUAGE="VBScript">
'**Start Encode**
OPTION EXPLICIT
DIM objNetwork, objUser, objComputer
DIM strPassword, strAdminUserName, strNewAdminUserName, strComputer, strUser
' Get Computer Name and make it all uppercase
SET objNetwork = CREATEOBJECT("Wscript.Network")
strComputer = UCASE(objNetwork.ComputerName)
' Setting veriable for IF statement
strUser= "NewAdmin"
' The old name of the administrator user account (normally administrator)
strAdminUserName = "Administrator"
' The new name of the administrator user account
strNewAdminUserName = "NewAdmin"
' New Password for administrator account.
strPassword = "passwordhere"
On Error Resume Next
Set objUser = GetObject("WinNT://" & strComputer & "/" & strUser & ",user")
If (Err.Number = 0) Then
On Error GoTo 0
' Set password of admin user account
setPWD strComputer,strNewAdminUserName,strPassword
' Disable Local Administrator account
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator, user")
objUser.AccountDisabled = True
objUser.SetInfo
Else
On Error GoTo 0
' Rename admin user account
renameUser strComputer,strAdminUserName,strNewAdminUserName
' Set password of admin user account
setPWD strComputer,strNewAdminUserName,strPassword
End If
' enter code hereReset password for a local user account on a given computer
SUB setPWD(strComputer,strUser,strPassword)
DIM objUser
' Ignore error if user account isn't found or error changing password
ON ERROR RESUME NEXT
SET objUser = GETOBJECT("WinNT://" & strComputer & "/" & strUser & ",user")
IF err.number = 0 THEN
objUser.SetPassword strPassword
objUser.SetInfo
END IF
ON ERROR GOTO 0
END SUB
' Rename a local user account on a given computer
SUB renameUser(strComputer,strFromName, strToName)
DIM objComputer,objUser
' Ignore error if user account isn't found or error moving user
ON ERROR RESUME NEXT
SET objComputer = GETOBJECT("WinNT://" & strComputer)
SET objUser = GETOBJECT("WinNT://" & strComputer & "/" & strFromName & ",user")
IF err.number = 0 THEN
objComputer.MoveHere objUser.ADsPath,strToName
END IF
ON ERROR GOTO 0
END SUB
</SCRIPT>
答案 0 :(得分:0)
更改此
If (Err.Number <> 0) Then
到这个
If (Err.Number = 0) Then