Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > VB to get uptime from txt file then to export it to excel - Close

Reply
Thread Tools Display Modes

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

 
 
David Rodriguez
Guest
Posts: n/a

 
      09-03-2008
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,strP asswd)
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


 
Reply With Quote
 
 
 
 
David Rodriguez
Guest
Posts: n/a

 
      09-03-2008
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" wrote:

> 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,strP asswd)
> 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
>
>

 
Reply With Quote
 
J Ford
Guest
Posts: n/a

 
      09-15-2008

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

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

-j

"David Rodriguez" wrote:

> 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" wrote:
>
> > 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,strP asswd)
> > 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
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
export to excel file is gone from ie7 Pamela Internet Explorer 1 05-03-2009 02:13 PM
How To Get Excel File Folder to Associate with Excel File Open ncprius Windows Vista File Management 2 04-07-2008 01:38 PM
How to export all the user's name and surname of my Active Directory in an excel file ? moi Active Directory 1 03-10-2006 07:37 AM
export printer settings to a text file or excel spreadsheet donny Windows Server 0 01-27-2005 03:25 AM
Re: how do i export a playlist to an excel file? Chris Lanier [MVP] Windows Media Player 0 06-04-2004 02:40 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59