Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

retrieve the system uptime

Posted on 2007-12-04
5
Medium Priority
?
421 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
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Progress
Suggested Courses

971 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