 |
|
 |
the one given in artcle works well with local host. or when i deploy file on remote host I want to deploy on one host and find uptime for all network systems.
thanks for your hlep.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi there, thanks for the article - it inspired me to start thinking of putting a web page together on our network to list all of the servers uptime 
Alas, prior to getting that far I had a problem running this on my local PC (WinXP Pro).
I'm using VB.Net - but there's hardly any difference in our code at all...
Machine.vb
Public Function UpTime() As TimeSpan
Dim Result As TimeSpan Dim PerformanceCounter As PerformanceCounter
PerformanceCounter = New PerformanceCounter("System", "System Up Time")
Result = TimeSpan.FromSeconds(PerformanceCounter.NextValue)
Return Result
End Function
And then called from my Default.aspx page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Machine As Machine
Machine = New Machine
Dim TimeSpan As TimeSpan
TimeSpan = Machine.UpTime
Response.Write("This system " & Environment.MachineName & " has been up for " & TimeSpan.Days & " days " & TimeSpan.Hours & " hours, " & TimeSpan.Minutes & " and " & TimeSpan.Seconds & " seconds.") End Sub
I get this output...
This system PC07575 has been up for 0 days 0 hours, 0 and 0 seconds.
Clearly I'm going wrong somewhere - is there anything else I need to do?
I too have the "UpTime.exe" from Microsoft (I think) and it does report the uptime of my PC.
Any info appreciated - I'd like to take this further to produce the above mentioned app for our Development and OPS team..
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi All I have web application I am develop success already in my computer if I want to use my web application from another computer How I must to do?
Please help me
Thanks, Nisarat
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
If you want to use a script to determine the uptime of remote systems using WMI, you can execute the following vbscript code.
'========================================================================== ' ' COMMENT: Calculates system uptime; that is, the number of hours a computer ' has been running since its last restart. ' '========================================================================== On Error Resume Next
strComputer = "." WScript.Echo "Server: " & strComputer
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") ' Make WMI call to find the Local System Time Set colTime = objWMIService.ExecQuery("SELECT * FROM Win32_LocalTime", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly) For Each objItem In colTime 'format a date string sysdate1 = objItem.month & "/" & objItem.day & "/" & objItem.Year 'create a date value from the date string sysdate2 = DateValue(sysdate1) 'format a time string systime1 = objItem.Hour & ":" & objItem.Minute & ":" & objItem.Second ' crate a time value from the time string systime2 = TimeValue(systime1) 'create a datetime value SysDateTime = SysDate2 & " " & Systime2 Next
Err.Clear ' Call WMI to get the last bootup time Set colOperatingSystems = objWMIService.ExecQuery _ ("Select LastBootUpTime from Win32_OperatingSystem") If Err.Number <> 0 Then WScript.Echo "ERROR: Cannot Connect to Server " & strComputer WScript.Echo Err.Number Else For Each objOS in colOperatingSystems dtmBootup = objOS.LastBootUpTime wd = objOS.LastBootUpTime ' Convert WMI time to a datetime value dtmLastBootupTime = WMIDateStringToDate(dtmBootup) WScript.Echo "The Current System Time is : " & SysDateTime WScript.Echo "The Last BootUp Time was : " & dtmLastBootUpTime ' get the number of minutes the system has been up dtmSystemUpMinutes = DateDiff("n", dtmLastBootUpTime, SysDateTime) Wscript.Echo " " 'calculate days from dtmSystemUpMinutes minutes=dtmSystemUpMinutes days=Fix(dtmSystemUpMinutes/(60*24)) minutes=(minutes Mod (60*24)) 'calculate hours from dtmSystemUpMinutes hours=Fix(minutes/60) minutes=(minutes Mod 60) WScript.Echo "Server has been up for: " & days & " day(s), " & hours & " hour(s), " & minutes & " minute(s)" Next End If 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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I think we have to use FromMilliseconds instead of FromSeconds --> TimeSpan ts = TimeSpan.FromMilliseconds(Environment.TickCount); This gives me the right uptime from my Windows XP Professional.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I found this to be very good. The only other viable alternative is to muck through WMI, and WMI may not be fully functional on the machine.
And it doesn't suffer the looping effect like System.Environment.TickCount. For the most part, resolution to the second is sufficient.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I was getting the same "Access Denied" message, so I looked around for a different method.
If you're looking for an even easier way, or are having "Access Denied" message, try:
lblMachineName.Text = Environment.MachineName Dim ts As TimeSpan = TimeSpan.FromMilliseconds(Environment.TickCount) lblUptime.Text = String.Concat(ts.Days, " days, ", ts.Hours, " hours, ", ts.Minutes, " minutes, and ", ts.Seconds, " seconds")
I think the C# translation is
TimeSpan ts = TimeSpan.FromSeconds(Environment.TickCount); Response.Write("This system " + Environment.MachineName + " has been up for " + ts.Days + " days " + ts.Hours + " hours, " + ts.Minutes + " and " + ts.Seconds + " seconds.");
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Only the "easier way" will wrap, right? - The actual code from the article shouldn't wrap.. Correct? - I just wanted to make sure... - Thanks!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
I recive the following message when I try to run the code: Server Error in '/' Application. --------------------------------------------------------------------------------
Access is denied Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ComponentModel.Win32Exception: Access is denied
Source Error:
Line 16: protected void Page_Load(object sender, System.EventArgs e) Line 17: { Line 18: PerformanceCounter pc = new PerformanceCounter("System","System Up Time"); Line 19: pc.NextValue(); //Normally starts with zero. do Next Value always. Line 20: TimeSpan ts = TimeSpan.FromSeconds(pc.NextValue());
Source File: c:\inetpub\wwwroot\uptime.aspx Line: 18
Stack Trace:
[Win32Exception (0x80004005): Access is denied] System.Diagnostics.PerformanceMonitor.GetData(String item) +371 System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String item) +150 System.Diagnostics.PerformanceCounterLib.get_CategoryTable() +80 System.Diagnostics.PerformanceCounterLib.CounterExists(String category, String counter, Boolean& categoryExists) +23 System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter) +71 System.Diagnostics.PerformanceCounter.Initialize() +237 System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly) +127 System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, Boolean readOnly) +21 System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName) +11 ASP.uptime_aspx.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\uptime.aspx:18 System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive() +29 System.Web.UI.Page.ProcessRequestMain() +724
-------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:1.0.3705.288; ASP.NET Version:1.0.3705.288
Any ideas? Thanks.
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
 |
|
 |
Works fine here! This system AD-SERVER has been up for 11 days 2 hours, 9 minutes and 22 seconds. You need to create a new subweb and associate it with an application pool in IIS
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Try:
TimeSpan ts = TimeSpan.FromSeconds(Environment.TickCount);
Response.Write("This system " + Environment.MachineName + " has been up for " + ts.Days + " days " + ts.Hours + " hours, " + ts.Minutes + " and " + ts.Seconds + " seconds.");
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I Get these results
This system GIMPY has been up for 4733 days 3 hours, 9 and 8 seconds.
thats a little under 13 Years
Changed .FromSeconds to .FromMilliseconds I Get This
This system GIMPY has been up for 4 days 17 hours, 39 and 7 seconds.
thats more like it
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Just download uptime.exe from Microsoft, it can give you detailed statistics about server uptimes
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Anders,
That is really a small, good and useful too but we had the problem like this. Our web hosting party does not allow console access to Web Server. In that case, we have no way to run any Executable Applications. Is'nt it?
Deepak Kumar Vasudevan http://deepak.portland.co.uk/
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Paul did mention this in the article
"most of the hosting cases, we normally do not get an Full Console Access to the webserver and we might not be able to run the uptime.exe Script that is normally available"
I knew it would end badly when I first met Chris in a Canberra alleyway and he said 'try some - it won't hurt you'..... - Christian Graus on Code Project outages
Damned nice for remote servers where using Enterprise Manager is like wadding through treacle while covered in velcro, upside down -Paul Watson on SQL Server Query Analyser
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Dim ts As TimeSpan = TimeSpan.FromMilliseconds(Environment.TickCount) will supply the right result without having to reference a performance counter
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |