Remote machine time using NET TIME

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • remya1000
    New Member
    • Apr 2007
    • 115

    Remote machine time using NET TIME

    i'm using Vb.net.
    i need to find out the remote machine's time by using NET TIME.

    NET TIME [\\computer | /WORKGROUP:wgnam e] [/SET] [/YES]

    i got this help from internet while searching. but while using this code i'm not able to display the time in my machine in "cmd".

    anyidea how can i find the remote machine time using NET TIME. if u have please let me know.

    thanks in advace
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Well I just put in NET TIME at a command prompt and got back the time from my domain controller.
    Code:
    C:\Documents and Settings\Plater>net time
    Current time at \\DSERVER is 5/25/2007 9:33 AM
    
    The command completed successfully.
    So what is the issue you are having?

    Comment

    • remya1000
      New Member
      • Apr 2007
      • 115

      #3
      i need to synchrinize the remote machine's time.

      i tried this code

      net time \\servername

      and i'm getting the remote machine's time
      and while using this

      net time \\servername /set /yes

      i can synchronize the remote machine's time too.

      anyway thanks a lot to help me..... thanks...

      Comment

      • oohay251
        New Member
        • May 2007
        • 27

        #4
        You can use the System.Manageme nt WMI stuff.

        In your .Net documenation:

        Search "Advanced Programming Topics in WMI .NET " and check out the "How To: Connect to a Remote Computer"

        Then lookup the WMI topics
        - Win32_LocalTime to develop and use a "Select * from Win32_LocalTime " WMI query.
        - "WMI Update Query Language" to form an update query to change the time.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Originally posted by remya1000
          i need to synchrinize the remote machine's time.
          i tried this code

          net time \\servername

          and i'm getting the remote machine's time
          and while using this

          net time \\servername /set /yes

          i can synchronize the remote machine's time too.
          anyway thanks a lot to help me..... thanks...
          So just run that code in your program then? Or use the WMI if you want to learn it

          Comment

          • somnathmali
            New Member
            • May 2007
            • 4

            #6
            try command

            net time /set \\servername

            Comment

            • kombsh
              New Member
              • Sep 2013
              • 3

              #7
              You can get it by using below code without WMI usage (http://www.morgantechspace.com/2013/...tem-using.html)

              Code:
              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();
                          }
                      }
                  }
              }

              Comment

              Working...