Click here to Skip to main content
15,888,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,

Dirst of all let me introduce my problem:

I have a small server that is giving users remote licences to use the accountants program.
That program requires all the computers that work with it to be on the same date (i.e. If I want to get the accountants program working in my computer my computer and the license server must be on the same date and in the same hour).

Another problem that this accountants program has is that if you want to introduce data that belongs to 2012 you must be at 2012 (you can't do that once your computer has entered 2013) which is crap.

So now I face a stupid problem:

I would like to allow the accountants to remotely change the date and time (it should be a small program or so which would allow to get this done easily without needing to give them (the accountants) access to the server).

Any idea on how to get this done?

Thank you in advance!
Posted

1 solution

Management Object(WMI) is a good method if you use XP or later.

C#
public void SetSystemTime(string host, string username, string password, DateTime dt)
{

  ConnectionOptions options = new ConnectionOptions();

  options.Username = username;

  options.Password = password;

  path = new ManagementPath(String.Format("\\\\{0}\\root\\cimv2", host));

  scope = new ManagementScope(path, options);

  foreach (ManagementObject classInstance in new ManagementClass(scope, new ManagementPath("Win32_OperatingSystem"), null).GetInstances())
    {
      // Obtain in-parameters for the method
      ManagementBaseObject inParams = classInstance.GetMethodParameters("SetDateTime");

      // Add the input parameters.
      inParams["LocalDateTime"] = ManagementDateTimeConverter.ToDmtfDateTime(dt);

      // Execute the method and obtain the return values.
      ManagementBaseObject outParams = classInstance.InvokeMethod("SetDateTime", inParams, null);
    }

}



Alternatively, you could use PSTools:
http://technet.microsoft.com/en-us/sysinternals/bb897553[^]


PsExec.exe -u domain/username -p password \\RemoteServerName cmd /C date 07-11-2010

You could use this and create a small .Net Program. Use System.Diagnostic.Process.Start("the above command")
Note: Use full path to PsExec.exe when you use inside Process.Start method

Thanks,

Kuthuparakkal
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900