-
Oct 31st, 2000, 07:03 AM
#1
Thread Starter
Lively Member
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.
-
Nov 1st, 2000, 07:00 AM
#2
Lively Member
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)
-
Nov 1st, 2000, 08:15 AM
#3
Thread Starter
Lively Member
OK, Orpheus, but --->
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. :-))
-
Nov 1st, 2000, 09:21 AM
#4
Lively Member
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 ...
-
Nov 1st, 2000, 11:14 AM
#5
Thread Starter
Lively Member
OK
MANY THANX, Orpheus !!! It worked and helped me A LOT !!!
-
Nov 6th, 2000, 11:08 AM
#6
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,
-
Nov 11th, 2000, 02:37 PM
#7
Fanatic Member
Try this:
Code:
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]
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Nov 11th, 2000, 02:49 PM
#8
I've found another way of defeating my problem. Let me know if you want me to post my solution. Thanks, for your reply.
-
Nov 13th, 2000, 02:19 AM
#9
Thread Starter
Lively Member
Yes Caspian, I'd like to see your different solution.
Surgeon
-
Nov 13th, 2000, 08:58 AM
#10
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
-
Nov 13th, 2000, 09:32 AM
#11
Thread Starter
Lively Member
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
-
Nov 13th, 2000, 01:24 PM
#12
Sorry, I didn't try it under those OS's because I have no need to.
-
Jan 5th, 2001, 12:42 PM
#13
Hyperactive Member
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...
-
Jan 5th, 2001, 02:59 PM
#14
Lively Member
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).
-
Jan 8th, 2001, 06:47 AM
#15
Hyperactive Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|