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!

LVL 23
Who is Participating?
Mark_FreeSoftwareConnect With a Mentor Commented:

if that is the issue,

check every second or half second while the "control" program is open if you can find a dialog with that title, and close/hide it
Look up WM_TIMECHANGE, you can subclass for this message which will let you know when the time has been changed.
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.


Here is an old code of mine:

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"


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?  
ahammarAuthor Commented:
Thanks everyone!
I will review these options and see what I can come up with.

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.


ahammarAuthor Commented:
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...


>>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

ahammarAuthor Commented:
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.

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.

ahammarAuthor Commented:
Thank you All!


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

ahammarAuthor Commented:
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!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.