469,271 Members | 1,785 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Remote machine time using NET TIME

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

NET TIME [\\computer | /WORKGROUP:wgname] [/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
May 25 '07 #1
6 18105
Plater
7,872 Expert 4TB
Well I just put in NET TIME at a command prompt and got back the time from my domain controller.
Expand|Select|Wrap|Line Numbers
  1. C:\Documents and Settings\Plater>net time
  2. Current time at \\DSERVER is 5/25/2007 9:33 AM
  3.  
  4. The command completed successfully.
  5.  
So what is the issue you are having?
May 25 '07 #2
remya1000
115 100+
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...
May 25 '07 #3
You can use the System.Management 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.
May 26 '07 #4
Plater
7,872 Expert 4TB
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
May 29 '07 #5
try command

net time /set \\servername
May 29 '07 #6
kombsh
3
You can get it by using below code without WMI usage (http://www.morgantechspace.com/2013/...tem-using.html)

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4.  
  5. namespace RemoteSystemTime
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             try
  12.             {
  13.                 string machineName = "vista-pc";
  14.                 Process proc = new Process();
  15.                 proc.StartInfo.UseShellExecute = false;
  16.                 proc.StartInfo.RedirectStandardOutput = true;
  17.                 proc.StartInfo.FileName = "net";
  18.                 proc.StartInfo.Arguments = @"time \\" + machineName;
  19.                 proc.Start();
  20.                 proc.WaitForExit();
  21.  
  22.                 List<string> results = new List<string>();
  23.  
  24.                 while (!proc.StandardOutput.EndOfStream)
  25.                 {
  26.                     string currentline = proc.StandardOutput.ReadLine();
  27.  
  28.                     if (!string.IsNullOrEmpty(currentline))
  29.                     {
  30.                         results.Add(currentline);
  31.                     }
  32.                 }
  33.  
  34.                 string currentTime = string.Empty;
  35.  
  36.                 if (results.Count > 0 && results[0].ToLower().StartsWith(@"current time at \\" + machineName.ToLower() + " is "))
  37.                 {
  38.                     currentTime = results[0].Substring((@"current time at \\" +
  39.                                   machineName.ToLower() + " is ").Length);
  40.  
  41.                     Console.WriteLine(DateTime.Parse(currentTime));
  42.                     Console.ReadLine();
  43.                 }
  44.             }
  45.             catch (Exception ex)
  46.             {
  47.                 Console.WriteLine(ex.Message);
  48.                 Console.ReadLine();
  49.             }
  50.         }
  51.     }
  52. }
Sep 3 '13 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Douglas Harber | last post: by
3 posts views Thread by Nick | last post: by
7 posts views Thread by Chris Marsh | last post: by
11 posts views Thread by =?Utf-8?B?U2FsYW1FbGlhcw==?= | last post: by
5 posts views Thread by =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.