Delirium
01-06-2011, 01:15
Чтобы не было криков, что я отсчитываю время от единожды полученного, вот вам весь исходник DOS приложения. WIN приложение делает тоже самое, только выводит данные на форму:
namespace uptime
{
class Program
{
[DllImport("user32.dll")]
static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
static void Main(string[] args)
{
string s1, s2;
int systemUptime = Environment.TickCount;
// The tick at which the last input was recorded
int LastInputTicks = 0;
// The number of ticks that passed since last input
int IdleTicks = 0;
// Set the struct
LASTINPUTINFO LastInputInfo = new LASTINPUTINFO();
LastInputInfo.cbSize = (uint)Marshal.SizeOf(LastInputInfo);
LastInputInfo.dwTime = 0;
// If we have a value from the function
if (GetLastInputInfo(ref LastInputInfo))
{
// Get the number of ticks at the point when the last activity was seen
LastInputTicks = (int)LastInputInfo.dwTime;
// Number of idle ticks = system uptime ticks - number of ticks at last input
IdleTicks = systemUptime - LastInputTicks;
}
// Set the labels; divide by 1000 to transform the milliseconds to seconds
s1 = Convert.ToString(systemUptime / 1000) + " секунд";
s2 = Convert.ToString(IdleTicks / 1000) + " seconds";
TimeSpan t = TimeSpan.FromSeconds(systemUptime / 1000);
t = TimeSpan.FromSeconds(systemUptime / 1000);
string itog = t.Days.ToString() + "дн:" + t.Hours.ToString() + "ч:" + t.Minutes.ToString() + "м:" + t.Seconds.ToString() + "с.";
Console.Write("\n\nВремя работы системы: " + s1 + "\n\nили " + itog);
Console.Write("\n\nFreeware special for OsZone.Net :)\nby Delirium\n\n");
var name = Console.ReadKey(true);
}
internal struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
}
}
namespace uptime
{
class Program
{
[DllImport("user32.dll")]
static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
static void Main(string[] args)
{
string s1, s2;
int systemUptime = Environment.TickCount;
// The tick at which the last input was recorded
int LastInputTicks = 0;
// The number of ticks that passed since last input
int IdleTicks = 0;
// Set the struct
LASTINPUTINFO LastInputInfo = new LASTINPUTINFO();
LastInputInfo.cbSize = (uint)Marshal.SizeOf(LastInputInfo);
LastInputInfo.dwTime = 0;
// If we have a value from the function
if (GetLastInputInfo(ref LastInputInfo))
{
// Get the number of ticks at the point when the last activity was seen
LastInputTicks = (int)LastInputInfo.dwTime;
// Number of idle ticks = system uptime ticks - number of ticks at last input
IdleTicks = systemUptime - LastInputTicks;
}
// Set the labels; divide by 1000 to transform the milliseconds to seconds
s1 = Convert.ToString(systemUptime / 1000) + " секунд";
s2 = Convert.ToString(IdleTicks / 1000) + " seconds";
TimeSpan t = TimeSpan.FromSeconds(systemUptime / 1000);
t = TimeSpan.FromSeconds(systemUptime / 1000);
string itog = t.Days.ToString() + "дн:" + t.Hours.ToString() + "ч:" + t.Minutes.ToString() + "м:" + t.Seconds.ToString() + "с.";
Console.Write("\n\nВремя работы системы: " + s1 + "\n\nили " + itog);
Console.Write("\n\nFreeware special for OsZone.Net :)\nby Delirium\n\n");
var name = Console.ReadKey(true);
}
internal struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
}
}