Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 17-Feb-13 20:58pm
Joan Murt82.4K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Management Object(WMI) is a good method if you use XP or later.
 
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
  Permalink  
v3

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



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100