 |
|
 |
Doesn't work. Always gives an error message.
|
|
|
|
 |
|
 |
Hi,
We have been using this code since long but could not observe a problem till now. The problem we are facing is that the server time gets 1 day decremented at certain times. After careful analaysis we figured out that this is something related to time zone computation because we are in GMT+3 and also found a similar problem/solution reported on net.
Here is the page which reported the problem and solution: http://forums.devx.com/showpost.php?p=512474&postcount=2[^]
And here is the page with a more stable solution: http://vbnet.mvps.org/index.html?code/network/netremotetod.htm[^]
I request the author to look if the code needs updating and this has been shared for community welfare.
|
|
|
|
 |
|
 |
The sample code is working fine, when i try to use that on my laptop to get the datetime of another development PC in same network...but when i use that code at development PC to get my laptop datetime...the fuction always return me a Error Code = 5 (Access denied)...
When i call the fucntion, i key in the ip add instead of the computer name.... any idea of why i got those error..and how to solve
|
|
|
|
 |
|
 |
Does somebody have any idea how could I accomplish the same thing on linux?
Chris
|
|
|
|
 |
|
 |
Hi,
This is a wonderfull work! But I have some problem. It cant retrive the time and date from a remote server im trying to, I think this is because there is username and password for the server, where do I fill this information in the code?
Please Help!
Thank you.
Karthik
|
|
|
|
 |
|
 |
I'm using Advanced server 2000 and Windows 2000 Professional for workstation. At first it is working fine logging in to my workstation using the login info of my Server. But when I use the login info of my workstation, it doesn't work. When I tried debugging it, I found out that
iRet = NetRemoteTOD(strServerName, ptodi)
iRet doesn't return a value 0, I don't know why, cause I'm just a beginner in VB.NET I just use the sample code for my system and the other functionalities are working and connecting to the server.
psssst
|
|
|
|
 |
|
 |
I'm using Advanced server 2000 and Windows 2000 Professional for workstation. At first it is working fine logging in to my workstation using the login info of my Server. But when I use the login info of my workstation, it doesn't work. When I tried debugging it, I found out that
iRet = NetRemoteTOD(strServerName, ptodi)
iRet doesn't return a value 0, I don't know why, cause I'm just a beginner in VB.NET I just use the sample code for my system and the other functionalities are working and connecting to the server.
|
|
|
|
 |
|
 |
How would you use this same program to extend the time format to return milliseconds? TimeSerial doesn't support milliseconds, correct?
|
|
|
|
 |
|
 |
Hi,
I'm using this piece of code and I must say it works like a charm but....
I'm trying to connect to a remote server which has not the same administrator password as my client.
When I haven't connected to the server yet, the code doesn't work.
If I open a session (by for example navigating to \\myserver\c$) and filling in my administrator credentials, and then I execute the code through .NET, it works...
My question: how to avoid I have to first manually create a session to the remote server ? Is there any way to do that through VB.NET by sending credentials or so ?
Thanks for your replies !!
Greetings,
Mathieu
|
|
|
|
 |
|
 |
Any idea how to fix it?
Thanks
|
|
|
|
 |
|
 |
First: Thanks for that source! Second: Here an update for it: Function GetNetRemoteTOD(ByVal strServerName As String) As Date '------------------------------------------------------------------ 'Returns Date and Time of the given client computer '- returns an empty date/time on failure Dim ptrTODI As IntPtr Dim strTODI As TIME_OF_DAY_INFO '------------------------------------------------------------------ Try 'Adding the vbNullChar isn't needed - Marshalling in declaration 'of the API-Call does this for us. If NetRemoteTOD(strServerName, ptrTODI) = 0 Then strTODI = CType(Marshal.PtrToStructure(ptrTODI, GetType(TIME_OF_DAY_INFO)), _ TIME_OF_DAY_INFO) Return New Date(strTODI.tod_year, strTODI.tod_month, strTODI.tod_day, _ strTODI.tod_hours, strTODI.tod_mins, strTODI.tod_secs, _ strTODI.tod_hunds * 10).AddMinutes(-strTODI.tod_timezone) Else Return Nothing End If Catch Return Nothing Finally If Not ptrTODI.Equals(ptrTODI.Zero) Then NetApiBufferFree(ptrTODI) End Try '------------------------------------------------------------------ End Function Just a hint: The function accepts IP-addresses as well. [ like this: Debug.WriteLine(GetNetRemoteTOD("192.168.0.1")) ]
|
|
|
|
 |
|
 |
Hi, I'm new here and I am a student at OCC...and I was trying to make this run because my assignment is close to this.
For whatever reason, it did not work the way I wanted. I exactly copied the code.
===================
Imports System.Runtime.InteropServices
Public Class Form1
Private Declare Unicode Function NetRemoteTOD Lib "netapi32" ( _
<MarshalAs(UnmanagedType.LPWStr)> ByVal ServerName As String, _
ByRef BufferPtr As IntPtr) As Integer
Private Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As IntPtr) As Integer
Structure TIME_OF_DAY_INFO
Dim tod_elapsedt As Integer
Dim tod_msecs As Integer
Dim tod_hours As Integer
Dim tod_mins As Integer
Dim tod_secs As Integer
Dim tod_hunds As Integer
Dim tod_timezone As Integer
Dim tod_tinterval As Integer
Dim tod_day As Integer
Dim tod_month As Integer
Dim tod_year As Integer
Dim tod_weekday As Integer
End Structure
Function GetNetRemoteTOD(ByVal strServerName As String) As Date
'------------------------------------------------------------------
'Returns Date and Time of the given client computer
'- returns an empty date/time on failure
Dim ptrTODI As IntPtr
Dim strTODI As TIME_OF_DAY_INFO
'------------------------------------------------------------------
Try
'Adding the vbNullChar isn't needed - Marshalling in declaration
'of the API-Call does this for us.
If NetRemoteTOD(strServerName, ptrTODI) = 0 Then
strTODI = CType(Marshal.PtrToStructure(ptrTODI, _
GetType(TIME_OF_DAY_INFO)), TIME_OF_DAY_INFO)
Return New Date(strTODI.tod_year, strTODI.tod_month, _
strTODI.tod_day, strTODI.tod_hours, strTODI.tod_mins, _
strTODI.tod_secs, strTODI.tod_hunds * 10).AddMinutes _
(-strTODI.tod_timezone)
Else
Return Nothing
End If
Catch
Return Nothing
Finally
If Not ptrTODI.Equals(IntPtr.Zero) Then NetApiBufferFree(ptrTODI)
End Try
End Function
'--------------------------------------------------------------------------
Private Sub RetrieveButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RetrieveButton.Click
Dim dRemoteDate As Date
dRemoteDate = GetNetRemoteTOD("localhost") ' ..............................?????????
MsgBox("The remote date is " & dRemoteDate)
End Sub
End Class
===================
PLEASE, anyone, what am I missing?
At the [ dRemoteDate = GetNetRemoteTOD("localhost") ] line, I have tried all possible replacement for "localhost". I even used the exact IP Address of our School Lab's server (with the professor's acknowledgment and Lab Tech'n help). OR have I not tried the correct one yet? What would that be?
If I leave it blank (""), it retrieves the date and time of the PC that I am using and NOT the date and time of the server. I dont mind if the server's date and time is GMT or any. I think I need that better that way to distinguish if it is retrieving correctly...PLEASE HELP. THANKS in advance.
Dor
|
|
|
|
 |
|
 |
When my current time is like 7pm or later...It shows the day as 1 day further ahead then it should be. My guess it's something to do with Greenwich time, but not sure why it's occuring or if it's just a bug with the dll.
|
|
|
|
 |
|
 |
I posted this...I fixed. NetRemoteTOD returns a time relative to GMT, so after if currently my date is 9/28/2004 7:01PM...NetRemoteTOD returns TIME OF DAY INFO that contains a date of 9/29/2004 12:01AM. The code in this page subtracts the TIMEZONE, but just from the time...not taking into consideration the date. I solved by remove the '- todi.tod_timezone' from this function:
TimeSerial(todi.tod_hours, todi.tod_mins - todi.tod_timezone, todi.tod_secs)
and adding this to the return statement:
GetNetRemoteTOD = dDate(-todi.tod_timezone)
Now when you adjust for the timezone...you aren't just correcting the time, but also the day. Works for me anyway.
|
|
|
|
 |
|
 |
Imports System.Runtime.InteropServices
Friend Class RemoteTime
Private Declare Unicode Function NetRemoteTOD Lib "netapi32" ( _
<MarshalAs(UnmanagedType.LPWStr)> ByVal ServerName As String, _
ByRef BufferPtr As IntPtr) As Integer
Private Declare Function NetApiBufferFree Lib _
"netapi32" (ByVal Buffer As IntPtr) As Integer
Private Structure TIME_OF_DAY_INFO
Dim tod_elapsedt As Integer
Dim tod_msecs As Integer
Dim tod_hours As Integer
Dim tod_mins As Integer
Dim tod_secs As Integer
Dim tod_hunds As Integer
Dim tod_timezone As Integer
Dim tod_tinterval As Integer
Dim tod_day As Integer
Dim tod_month As Integer
Dim tod_year As Integer
Dim tod_weekday As Integer
End Structure
Public Function GetNetRemoteTOD(ByVal strServerName As String) As Date
Try
Dim iRet As Integer
Dim ptodi As IntPtr
Dim todi As TIME_OF_DAY_INFO
strServerName = strServerName & vbNullChar
iRet = NetRemoteTOD(strServerName, ptodi)
If iRet = 0 Then
todi = CType(Marshal.PtrToStructure(ptodi, GetType(TIME_OF_DAY_INFO)), _
TIME_OF_DAY_INFO)
NetApiBufferFree(ptodi)
Dim dat As Date = New Date(todi.tod_year, todi.tod_month, todi.tod_day, todi.tod_hours, todi.tod_mins, todi.tod_secs)
Return DateAdd(DateInterval.Minute, -todi.tod_timezone, dat)
Else
Throw New Exception("NetRemoteTOD raise error: " & iRet)
End If
Catch
Throw
End Try
End Function
End Class
|
|
|
|
 |
|
 |
I am glad to see that someone has taken the "classic" net time and used the API. When you wrote this did you have intentions on running a NTP server/service for sync'ing network devices? If so are you running these as a Service (like Windows Time)?
|
|
|
|
 |
|
 |
Thanks for your comment. Exactly, a very good use for this would be to place this code in a windows service and create a custom application that could for example, monitor all your servers to make sure the system time is not off on one of your servers. It is easy to take for granted that you can now create a windows service very easy using .Net. compared to vb6. Thanks for bringing up that excellent point.
Thanks,
SeaWater
|
|
|
|
 |
|
 |
c:\>net time \\computername | /domain | rtsdomain [/set]
retrieves time using windows...
|
|
|
|
 |
|
 |
Hello, you can use net time but, net time is intended to be used as a command line tool and not an api. There are also a couple of disadvantages of using net time instead of NetRemoteTOD:
1. Net Time is an older command line tool from Microsoft.
2. You must be logged on to the system in order for net time to work. (Not the case with NetRemoteTOD). In the case the system boots up and no one is logged in, the net time command will not work unless you log in.
3. The main problem with net time is that it behaves differently on Windows NT/2K/XP/2003 and Win3x/95/98 in how it handles time zones. On the other hand, when using NetRemoteTOD, you have complete control of the time zone as you see in the code above.
Thanks,
SeaWater
|
|
|
|
 |
|
 |
If I understand what you are trying to say, setting up a web service on the server would accomplish the same thing. Just have a function that returns the date / time .
|
|
|
|
 |
|
 |
Hello, thank you for taking the time to comment on this topic. At first using a web service might seem like the logical thing to do but, after a careful consideration, there are a couple of advantages of using this api rather than a web service:
1. If you use a web service, you would need to create two separate applications. One would be the actual web service on the server which you are retrieving the date/time from using a function that returns the date/time as you described. The second application would be the consumer on the client retrieving the time. By using the NetRemoteTOD api, you only need one piece of code on the client and nothing on the server!
2. The second problem and the definite difference between using a web service and the NetRemoteTOD is that you would need to install the web service on every machine that you want to retrieve the time from! If you have 2200 servers that you want to check the date/time on, then you would need to install the web service on all 2200 servers! On the other hand, NetRemoteTOD is a time synchronization protocol that is already built into the operating system(Except For Windows 95/98), therefore you can retrieve the time from a server without installing any code on that server.
I do see a use for a web service but it would be in a different scenario, you can use the web service to host the call to NetRemoteTOD. You would pass the server name that you wish to retrieve the date/time from and then you would get back the date/time value for that server. Then you would just have one server which retrieves the time from all the machines using just one web service.
Thanks and I hope this clears up the use of NetRemoteTOD,
SeaWater
|
|
|
|
 |
|
 |
Is "NetRemoteTOD" api going to work when the client is not part of the domain?. I have a case where clients are not part of the domain but are able to ping the server and access resource such as the website. Both "Net time" and "NetRemoteTOD" api fails with "access denied" error. Is there any other way other than joining the domain if thats even an issue? Plz help!!
|
|
|
|
 |
|
 |
Hello, are you sure that the problem is with the NetRemoteTOD api? Try this: try running the api from the SAME domain as the server you are requesting the time from. If that still fails, there is a problem with the configuration of the server. Also, remember that NetRemoteTOD is not available for Windows 95/98.
Thanks,
SeaWater
|
|
|
|
 |
|
 |
Server: windows 2000 Server
Clients: windows 2000 pro
It works when Server and clients are in same domain.
It doesn't work when clients are not a member of domain.
Is this the nature of design?
I have figured out a workaround. I've set the same local administrator passwords for the server and client.
|
|
|
|
 |
|
 |
This is due to the way Windows handles "Remoted" functions (pretty much any of the Net* functions actually).
Since you are initiating a connection to a remote machine in an untrusted environment (ie NO domain), Windows attempts to use the current user name and password when creating the connection. This is why having the admin name and password the same on both machines works.
You could try creating a connection to the remote machine's IPC$ share (\\servername\ipc$) and then trying the code. If that works, simply build the code to create a connection prior to calling NetRemoteTOD, and then disconnecting afterwards.
|
|
|
|
 |