Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Using WMI to get date and time on a remote computer
 

Using WMI to get date and time on a remote computer

Hi Guys I have done a WMI Script inC#.netto connect to a remote computer on a lan. However I want to get the date and time on that computer but cannot find which properties will allow me to access this information. The example I followed was the link below.

http://msdn2.microsoft.com/en-us/library/ms257337.aspx

Damion Chambers  Saturday, March 10, 2007 3:10 AM

try wbemtest.exe to find the properties.

or google/msdnfor

wmi c# time

win32_localtime

win32_utctime

and here is some code snippet for local server.

SelectQuery selectQuery = new SelectQuery("select * from win32_localtime");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery);
int i = 0;
foreach (ManagementObject mo in searcher.Get())
{
Console.WriteLine("x:" + (mo["Hour"]));
}
System.Console.Read();

Hope this could help.

_Justin

Justin Jin  Tuesday, March 13, 2007 1:27 PM
I had a hard time connecting to a workgroup computer but finally got it. You have to use the local administrator account and not windows domain accounts. However the script runs on my computer to get the local time. However when I connect to the remote computer and run the same script I get an "Invalid Class" error? Any idea?
Damion Chambers  Wednesday, March 14, 2007 1:24 PM
Try with Connectionoptions


public static ConnectionOptions ProcessConnectionOptions()
{
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = ImpersonationLevel.Impersonate;
options.Authentication = AuthenticationLevel.Default;
options.EnablePrivileges = true;
return options;
}

public static ManagementScope ConnectionScope( string machineName,
string Username,
string Password,
string Domain,
ConnectionOptions options)
{
ManagementScope connectScope = new ManagementScope();
connectScope.Path = new ManagementPath(@"\\" + machineName + @"\root\CIMV2");
if (Domain != null || Username != null)
{
options.Username = Domain + "\\" + Username;
options.Password = Password;
}
connectScope.Options = options;

try
{
connectScope.Connect();
}
catch (ManagementException e)
{
//Console.WriteLine("An Error Occurred: " + e.Message.ToString());
}
catch
{
}
return connectScope;
}
}
M.S.K  Thursday, October 16, 2008 6:26 PM
I stumbled on this looking for a way to get the times from the command prompt. Here's what I came up with...

wmic /NODE:SERVER path win32_operatingsystem get LocalDateTime, CurrentTimeZone /FORMAT:CSV

Time On a Remote Computer

Time of a remote computer

Query remote time

-AA

http://www.adamanthony.net/adama/?tab=C


Adam T. Anthony  Friday, March 13, 2009 2:01 AM

You can use google to search for other answers

Custom Search

More Threads

• ToolStripMenuItems have disappeared from the MenuStrip
• TabControl problem
• Custom Controls with Visual C++ .NET
• Move scrollbar at top position
• adding a control to a derived control
• TypeConverter
• UITypeEditor fails to load when using the string-based Editor attribute params
• Control Custom Properties
• How to create and Invisible Groupbox
• Remove Drawing Events - C#,Windows Application