Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get the date and time from another PC in LAN network
plz help me
Posted
Comments
Mehdi Gholam 28-Dec-13 6:09am    
Why?
marimir 28-Dec-13 6:22am    
I need server date and time to store in my database ... so I want it

1 solution

You will need the System.Management assembly referenced, and the appropriate Imports statement.
VB
Dim pc As String = "REMOTEPC"
Dim remotePath As String = String.Format("\\{0}\root\CIMV2", pc)
Dim ms As New ManagementScope(remotePath)
ms.Connect()

Dim oq As New ObjectQuery("SELECT * FROM Win32_LocalTime")

Dim mos As New ManagementObjectSearcher(ms, oq)

For Each obj As ManagementObject In mos.[Get]()
    Console.WriteLine("{0}-{1}-{2} {3}:{4}:{5}", obj("Year"), obj("Month"), obj("Day"), obj("Hour"), obj("Minute"), _
        obj("Second"))
Next
 
Share this answer
 
Comments
marimir 28-Dec-13 6:30am    
Thank you ..
But on "ms.Connect()" I've got this error :
Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
OriginalGriff 28-Dec-13 6:43am    
The error is pretty clear - you do not have permission to access the remote computer - I can;t help you there! :laugh:
marimir 28-Dec-13 6:51am    
I know that I don't have permission !
There isn't anyway to access it ?!
OriginalGriff 28-Dec-13 6:57am    
You can try using it with a ConnectionOptions and filling in the security information with valid credentials:
http://msdn.microsoft.com/en-us/library/w7sx1w4f(v=vs.110).aspx
marimir 28-Dec-13 7:15am    
Thank you :)

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