VB to get uptime from txt file then to export it to excel - Close

Discussion in 'Scripting' started by David Rodriguez, Sep 3, 2008.

  1. Hello,
    I am so close to getting this completed. Right now I am getting an error
    for "No RPC availible.

    'on error resume next

    strUser = "ABS\User"
    strPasswd = "password"

    Set objExcel = CreateObject("Excel.Application")

    objExcel.Visible = True

    objExcel.Workbooks.Add

    intRow = 2



    objExcel.Cells(1, 1).Value = "Machine Name"

    objExcel.Cells(1, 2).Value = "Last Boot Time Stamp"



    Set Fso = CreateObject("Scripting.FileSystemObject")

    Set InputFile = fso_OpenTextFile("servers1.Txt")

    Do While Not (InputFile.atEndOfStream)

    strComputer = InputFile.ReadLine

    'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    'Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")


    set objLocator = CreateObject("WbemScripting.SWbemLocator")
    set objWMI = objLocator.ConnectServer("root\cimv2",strUser,strPasswd)
    if Err.Number <> 0 then
    WScript.Echo "Authentication failed: " & Err.Description
    end if

    set colOS = objWMI.InstancesOf("Win32_OperatingSystem")



    For Each objOS in colOS

    objExcel.Cells(intRow, 1).Value = strComputer

    objExcel.Cells(intRow, 2).Value = ConvWbemTime(objOS.LastBootUpTime)



    intRow = intRow + 1

    Next

    Loop



    objExcel.Range("A1:B1").Select

    objExcel.Selection.Interior.ColorIndex = 19

    objExcel.Selection.Font.ColorIndex = 11

    objExcel.Selection.Font.Bold = True

    objExcel.Cells.HorizontalAlignment = 2

    objExcel.Cells.EntireColumn.AutoFit



    objExcel.Columns("B:B").Select

    objExcel.Selection.NumberFormat = "DDDD, MMMM DD, YYY h:mm AM/PM"



    Function ConvWbemTime(IntervalFormat)

    sMonth = mid(IntervalFormat,5,2)

    sDay = mid(IntervalFormat,7,2)

    sYear = mid(IntervalFormat,1,4)

    sHour = mid(IntervalFormat,9,2)

    sMinutes = mid(IntervalFormat,11,2)

    sSeconds = mid(IntervalFormat,13,2)

    ConvWbemTime = sMonth & "-" & sDay & "-" & sYear & " " & sHour & ":" &
    sMinutes & ":" & sSeconds

    End Function
     
    David Rodriguez, Sep 3, 2008
    #1
    1. Advertisements

  2. here is the working script but the current user doesn't have rights the
    computers they are trying to access.

    on error resume next


    Set objExcel = CreateObject("Excel.Application")

    objExcel.Visible = True

    objExcel.Workbooks.Add

    intRow = 2



    objExcel.Cells(1, 1).Value = "Machine Name"

    objExcel.Cells(1, 2).Value = "Last Boot Time Stamp"



    Set Fso = CreateObject("Scripting.FileSystemObject")

    Set InputFile = fso_OpenTextFile("servers.Txt")

    Do While Not (InputFile.atEndOfStream)

    strComputer = InputFile.ReadLine



    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

    For Each objItem in colItems

    objExcel.Cells(intRow, 1).Value = UCase(objItem.CSName)

    objExcel.Cells(intRow, 2).Value = ConvWbemTime(objItem.LastBootUpTime)



    intRow = intRow + 1

    Next

    Loop



    objExcel.Range("A1:B1").Select

    objExcel.Selection.Interior.ColorIndex = 19

    objExcel.Selection.Font.ColorIndex = 11

    objExcel.Selection.Font.Bold = True

    objExcel.Cells.HorizontalAlignment = 2

    objExcel.Cells.EntireColumn.AutoFit



    objExcel.Columns("B:B").Select

    objExcel.Selection.NumberFormat = "DDDD, MMMM DD, YYY h:mm AM/PM"



    Function ConvWbemTime(IntervalFormat)

    sMonth = mid(IntervalFormat,5,2)

    sDay = mid(IntervalFormat,7,2)

    sYear = mid(IntervalFormat,1,4)

    sHour = mid(IntervalFormat,9,2)

    sMinutes = mid(IntervalFormat,11,2)

    sSeconds = mid(IntervalFormat,13,2)

    ConvWbemTime = sMonth & "-" & sDay & "-" & sYear & " " & sHour & ":" &
    sMinutes & ":" & sSeconds

    End Function
     
    David Rodriguez, Sep 3, 2008
    #2
    1. Advertisements

  3. David Rodriguez

    J Ford Guest

    you need to specify the computer name on the connect server peice.

    objLocator.ConnectServer(strComputer, "root\cimv2", strUser, strPasswd)

    -j
     
    J Ford, Sep 15, 2008
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.