Link to home
Start Free TrialLog in
Avatar of ahammar
ahammarFlag for United States of America

asked on

prevent change of date and time

What code can I use to prevent the user from being able to change the computer clock (date and time) using VB6?

Thanks and Cheers!

ahammar
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Look up WM_TIMECHANGE, you can subclass for this message which will let you know when the time has been changed.

Here is an old code of mine:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=35185&lngWId=1

that does exactly this: intercept hte WM_TIMECHANGE message and generates an event when it is found. For the description:

"This class allows you to detect changes in system date and time. It raises an event whenever the date and time is changed by means of the control panel applet"

HTH
Marco

you can rename "timedate.cpl" in c:\windows\system32

then user's can't open the time propertys anymore
>>you can rename "timedate.cpl" in c:\windows\system32


if you use xp, xp will restore the file back if you rename the file
>What code can I use to prevent the user from being able to change the computer clock (date and time) using VB6?

You can't.  You can only detect when the time was changed, as others have stated.

Why are you trying to prevent the system time from being changed?  Is this part of some security issue?  
Avatar of ahammar

ASKER

Thanks everyone!
I will review these options and see what I can come up with.

dancebert:
Actually, I am writing a simple app that will only allow windows to run up to a certain time, then shut off.  This is for my kids.  I know how to make the computer shut off, but once they figure out that all they would need to do is change the computer clock back before the shut down time, then it would be useless, so I need to prevent them from being able to change the clock.  I may have other people that want to use it also, so I need to have my app to be able to do this.

Thanks again everyone.
I'll be back.

Cheers!
ahammar

ASKER CERTIFIED SOLUTION
Avatar of Mark_FreeSoftware
Mark_FreeSoftware
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ahammar

ASKER

Thanks again everyone!

I've decided that mark Freesoftware had the easiest solution.  I already know how to do that so I just whipped up a test app and it works very well.
I tried your link Hit MN, but the code gave me a "Can't find Class error" (or something like that), so that's as far as I went.
I had actually already thought about doing it the way Mark Freesoftware suggested, but I wanted to see if there was just some way to lock the clock properties or something.  But since it was also suggested here, I tried it, and it works good.
Just 1 more problem now though... Do all OS's have the same window title for the time and date properties?
I know XP's is just "Time and Date Properties".  That's the only way I can find the Hwnd of the window.

Should I just post another question for each OS maybe??  That's probably the best way to find the title of all the 32 bit os's...

Thanks!
Cheers!
ahammar

>>Should I just post another question for each OS maybe??
if you have enough points, this would be the easiest way


but i can tell you this:
it depends on the language of windows

mine says:
"Eigenschappen voor Datum en tijd"

it got that string from the resource table,
to find the good string, open "timedate.cpl" with resource hacker
it is string id 304


mark
Avatar of ahammar

ASKER

I'm going to accept Mark's comment as answer.  That is the best way here I think.  I've got the main part of my app done and closing the window works great on 98 and XP and I assume it will probably work on all os's.  I'm going to post a question for each OS and get as much info in as many languages as I can and impliment them all, plus offer the user a setup option to enter his own window title in the rare cases where it won't work.

Mark:
I don't know what resource hacker is or what you mean by string id.  Is that something simple enough to fill me in on?  If it's to complicated, then I'll continue with my current plan.

Cheers!
Albert
Avatar of ahammar

ASKER

Thank you All!

Albert

thanks for the points, and happy coding!


this example will give a messagebox with the title of the dialog (atleast in my version of the timedate.cpl)

it will read the string from the id 304


Option Explicit

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function LoadString Lib "user32" Alias "LoadStringA" (ByVal hInstance As Long, ByVal wID As Long, ByVal lpBuffer As String, ByVal nBufferMax As Long) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long

Private Sub Main()
MsgBox readProp
End Sub


Private Function readProp()
    Dim hInstance As Long
    Dim sResString As String
    Dim lRet As Long
    hInstance = LoadLibrary("timedate.cpl")
    If hInstance Then
        'Allocate space for call:
        sResString = Space$(512)
        'Load the resource from the DLL:
        lRet = LoadString(hInstance, 304&, sResString, 512)
        If lRet Then
            'Display the results:
            readProp = Left$(sResString, lRet)
        End If
        FreeLibrary hInstance
    End If
End Function

Avatar of ahammar

ASKER

Thanks Mark...
It works on mine too.  I'll try it on a couple more os's later and see if it works and if so, that might be the ticket I need!
Thanks again!

Albert