Synchronizing datetime of computers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sushi

    Synchronizing datetime of computers

    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.b at" );
    byte[] b = System.Text.Enc oding.ASCII.Get Bytes( @" net time
    \\machinename-with-whom-to-sync /set /yes" );
    stream.Write( b, 0, b.Length );
    stream.Close( );
    Process p1 = new Process( );
    p1.EnableRaisin gEvents = false;
    p1.StartInfo.Fi leName= "C:\\batch.bat" ;
    p1.StartInfo.Cr eateNoWindow = true;
    p1.StartInfo.Us eShellExecute = false;
    p1.Start( );
    p1.WaitForExit( );

    Thanks,
    Sushi
  • William Stacey [MVP]

    #2
    Re: Synchronizing datetime of computers

    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.Fi leName = "cmd";
    p1.StartInfo.Ar guments = "/c net time " + machine + " /set /yes[color=blue]
    > c:\\output.txt" ;[/color]
    p1.StartInfo.Cr eateNoWindow = true;
    p1.StartInfo.Us eShellExecute = false;
    p1.Start();
    p1.WaitForExit( );

    --
    William Stacey [MVP]

    "sushi" <sushi@discussi ons.microsoft.c om> wrote in message
    news:4625C9AE-8E65-4A08-B3BD-23303C4CA433@mi crosoft.com...[color=blue]
    > 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.b at" );
    > byte[] b = System.Text.Enc oding.ASCII.Get Bytes( @" net time
    > \\machinename-with-whom-to-sync /set /yes" );
    > stream.Write( b, 0, b.Length );
    > stream.Close( );
    > Process p1 = new Process( );
    > p1.EnableRaisin gEvents = false;
    > p1.StartInfo.Fi leName= "C:\\batch.bat" ;
    > p1.StartInfo.Cr eateNoWindow = true;
    > p1.StartInfo.Us eShellExecute = false;
    > p1.Start( );
    > p1.WaitForExit( );
    >
    > Thanks,
    > Sushi[/color]


    Comment

    • sushi

      #3
      Re: Synchronizing datetime of computers

      hello,

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

      Thanks,
      Sushi

      "William Stacey [MVP]" wrote:
      [color=blue]
      > 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.Fi leName = "cmd";
      > p1.StartInfo.Ar guments = "/c net time " + machine + " /set /yes[color=green]
      > > c:\\output.txt" ;[/color]
      > p1.StartInfo.Cr eateNoWindow = true;
      > p1.StartInfo.Us eShellExecute = false;
      > p1.Start();
      > p1.WaitForExit( );
      >
      > --
      > William Stacey [MVP]
      >
      > "sushi" <sushi@discussi ons.microsoft.c om> wrote in message
      > news:4625C9AE-8E65-4A08-B3BD-23303C4CA433@mi crosoft.com...[color=green]
      > > 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.b at" );
      > > byte[] b = System.Text.Enc oding.ASCII.Get Bytes( @" net time
      > > \\machinename-with-whom-to-sync /set /yes" );
      > > stream.Write( b, 0, b.Length );
      > > stream.Close( );
      > > Process p1 = new Process( );
      > > p1.EnableRaisin gEvents = false;
      > > p1.StartInfo.Fi leName= "C:\\batch.bat" ;
      > > p1.StartInfo.Cr eateNoWindow = true;
      > > p1.StartInfo.Us eShellExecute = false;
      > > p1.Start( );
      > > p1.WaitForExit( );
      > >
      > > Thanks,
      > > Sushi[/color]
      >
      >
      >[/color]

      Comment

      Working...