2011-06-12 2 views
3

우리는 속성 값이 현재 날짜 IP 주소 또는 컴퓨터의 이름 당신은 서면으로시간 C#에서

+0

왜 이렇게해야합니까? – Earlz

+0

클라이언트 활동 시간이 참임을 확인하십시오. –

답변

3

achive 수있는 다른 컴퓨터의 시간을 얻을 수있는 방법 로컬 컴퓨터 의 & 시간 DateTime.Now 사용 현재 시간을 알려주는 서비스? 또는 원격 컴퓨터에 연결하고 일부 WMI 쿼리를

비슷한 질문을 보내 : http://social.msdn.microsoft.com/forums/en-US/netfxremoting/thread/f2ff8a33-df5d-4bad-aa89-7b2a2dd73d73/

+0

아, WMI에 대해 잊어 버렸습니다 ... 더 좋은 생각입니다. – bobbymcr

+0

NetTime 명령을 사용할 수 있습니까 –

+0

nettime 명령을 프로세스로 래핑 할 수 있다고 생각합니다. 콘솔 출력의 결과를 datetime으로 구문 분석 할 수 있습니다. 또 다른 해결책이되어야합니다. –

0

이 작업을 수행 할 내장 방법은 없습니다. 컴퓨터에 어떤 통신 프로토콜을 통해 시간을 알려달라고 요청해야합니다. 예를 들어 WCF 서비스를 만들어 다른 시스템에서 실행하고 시스템 시간을 반환하도록 서비스 계약을 노출 할 수 있습니다. 네트워크 홉 (hop)으로 인해 대기 시간이 다소 길어질 것이라는 점을 명심하십시오. 따라서 돌아 오는 시간은 오래된 것입니다. 연결 속도에 따라 몇 밀리 초 (또는 초)가 지나치게 오래 걸릴 수 있습니다.

.NET을 필요로하지 않는 빠르고 더러운 방법이나 다른 컴퓨터에서 실행되는 특별한 것이 있으면 PSExec을 사용할 수 있습니다.

0

당신은 WMI없이 C 번호로 그것을 얻을 수

using System; 
using System.Collections.Generic; 
using System.Diagnostics; 

namespace RemoteSystemTime 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      try 
      { 
       string machineName = "vista-pc"; 
       Process proc = new Process(); 
       proc.StartInfo.UseShellExecute = false; 
       proc.StartInfo.RedirectStandardOutput = true; 
       proc.StartInfo.FileName = "net"; 
       proc.StartInfo.Arguments = @"time \\" + machineName; 
       proc.Start(); 
       proc.WaitForExit(); 

       List<string> results = new List<string>(); 

       while (!proc.StandardOutput.EndOfStream) 
       { 
        string currentline = proc.StandardOutput.ReadLine(); 

        if (!string.IsNullOrEmpty(currentline)) 
        { 
         results.Add(currentline); 
        } 
       } 

       string currentTime = string.Empty; 

       if (results.Count > 0 && results[0].ToLower().StartsWith(@"current time at \\" + machineName.ToLower() + " is ")) 
       { 
        currentTime = results[0].Substring((@"current time at \\" + 
            machineName.ToLower() + " is ").Length); 

        Console.WriteLine(DateTime.Parse(currentTime)); 
        Console.ReadLine(); 
       } 
      } 
      catch (Exception ex) 
      { 
       Console.WriteLine(ex.Message); 
       Console.ReadLine(); 
      } 
     } 
    } 
}