Click to See Complete Forum and Search --> : another's PC time ?? Can I get it ? plz help
Surgeon
Oct 31st, 2000, 06:03 AM
Does anyone know how do I get another's computer date/time ? I mean if my PC is on a 95/98/ME network, how do I find out the system time of an other speciffic computer ? Is there an API that could do it for me ?
Plz help.
Orpheus
Nov 1st, 2000, 06:00 AM
You could write a DCOM routine that executes on the local and remote PC's and then simply use the Date() function.
If you are looking to set the time based upon the time on another machine, then use the NET command (Net /? for help)
Surgeon
Nov 1st, 2000, 07:15 AM
Orpheus, thanks for the help. The NET command works fine indeed, but I would need an API function that could return me the time in a variable when I give it as parameter the other computer's name, or something like that. Maybe you could be more specific about that DCOM routine ? Plz. :-))
Orpheus
Nov 1st, 2000, 08:21 AM
Create an activex exe project in vb. for this example, we will call it Server.
Within the project, create a class called TimeServer, and within the class create
public function LocalTime() as Variant
LocalTime = Now()
end function
Select the project properties, and ensure the tickbox is set for unnattended execution and remote server files.
Now compile the project and create a distribution.
Now create a standard exe project. Within the project references, select the previous Server project.
Add a button to the default form with the following code
Private Sub Command1_Click()
Dim objServer As Server.TimeServer
Set objServer = CreateObject("server.TimeServer", "localhost")
MsgBox objServer.LocalTime
End Sub
when you run this project, pressing the button will give you a message box with the time from the local machine. If you wish to be able to interrogate other machines, install the initial "Server" project onto the machine in question and then specify the host name for the machine in place of 'localhost'.
DCOM will automatically start the server on the remote machine and return the time from that machine for you.
It is (i believe) possible to remotely install the Server project accross a network remotely on demand, but I have not yet acheived this myself.
Hope it helps ...
Surgeon
Nov 1st, 2000, 10:14 AM
MANY THANX, Orpheus !!! It worked and helped me A LOT !!!
Hi guys, is there any way of having the NET TIME command return the time from a remote PC back to the local machine in VB? I'm looking for a solution to getting the remote machine's time WITHOUT putting anything on the remote machine.
Thanks,
gwdash
Nov 11th, 2000, 01:37 PM
Try this:
Function GetNetTime(PCName)
Dim TimeText As String
Dim NetTime As String
Dim NetTimeAsDate As Date
Dim ShellString As String
Dim i As Integer
ShellString = "command.com NET TIME \\" & PCName & " > c:\time.txt" 'get time
Shell ShellString
Open "c:\time.txt" For Input As #1
Line Input #1, TimeText 'read file
Close #1
i = InStr(1, TimeText, "is ", vbTextCompare)
TimeText = Mid(TimeText, i + 3)
i = InStr(1, TimeText, " ", vbTextCompare)
TimeText = Mid(TimeText, i + 1)
i = InStr(1, TimeText, "M", vbTextCompare)
TimeText = Left(TimeText, i - 2)
NetTime = Format(TimeText, "H:M AM/PM")
NetTimeAsDate = CDate(NetTime)
GetNetTime = NetTime 'for string (H:M AM/PM)
'GetNetTime = NetTimeAsDate 'for date(H:M:SS AM/PM) (Date Data Type)
End Function
It leaves an MS-DOS window open on my PC though, if that's a problem, you could use API's to close it (FindWindow & SendMessage) I can give you that code if you want
[Edited by gwdash on 11-11-2000 at 02:39 PM]
I've found another way of defeating my problem. Let me know if you want me to post my solution. Thanks, for your reply.
Surgeon
Nov 13th, 2000, 01:19 AM
Yes Caspian, I'd like to see your different solution.
Surgeon
Private Declare Function NetRemoteTOD Lib "Netapi32.dll" (tServer As Any, pBuffer As Long) As Long
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Private Declare Function NetApiBufferFree Lib "Netapi32.dll" (ByVal lpBuffer As Long) As Long
Private 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
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal length As Long)
Public Function GetServerDateTime(ByVal strServer As String, dtRetDatum As Date) As Boolean
Dim dtResult As Date
Dim lngRetCode As Long
Dim TOD As TIME_OF_DAY_INFO
Dim lngBuff As Long
Dim tServer() As Byte
On Error GoTo err_handler
tServer = strServer & vbNullChar
lngRetCode = NetRemoteTOD(tServer(0), lngBuff)
If lngRetCode = 0 Then
CopyMemory TOD, ByVal lngBuff, Len(TOD)
NetApiBufferFree lngBuff
dtResult = TimeSerial(TOD.tod_hours, TOD.tod_mins - TOD.tod_timezone, TOD.tod_secs)
dtRetDatum = dtResult
Else
Err.Raise Number:=vbObjectError + 1001, _
Description:="cannot get remote TOD"
End If
GetServerDateTime = True
Exit Function
err_handler:
GetServerDateTime = False
End Function
Surgeon
Nov 13th, 2000, 08:32 AM
Well, thanks, that maybe works under NT/2000 because NetRemoteTOD is only supported under NT/2000. How about Win95/98/ME ? Did you tried it like that ?
Surgeon
Sorry, I didn't try it under those OS's because I have no need to.
Bananafish
Jan 5th, 2001, 11:42 AM
Sorry to re-open an old thread - but I am trying to do something similar to the original request (except rather than get the time, I am testing to see if an exe is running on the remote machine).
Anyway - to cut a long story short - I have being trying to get the example posted by ORPHEUS to work, and find that although it works on the "localhost", if I try using the "remote" machine it says it can't find the activex exe.
Orpheus states that I must "install" the original "server" project onto the machine in question - which I thought I had done - but I guess I haven't done it properly - could someone maybe elaborate for me exactly what I need to do for the install? I did try using regsvr32 - but that obviously didnt work as it isnt a "dll" or an "ocx". Is there something similar for an activex exe?
Thanks in advance...
Orpheus
Jan 5th, 2001, 01:59 PM
RegSvr32 is not sufficient. You are installing an ActiveX EXE VB Executable, this will require all of the run-time files as would be used by a standard VB executable.
Simply use the Package and Deployment wizard to create an installation routine and then install as per normal on the machine to be interrogated (Server).
Bananafish
Jan 8th, 2001, 05:47 AM
Thanks for the reply.
I kinda got it working - in that it gets the local time ok, however I am trying to test to see if a specific application is running on the remote machine (using calls such as:-
Process32First, Process32Next, OpenProcess, EnumProcesses, GetWindowText, GetWIndowTextLength etc.
Anyway - basically the only applications I appear to see on the remote machine is the activex exe, "dde server window" and "OLEmain threadwndname".
This is a shame - I don't suppose you have any ideas?
(I guess really I should open this as a new message thread...)
Thanks again for your previous reply
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.