Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

retrieve the system uptime

Posted on 2007-12-04
5
Medium Priority
?
418 Views
Last Modified: 2008-02-01
This script below provides a bunch of info about the computer after I enter the computer name.
I would like to know if I can see another info which is the system uptime( since when the computer hasn't been restarted.)

Thanks

<head>
<title>Login Details of a Machine</title>
<HTA:APPLICATION
     APPLICATIONNAME="Login Details"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
</head>

<script language="VBScript">

Sub Window_onLoad
      Me.ResizeTo 400,300
    Me.MoveTo ((Screen.Width / 2) - 200),((Screen.Height / 2) - 150)
End Sub

Sub Default_Buttons
      If Window.Event.KeyCode = 13 Then
            btn_logindetails.Click
      End If
End Sub

Sub Get_Login_Details
   
      strComputer = txt_computer.value
     
      if strComputer = "" Then
            msgbox "Please enter a computer name or IP Address",vbOKOnly,"No Computer Name or IP Address"
            Exit Sub
      End If
     
      If Ping(strComputer) = False Then
        msgbox strComputer & " did not respond to ping. No action could be taken.",vbOkOnly, "Cannot continue script."
        Exit Sub
      End If      
     
      Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
      Set colComputer = objWMIService.ExecQuery _
          ("Select * from Win32_ComputerSystem")
     
      Set colComputerIP = objWMIService.ExecQuery _
          ("Select * from Win32_NetworkAdapterConfiguration")
     
      Set colSystemInfo = objWMIService.ExecQuery _
          ("Select * from Win32_OperatingSystem",,48)
       
      For Each objComputer in colComputer
          strUserName = "User Name: " & objComputer.UserName
          strHostName = "Host Name: " & objComputer.Name
      Next
     
      For Each IPConfig in colComputerIP
            If Not IsNull(IPConfig.IPAddress) Then
              For intIPCount = LBound(IPConfig.IPAddress) _
                  to UBound(IPConfig.IPAddress)
                      strIPAddress = strIPAddress & "IP Address: " & IPConfig.IPAddress(intIPCount) & "~"
            next
            end if
      Next
     
      If Right(strIPAddress, 1) = "~" Then
            strIPAddress = Left(strIPAddress, Len(strIPAddress) - 1)
      End If
      strIPAddress = Replace(strIPAddress, "~", vbCrLf)
     
      For Each objItem in colSystemInfo
           strOS_Caption = "Caption: " & objItem.Caption
           strOS_SPVersion = "SP Version: " & objItem.CSDVersion
           strOS_VerNumber = "Version Number: " & objItem.Version
      Next
     
      MsgBox strUserName & vbcrlf & strHostName & vbcrlf & _
           strIPAddress & vbcrlf & strOS_Caption & vbcrlf & _
           strOS_SPVersion & vbcrlf & strOS_VerNumber, vbOKOnly, "Login Details"
   
End Sub

Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function

</script>

<body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>
      <table width='80%' height = '100%' align='center' border='0'>
            <tr height='20%'>
                  <td>
                  </td>
            </tr>
            <tr height='10%'>
                  <td align='center'>
                        Computer name or IP Address:
                  </td>
            </tr
            <tr height='20%'>
                  <td align='center'>
                        <input type="text" value="172.16.2.48" name="txt_computer" maxlength='15' size='16'>
                  </td>
            </tr>
            <tr height='30%'>
                  <td align='center'>
                        <input type="button" value="Check Machine" name="btn_logindetails"  onClick="Get_Login_Details">
                  </td>
            </tr>
            <tr height='20%'>
                  <td>
                  </td>
            </tr>

      </table>

</body>
'===========
0
Comment
Question by:jskfan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 20406712
For boot time, lopok in the system event log for type 6009 entries.
0
 
LVL 12

Accepted Solution

by:
chandru_sol earned 2000 total points
ID: 20408369
Try this script jskfan..........

Put the computers list in the c:\computers.txt


regards
Chandru
'Constant declarations for File I/O
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
 
set fs = CreateObject("Scripting.FileSystemObject")
 
strPath = "C:\computers.txt" 'Path to text file listing servers
 
if fs.FileExists(strPath) then
	set fsInput = fs.OpenTextFile(strPath,ForReading)
		do until fsInput.AtEndOfStream
			strComputer = fsInput.ReadLine
			Set objWMIService = GetObject("winmgmts:" _
				& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
			Set colOperatingSystems = objWMIService.ExecQuery _
				("Select * from Win32_OperatingSystem")
			For Each objOS in colOperatingSystems
				dtmBootup = objOS.LastBootUpTime
				dtmLastBootupTime =
WMIDateStringToDate(dtmBootup)
				dtmSystemUptime = DateDiff("h",
dtmLastBootUpTime, Now)
				Wscript.Echo "Computer " & strComputer & "
has been up for " & dtmSystemUptime & " Hours"
			Next
		loop
 
End if
 
wscript.echo "Script Complete"
 
Function WMIDateStringToDate(dtmBootup)
    WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
         Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
         & " " & Mid (dtmBootup, 9, 2) & ":" & _
         Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
         13, 2))
End Function

Open in new window

0
 

Author Comment

by:jskfan
ID: 20411904
excellent!!!!!!!!!!
0
 

Author Comment

by:jskfan
ID: 20411907
'Constant declarations for File I/O
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
 
set fs = CreateObject("Scripting.FileSystemObject")
 
strPath = "C:\computers.txt" 'Path to text file listing servers
 
if fs.FileExists(strPath) then
      set fsInput = fs.OpenTextFile(strPath,ForReading)
            do until fsInput.AtEndOfStream
                  strComputer = fsInput.ReadLine
                  Set objWMIService = GetObject("winmgmts:" _
                        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
                  Set colOperatingSystems = objWMIService.ExecQuery _
                        ("Select * from Win32_OperatingSystem")
                  For Each objOS in colOperatingSystems
                        dtmBootup = objOS.LastBootUpTime
                        dtmLastBootupTime =WMIDateStringToDate(dtmBootup)
                        dtmSystemUptime = DateDiff("h",dtmLastBootUpTime, Now)
                        Wscript.Echo "Computer " & strComputer & "has been up for " & dtmSystemUptime & " Hours"
                  Next
            loop
 
End if
 
wscript.echo "Script Complete"
 
Function WMIDateStringToDate(dtmBootup)
    WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
         Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
         & " " & Mid (dtmBootup, 9, 2) & ":" & _
         Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
         13, 2))
End Function
 
'Open in New Window Accept Multiple Solutions Accept as Solution
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20411962
Great!

regards
Chandru
0

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Simple Linear Regression

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question