Synchronizing datetime of computers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

How can be synchronize dates of two computers.
I tried this using net time command but this works fine in Console
application but fails in web application.

Can any help me out.

My code is as follows

FileStream stream = File.Create( @"C:\batch.bat" );
byte[] b = System.Text.Encoding.ASCII.GetBytes( @" net time
\\machinename-with-whom-to-sync /set /yes" );
stream.Write( b, 0, b.Length );
stream.Close( );
Process p1 = new Process( );
p1.EnableRaisingEvents = false;
p1.StartInfo.FileName= "C:\\batch.bat";
p1.StartInfo.CreateNoWindow = true;
p1.StartInfo.UseShellExecute = false;
p1.Start( );
p1.WaitForExit( );

Thanks,
Sushi
 
Try this. Remove the "> c:\\output.txt" after your happy with the output.
You could also run it without CMD. I just did with CMD for debug reasons.
In that case the fileName would be "Net" and the args would be all after
"net" below.

string machine = @"\\wjs";
Process p1 = new Process();
p1.StartInfo.FileName = "cmd";
p1.StartInfo.Arguments = "/c net time " + machine + " /set /yes
c:\\output.txt";
p1.StartInfo.CreateNoWindow = true;
p1.StartInfo.UseShellExecute = false;
p1.Start();
p1.WaitForExit();

--
William Stacey [MVP]

sushi said:
Hello,

How can be synchronize dates of two computers.
I tried this using net time command but this works fine in Console
application but fails in web application.

Can any help me out.

My code is as follows

FileStream stream = File.Create( @"C:\batch.bat" );
byte[] b = System.Text.Encoding.ASCII.GetBytes( @" net time
\\machinename-with-whom-to-sync /set /yes" );
stream.Write( b, 0, b.Length );
stream.Close( );
Process p1 = new Process( );
p1.EnableRaisingEvents = false;
p1.StartInfo.FileName= "C:\\batch.bat";
p1.StartInfo.CreateNoWindow = true;
p1.StartInfo.UseShellExecute = false;
p1.Start( );
p1.WaitForExit( );

Thanks,
Sushi
 
hello,

I tried this but still it works fine in console application but does not
work in web application.

Thanks,
Sushi

William Stacey said:
Try this. Remove the "> c:\\output.txt" after your happy with the output.
You could also run it without CMD. I just did with CMD for debug reasons.
In that case the fileName would be "Net" and the args would be all after
"net" below.

string machine = @"\\wjs";
Process p1 = new Process();
p1.StartInfo.FileName = "cmd";
p1.StartInfo.Arguments = "/c net time " + machine + " /set /yes
c:\\output.txt";
p1.StartInfo.CreateNoWindow = true;
p1.StartInfo.UseShellExecute = false;
p1.Start();
p1.WaitForExit();

--
William Stacey [MVP]

sushi said:
Hello,

How can be synchronize dates of two computers.
I tried this using net time command but this works fine in Console
application but fails in web application.

Can any help me out.

My code is as follows

FileStream stream = File.Create( @"C:\batch.bat" );
byte[] b = System.Text.Encoding.ASCII.GetBytes( @" net time
\\machinename-with-whom-to-sync /set /yes" );
stream.Write( b, 0, b.Length );
stream.Close( );
Process p1 = new Process( );
p1.EnableRaisingEvents = false;
p1.StartInfo.FileName= "C:\\batch.bat";
p1.StartInfo.CreateNoWindow = true;
p1.StartInfo.UseShellExecute = false;
p1.Start( );
p1.WaitForExit( );

Thanks,
Sushi
 
Back
Top