在 VBS 中,“Wscript.echo”代替了 Report.txt 吗?

在 VBS 中,“Wscript.echo”代替了 Report.txt 吗?

此脚本获取远程用户的会员信息并保存一份 report.txt。此代码可以用 wscript.echo 代替 Report.txt 吗?我尝试过更改它,但无法更改 :( 提前谢谢

 strUsers = InputBox("Enter Username: ")
 arrUsers = Split(strUsers, ",")

 If strUsers <> "" Then
 On Error Resume Next
 Err.Clear

 '("WScript.Network")
 Set fs = CreateObject ("Scripting.FileSystemObject")
 Set outFile = fs.CreateTextFile (".\Report.txt")

outFile.WriteLine "Active User's Membership"
For x = 0 to UBound(arrUsers)
arrUsers(x) = Trim(arrUsers(x))
If x = 0 Then
    'outFile.WriteLine "USER: " & arrUsers(x)
Else
    outFile.WriteLine "        " & arrUsers(x)
End If
Next 
outFile.WriteLine "==========="
For x = 0 to UBound(arrUsers)
Call getGroups(arrUsers(x))
Next

Wscript.echo "Check the Report (report.txt) File!"


Sub getGroups(strUser)
Set oNetwork = CreateObject("WScript.Network")
strDomain = oNetwork.UserDomain
On Error Resume Next
Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
If Err.Number <> 0 Then
    outFile.WriteLine strUser & " not found..."
    Exit Sub
End If
Err.Clear
On Error Goto 0

outFile.WriteLine strUser & " - " & oUser.FullName

For Each strGroup In oUser.Groups
    outFile.WriteLine "" & strGroup.Name
Next
End Sub

ElseIf strUsers = "" Then
WScript.Echo "Cancelled."
End If

答案1

如果我理解正确的话,你只是希望这个脚本输出到屏幕而不是文本文件,这很容易做到。不确定你遇到了什么问题或尝试了什么。

删除以下几行:

'("WScript.Network")
Set fs = CreateObject ("Scripting.FileSystemObject")
Set outFile = fs.CreateTextFile (".\Report.txt")
.
.
.
Wscript.echo "Check the Report (report.txt) File!"

并将任何实例替换outFile.WriteLinewscript.echo

答案2

工作脚本:)是这样的

strUsers = InputBox("Enter Username: ")
arrUsers = Split(strUsers, ",")

If strUsers <> "" Then
On Error Resume Next
Err.Clear

WScript.Echo "Active User's Membership"
For x = 0 to UBound(arrUsers)
arrUsers(x) = Trim(arrUsers(x))
If x = 0 Then
    'outFile.WriteLine "USER: " & arrUsers(x)
Else
    WScript.Echo "        " & arrUsers(x)
End If
Next 
WScript.Echo "==========="
For x = 0 to UBound(arrUsers)
Call getGroups(arrUsers(x))
Next

WScript.Echo "Check the Report (report.txt) File!"


Sub getGroups(strUser)
Set oNetwork = CreateObject("WScript.Network")
strDomain = oNetwork.UserDomain
On Error Resume Next
Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
If Err.Number <> 0 Then
    WScript.Echo strUser & " not found..."
    Exit Sub
End If
Err.Clear
On Error Goto 0

WScript.Echo strUser & " - " & oUser.FullName

For Each strGroup In oUser.Groups
    WScript.Echo "" & strGroup.Name
Next
End Sub

ElseIf strUsers = "" Then
WScript.Echo "Cancelled."
End If

相关内容