|
-
Oct 31st, 1999, 03:27 PM
#1
Thread Starter
Lively Member
Is there a way to retrieve the System time on a network PC. I have the Name and IP of the destination PC.
Thanks in advance,
Steve.
-
Nov 1st, 1999, 08:32 AM
#2
Thread Starter
Lively Member
OK with the wealth of knowledge out there, I can't believe that nobody has an answer to my question.
If you can't get the system time, then is it possible to synchronise the 2 (or more) PC's system times.
Steve.
-
Nov 1st, 1999, 09:12 AM
#3
Addicted Member
Steve, I looked around and found nothing on it. I'm sure it can be done, but I don't know of anyone who has wanted to do this before. All, I know is, you could install executables on each workstation. Make sure the server can "see" the drive that the executable is on. Write the server application to execute the other programs and thats it! You can exectute other exe's by using the shell() function. Other than that, its just a matter of locating the right API and translating it from C documentation to Basic language. You will probably find the Date and time dialog box in any one of these libraries:
Kernel32.dll
User32.dll
Comdlg32.dll
LZ32.dll
Version.dll
I recommend you go sit down at barnes and noble, find a big ass book on Win32 API and see if you can't find that bad boy.
The reason no one is really going to know is because not many people are going to want to control the time on other PCs.
Hope that helps a little,
Phil
-
Nov 1st, 1999, 09:44 AM
#4
Addicted Member
Ok, you owe me a beer 
Take a look at SetSystemTime() function and the SYSTEMTIME structure. There was also a SetSystemTimeAdjustment() Function that may be of use to you.
Both are in the kernal.dll library. They both take the SYSTEMTIME Type as a argument and return a long. If you run into any problems I may be able to create you some sample code, but I recommend you buy Dan Appleman's "Visual Basic Programmers guide to the Win32 API", which goes into all the time functions.
Have a good one,
phil
-
Nov 1st, 1999, 10:09 AM
#5
Addicted Member
Heres some code on GetSystemTime(). SetSystemTime works almost the exact same way. You have to format the time and store it in the systemtime TYPE and then call the function.
Hope it helps:
Phil
Option Explicit
Private Const LOCALE_SYSTEM_DEFAULT& = &H800
Private Const LOCALE_USER_DEFAULT& = &H400
'**********************************
'** Type Definitions:
#If Win32 Then
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 As String * 64
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName As String * 64
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
#End If 'WIN32 Types
'**********************************
'** Function Declarations:
#If Win32 Then
Private Declare Function GetLocaleInfo& Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long)
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Declare Sub GetSystemTimeAdjustment Lib "kernel32" (lpTimeAdjustment As Long, lpTimeIncrement As Long, lpTimeAdjustmentDisabled As Long)
Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Declare Function GetTimeZoneInformation& Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION)
Private Declare Function GetTimeFormat& Lib "kernel32" Alias "GetTimeFormatA" _
(ByVal Locale As Long, ByVal dwFlags As Long, lpTime As SYSTEMTIME, _
ByVal lpFormat As Long, ByVal lpTimeStr As String, ByVal cchTime As Long)
#End If 'WIN32
Private Sub Form_Load()
Dim myTZ As TIME_ZONE_INFORMATION
Dim myAdj&, myIncr&, myDisabled&
Dim s$, dl&
GetSystemTimeAdjustment myAdj&, myIncr&, myDisabled&
If myDisabled& Then
txtAdjust = "Disabled."
Else
txtAdjust = myAdj& & " ns Every " & myIncr& & " ns."
End If
dl& = GetTimeZoneInformation(myTZ)
txtTZBias = CInt(myTZ.Bias / 30) / 2 & " hours"
s$ = myTZ.StandardName
txtTZName = StrConv(s$, vbFromUnicode)
s$ = myTZ.DaylightName
txtTZSName = StrConv(s$, vbFromUnicode)
End Sub
'
' Obtain the system and local time and display them
'
Private Sub Timer1_Timer()
Dim myTime As SYSTEMTIME, s$, dl&
GetLocalTime myTime
s$ = String$(255, Chr$(0))
dl& = GetTimeFormat&(LOCALE_SYSTEM_DEFAULT, 0, myTime, 0, s$, 254)
txtLocTime = s$
GetSystemTime myTime
s$ = String$(255, Chr$(0))
dl& = GetTimeFormat&(LOCALE_SYSTEM_DEFAULT, 0, myTime, 0, s$, 254)
txtSysTime = s$
End Sub
Private Sub txtNum_Change()
End Sub
Private Sub txtLocTime_Change()
End Sub
-
Nov 1st, 1999, 08:32 PM
#6
New Member
I needed to find the system time on all of our networked PCs after the clocks were turned back this past weekend. I used the following code for this task. The DateCreated method of the FileSystemObject uses the system clock of the target PC when it returns the date.
'Create an output file
open sOutputFile for Output As #1
'Loop through the following code for each machine on the network.
'Create a text file on the target machine
sRemoteFile = sCompName & "\c$\Test.txt"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile(sRemoteFile, True, True)
'Create a text file on the local machine. Use this file to compare time differences
'between the target and local machines. This file should be named differently at each
'loop iteration for this to work correctly.
sLocalFile = "C:\TEMP\~000"
sLocalFile = sLocalFile & Str$(Int(Rnd() * 10000) + 1) & ".TXT"
Set fs1 = CreateObject("Scripting.FileSystemObject")
Set f1 = fs.CreateTextFile(sLocalFile, True, True)
'Get DateCreated for each machine and print results to file
Set f = fs.GetFile(sRemoteFile)
Set f1 = fs1.GetFile(sLocalFile)
s = sCompName & " Target Time: " & f.DateCreated
s1 = vbTab & "Local Time: " & f1.DateCreated
Print #1, s & s1
'Delete files created for determining system time
Kill sRemoteFile
Kill sLocalFile
'End loop
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
|