扫描IP范围并将用户信息提供给Excel工作表的脚本。回收信息 [英] Script that scans IP range and gets user information to Excel sheet. Recycles information

查看:191
本文介绍了扫描IP范围并将用户信息提供给Excel工作表的脚本。回收信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助生成带有特定用户信息的Excel工作表的VBS脚本。

I need help with a VBS script that produces an Excel sheet with specific user information.

它有效...排序。问题是它似乎回收信息产生不准确的结果。任何人都知道如果没有相关信息,我会如何将Excel文档中的脚本区域留空?我知道这是可能的,只需要朝着正确的方向轻推。

It works... Sort of. The problem is that it seems to recycle information producing inaccurate results. Anybody know how I would go about making the script leave areas in the Excel document blank when no information is available? I know it's possible, just need a nudge in the right direction.

谢谢!

On Error Resume Next

Dim FSO
Dim objStream

Const TriStateFalse = 0
Const FILE_NAME = "Users.csv"

Set FSO = CreateObject("Scripting.FileSystemObject")

Set objStream = FSO.CreateTextFile(FILE_NAME, _
True, TristateFalse)

strSubnetPrefix = "192.168.1."
intBeginSubnet = 1
intEndSubnet = 254

For i = intBeginSubnet To intEndSubnet
strComputer = strSubnetPrefix & i
    'strcomputer = inputbox("Enter Computer Name or IP")
    if strcomputer = "" then
        wscript.quit
    else

    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
        ("select * from Win32_PingStatus where address = '" & strcomputer & "'")
    For Each objStatus in objPing
        If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then 
            'request timed out
            'msgbox(strcomputer & " did not reply" & vbcrlf & vbcrlf & _
                    '"Please check the name and try again")
        else

            set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2")
            Set colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
            For Each objComputer in colSettings 
                                    objStream.WriteLine objComputer.name & "," & objcomputer.username & "," & objcomputer.domain _
                & "," & strcomputer
                'msgbox("System Name: " & objComputer.Name & vbcrlf & "User Logged in : " & _
                'objcomputer.username  & vbcrlf & "Domain: " & objComputer.Domain)
            Next
        end if
    next
    end if
Next

Msgbox("Done Collecting")

set objwmiservice = nothing
set colsettings = nothing
set objping = nothing


推荐答案

在再次设置之前,需要将WMI调用变量重置为空。这个脚本应该更好。

Your WMI call variables need to be reset to nothing before you set them again. This script should work better.

On Error Resume Next

Dim FSO
Dim objStream

Const TriStateFalse = 0
Const FILE_NAME = "Users.csv"

Set FSO = CreateObject("Scripting.FileSystemObject")

Set objStream = FSO.CreateTextFile(FILE_NAME, _
True, TristateFalse)

strSubnetPrefix = "192.168.1."
intBeginSubnet = 1
intEndSubnet = 254

For i = intBeginSubnet To intEndSubnet
strComputer = strSubnetPrefix & i
    'strcomputer = inputbox("Enter Computer Name or IP")
    if strcomputer = "" then
        wscript.quit
    else

    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
        ("select * from Win32_PingStatus where address = '" & strcomputer & "'")
    For Each objStatus in objPing
        If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then 
            'request timed out
            'msgbox(strcomputer & " did not reply" & vbcrlf & vbcrlf & _
                    '"Please check the name and try again")
        else

            set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2")
            Set colSettings = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
            For Each objComputer in colSettings 
                                    objStream.WriteLine objComputer.name & "," & objcomputer.username & "," & objcomputer.domain _
                & "," & strcomputer
                'msgbox("System Name: " & objComputer.Name & vbcrlf & "User Logged in : " & _
                'objcomputer.username  & vbcrlf & "Domain: " & objComputer.Domain)
            Next
            set objwmiservice = nothing
            set colsettings = nothing
        end if
    next
    end if
    set objping = nothing
Next

Msgbox("Done Collecting")

这篇关于扫描IP范围并将用户信息提供给Excel工作表的脚本。回收信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆