Solved

NetRemoteTOD

Posted on 1997-12-15
14
343 Views
Last Modified: 2009-07-29
I work in VB3 and I want use the NetRemoteTOD function of NETAPI.DLL
 I have:
Type TIME_OF_DAY_INFO
 tod_elapsedt As Long
 tod_msecs As Long
 tod_hours As Long
 tod_mins As Long
 tod_secs As Long
 tod_hunds As Long
 tod_timezone As Long
 tod_tinterval As Long
 tod_day As Long
 tod_month As Long
 tod_year As Long
 tod_weekday As Long
End Type
Global TOD1 As TIME_OF_DAY_INFO
Declare Function NetRemoteTOD Lib "NETAPI.DLL" (ByVal SName&, TOD As TIME_OF_DAY_INFO) As Integer

when I use the NetRemoteTOD function obtain GPF.

How can I use (in VB3) the NetRemoteTOD function for obtain the time of day information from a specified server ?

I want a sample please !!!
0
Comment
Question by:miguelpf
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 8

Expert Comment

by:mrmick
ID: 1445291
A sample doesn't fall into to the easy (50-point) category!  But for 50...

1) The declare is wrong:

Declare Function NetRemoteTOD Lib "NETAPI32.DLL" (ByVal SName as String, TOD As TIME_OF_DAY_INFO) As Long

2) WinNT: Yes  Win95: No  Win32: No

3) The SName string must be in Unicode format, VB3 doesn't save strings in Unicode format.  I believe you could convert the string to Unicode format, but I don't know if VB3 strings can contain chr$(0) bytes (It's been so long since I've worked in VB3).

0
 

Author Comment

by:miguelpf
ID: 1445292
thanks, but i need obtain the time of day information from a specified server in VB3 without use "NET TIME \\SERVER" of DOS
0
 
LVL 4

Expert Comment

by:rantanen
ID: 1445293
Are you targeting to NT, 'cause

NetRemoteTOD
...
Windows NT: Use version 3.1 and later.
Windows: Unsupported.
0
 
LVL 6

Accepted Solution

by:
alamo earned 100 total points
ID: 1445294
If I recall, VB3 was 16-bit only.... so the chances that any of what has been said are correct is very small ;-) "NETAPI.DLL" in the original question was a tipoff also. (Though the declarations were the 32 bit versions... no wonder it GPFed :-)

By the way, mrmick, your Win32 prototype was wrong (just in case it ever comes up - look at it more closely and you'll see).

Here is the prototype and sample code for 16-bits.

' 16-bit declares - note they are different than the 32 bit ones!
Type TIME_OF_DAY_INFO
 tod_elapsedt   As Long      '/* time from 1-1-1970 in seconds */
 tod_msecs As Long           '/* milliseconds */
 tod_hours As Byte           '/* hours */
 tod_mins As Byte            '/* minutes */
 tod_secs As Byte            '/* seconds */
 tod_hunds As Byte           '/* hundredths */
 tod_timezone As Integer     '/* time zone in minutes from GMT */
 tod_tinterval As Integer    '/* timer interval (units = 0.0001 sec) */
 tod_day As Byte             '/* day */
 tod_month As Byte           '/* month */
 tod_year As Integer         '/* year */
 tod_weekday As Byte         '/* day of week */
End Type
Declare Function NetRemoteTOD Lib "NETAPI.DLL" (ByVal pszServer As String, pbBuffer As TIME_OF_DAY_INFO, ByVal cbBuffer As Integer) As Integer


Dim tTime As TIME_OF_DAY_INFO
Dim lLength As Integer
Dim lReturn As Integer
Dim swServername As String

lLength = Len(tTime)
swServername = ""    ' server, blank works

lReturn = NetRemoteTOD(swServername, tTime, lLength)

Debug.Print "lReturn     = " & lReturn
Debug.Print "Elapsed     = " & tTime.tod_elapsedt
Debug.Print "Milliseconds= " & tTime.tod_msecs
Debug.Print "Hours       = " & tTime.tod_hours
Debug.Print "Minutes     = " & tTime.tod_mins
Debug.Print "Seconds     = " & tTime.tod_secs
Debug.Print "Hundreds    = " & tTime.tod_hunds
Debug.Print "Time Zone   = " & tTime.tod_timezone
Debug.Print "Time Intervl= " & tTime.tod_tinterval
Debug.Print "Day         = " & tTime.tod_day
Debug.Print "Month       = " & tTime.tod_month
Debug.Print "Year        = " & tTime.tod_year
Debug.Print "Weekday     = " & tTime.tod_weekday

miguelpf, hope this is what you need. By the way, I would really appreciate it if you would increase the points before you grade,  it did take a while to track all this down and get it to work.

Let me know if you ahve problems with this, and good luck!
0
 
LVL 4

Expert Comment

by:rantanen
ID: 1445295
Alamo,

did you test it with VB3 or VB4/16, because VB3 does not have data type BYTE, so probably some difficulties ahead. (See your type definition TIME_OF_DAY_INFO ).
0
 
LVL 6

Expert Comment

by:alamo
ID: 1445296
Oooh, thanks, rantanen - I was switching between 32 and 16 bit VBs and endd up in VB4/16 - made a mental note to adjust for the lack of byte and forgot completely!

I just converted it to VB3 and it still works fine I changed only the Type definition and the Debug.print statements (easy) but I might as well post the whoile thing again:

' 16-bit VB3 declares - note they are different than the 32 bit ones!
Type TIME_OF_DAY_INFO
 tod_elapsedt   As Long      '/* time from 1-1-1970 in seconds */
 tod_msecs As Long           '/* milliseconds */
 tod_hours As String * 1         '/* hours */
 tod_mins As String * 1          '/* minutes */
 tod_secs As String * 1          '/* seconds */
 tod_hunds As String * 1         '/* hundredths */
 tod_timezone As Integer     '/* time zone in minutes from GMT */
 tod_tinterval As Integer    '/* timer interval (units = 0.0001 sec) */
 tod_day As String * 1           '/* day */
 tod_month As String * 1         '/* month */
 tod_year As Integer         '/* year */
 tod_weekday As String * 1       '/* day of week */
End Type

Declare Function NetRemoteTOD Lib "NETAPI.DLL" (ByVal pszServer As String, pbBuffer As TIME_OF_DAY_INFO, ByVal cbBuffer As Integer) As Integer

Code:

Dim tTime As TIME_OF_DAY_INFO
Dim lLength As Integer
Dim lReturn As Integer
Dim sServername As String

lLength = Len(tTime)
sServername = ""
lReturn = NetRemoteTOD(ByVal sServername, tTime, lLength)

Debug.Print "lReturn=" & lReturn
Debug.Print "Elapsed    = " & tTime.tod_elapsedt
Debug.Print "Milliseconds= " & tTime.tod_msecs
Debug.Print "Hours     = " & Asc(tTime.tod_hours)
Debug.Print "Minutes   = " & Asc(tTime.tod_mins)
Debug.Print "Seconds   = " & Asc(tTime.tod_secs)
Debug.Print "Hundreds  = " & Asc(tTime.tod_hunds)
Debug.Print "Time Zone = " & tTime.tod_timezone
Debug.Print "Time Interval = " & tTime.tod_tinterval
Debug.Print "Day     = " & Asc(tTime.tod_day)
Debug.Print "Month   = " & Asc(tTime.tod_month)
Debug.Print "Year    = " & tTime.tod_year
Debug.Print "Weekday = " & Asc(tTime.tod_weekday)


Sorry about that miguelpf, and thanks rantanen!
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1445297
Sorry alamo, but what do you see that I didn't?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 6

Expert Comment

by:alamo
ID: 1445298
mrmick, the second argument in NetRemoteTOD isn't TIME_OF_DAY_INFO, it's a pointer (passed ByRef) which the API sets to point to the TIME_OF_DAY_INFO buffer which it has allocated itself (and which you must deallocate when you're done with it).
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1445299
alamo,

uh, huh huh, huh huh, uh?  So... you actually think there's a difference in these two lines?

My declaration: TOD As TIME_OF_DAY_INFO
Your declaration: pbBuffer As TIME_OF_DAY_INFO

0
 

Author Comment

by:miguelpf
ID: 1445300
thanks !!!
0
 
LVL 6

Expert Comment

by:alamo
ID: 1445301
Actually, mrmick, that was my 16 bit declaration - it's the WinNT declaration you posted which is wrong, which should be the address not of the structurebut instead the address of a pointer which the API sets to the address of the structure.

The actual call is something like:
Dim ptrTime As Long
...
lReturn = NetRemoteTOD(swServerName, ptrTime)
0
 

Author Comment

by:miguelpf
ID: 1445302
thanks !!!
0
 
LVL 6

Expert Comment

by:alamo
ID: 1445303
You are welcome miguelpf... and thanks for the points!
0
 

Author Comment

by:miguelpf
ID: 1445304
happy new year !!!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now