|
alashan
新手上路
积分 9
发帖 4
注册 2006-10-24
状态 离线
|
『楼 主』:
非常着急,在线等,各位老大看看这个VBS脚本
─────────────────── 版务记录 ────────────────────
执行人:lxmxn
原标题:非常着急,在线等,各位老大看看这个VBS脚本
说明:因标题表述过于模糊,不便于论坛的搜索和管理,请在三日内修改标题。
提示:修改标题请在当前帖的右下脚点 编辑,修改完毕之后按 编辑帖子 即可。
处罚:因属论坛新人,暂时不予处罚;若三日之后尚未修改标题,将扣除2点积分,
以示惩罚,并由版主强制修改标题。请点击这里阅读论坛发帖规定或者查看
提问的智慧,以避免在今后的讨论中违规发帖。
─────────────────── 版务记录 ────────────────────
'mwpq changed the script to ask user to chose their own password.
'16/9/2006
' --------------------------------------------------------
' ScriptingAnswers.com ScriptVault
' --------------------------------------------------------
' Entry title: Change admin password on multi computers
' Author: Don Jones
' E-mail: don@scriptinganswers.com
'
' Brief desscription:
' Reads a list of computer names from a file (one name per
' line), and changes the local Admin password on each.
'
'
'
' --------------------------------------------------------
' Version history:
' 1.0 02/17/2006 Initial release
'
' --------------------------------------------------------
' The user of this script accepts all responsibility For
' reviewing, testing, and using it, and specifically
' holds harmless ScriptingAnswers.com, SAPIEN Technologies,
' and the script's original author from any damages which
' result from the use of this script, including any
' direct, consequential, or indirect damages which may
' result.
' --------------------------------------------------------
' --------------------------------------------------------
' DOCUMENTED DEPENDENCIES
' Things this script relies on or assumes are already
' in place, apart from things which are built into
' WinXP or later:
' Relies on WinXP or Win2003.
' --------------------------------------------------------
' --------------------------------------------------------
' VARIABLE DECLARATIONS
' --------------------------------------------------------
Option Explicit
Dim strFile
Dim objFSO, objTS, strComputer
Dim strnewPass
strnewPass = InputBox ("Enter your password plz.",,"P@ssW0rd!")
' --------------------------------------------------------
' STATIC VARIABLE ASSIGNMENTS
' --------------------------------------------------------
strFile = "C:\computers.txt"
' --------------------------------------------------------
' MAIN SCRIPT CODE
' --------------------------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFile) Then
Set objTS = objFSO.OpenTextFile(strFile)
Do Until objTS.AtEndOfStream
strComputer = objTS.ReadLine
'do something with strComputer
If TestPing(strComputer) Then
On Error Resume Next
Dim objAdmin
Set objAdmin = GetObject("WinNT:\\" & strComputer & "\Administrator,user")
If Err = 0 Then
objAdmin.SetPassword strnewPass
'objAdmin.SetPassword "P@ssw0rd!"
objAdmin.SetInfo
Else
WScript.Echo strComputer & " skipped: " & _
Err.Description
End If
On Error GoTo 0
End If
Loop
End If
objTS.Close
WScript.Echo "Complete"
' --------------------------------------------------------
' SUBS AND FUNCTIONS
' --------------------------------------------------------
Function TestPing(sName)
Dim cPingResults, oPingResult
Verbose " Pinging " & sName
Set cPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery("SELECT * FROM Win32_PinStatus WHERE Address = '" & sName & "'")
For Each oPingResult In cPingResults
If oPingResult.StatusCode = 0 Then
TestPing = True
Else
TestPing = False
End If
Next
End Function
根本无法执行,老是提示错误
[ Last edited by lxmxn on 2007-4-27 at 04:24 PM ]
|
|
2007-4-26 05:53 |
|
|
zhoushijay
高级用户
Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第
2 楼』:
Do Until objTS.AtEndOfStream
If TestPing(strComputer) Then
这样的是什么条件?
If Err = 0 Then ---> if err.number=0 then
感觉还有其他错误。。。
|
|
2007-4-27 02:41 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
3 楼』:
TestPing(strComputer)他自定义的函数……返回BOOLEAN有什么问题?
|
|
2007-4-27 03:19 |
|
|
slore
铂金会员
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
4 楼』:
我没有computers.txt文件,但是运行正常……
Err = 0 可以省略属性,那么用默认的属性……默认是 Number
没有错误……
|
|
2007-4-27 03:28 |
|
|
alashan
新手上路
积分 9
发帖 4
注册 2006-10-24
状态 离线
|
『第
5 楼』:
还是不行呀,调了好多此,总是出现同一个错误。
|
|
2007-4-28 04:30 |
|
|
baomaboy
银牌会员
积分 1513
发帖 554
注册 2005-12-30
状态 离线
|
『第
6 楼』:
Quote: | Originally posted by alashan at 2007-4-28 04:30:
还是不行呀,调了好多此,总是出现同一个错误。
根本无法执行,老是提示错误 |
|
说了这么多,你根本没说重点。 到底是什么错误?什么提示?
|
好多菩提树,好多明镜台。本来好多物,好多的尘埃。 |
|
2007-4-28 05:07 |
|
|
zhoushijay
高级用户
Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第
7 楼』:
Option Explicit
Dim strFile
Dim objFSO, objTS, strComputer
Dim strnewPass
strnewPass = InputBox ("Enter your password plz.",,"P@ssW0rd!")
strFile = "C:\computers.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFile) Then
Set objTS = objFSO.OpenTextFile(strFile)
Do Until objTS.AtEndOfStream
strComputer = objTS.ReadLine
'do something with strComputer
If TestPing(strComputer) Then
On Error Resume Next
Dim objAdmin
Set objAdmin = GetObject("WinNT:\\" & strComputer & "\Administrator,user")
If Err = 0 Then
objAdmin.SetPassword strnewPass
'objAdmin.SetPassword "P@ssw0rd!"
objAdmin.SetInfo
Else
WScript.Echo strComputer & " skipped: " & _
Err.Description
End If
On Error GoTo 0
End If
Loop
objTS.Close ''这句原代码中的位置在if语句外,这样如果C:\computers.txt不存在就会出错
End If
WScript.Echo "Complete"
Function TestPing(sName)
Dim cPingResults, oPingResult
Verbose " Pinging " & sName
Set cPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery("SELECT * FROM Win32_PinStatus WHERE Address = '" & sName & "'")
For Each oPingResult In cPingResults
If oPingResult.StatusCode = 0 Then
TestPing = True
Else
TestPing = False
End If
Next
End Function
|
|
2007-4-28 05:44 |
|
|
zhoushijay
高级用户
Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第
8 楼』:
还有 以后发代码上来把注释去掉先,这么大一串看了就想跑
|
|
2007-4-28 05:45 |
|