Solved

prevent change of date and time

Posted on 2006-07-12
14
334 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:ahammar
  • 5
  • 4
  • 2
  • +3
14 Comments
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 17090137
Look up WM_TIMECHANGE, you can subclass for this message which will let you know when the time has been changed.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 17090424
0
 
LVL 6

Expert Comment

by:Hit_MN
ID: 17090867

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
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 17090950

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

then user's can't open the time propertys anymore
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 17091032
>>you can rename "timedate.cpl" in c:\windows\system32


if you use xp, xp will restore the file back if you rename the file
0
 
LVL 9

Expert Comment

by:dancebert
ID: 17091600
>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?  
0
 
LVL 23

Author Comment

by:ahammar
ID: 17095381
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

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 500 total points
ID: 17095604

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
0
 
LVL 23

Author Comment

by:ahammar
ID: 17096524
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
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 17097617

>>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
0
 
LVL 23

Author Comment

by:ahammar
ID: 17105348
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
0
 
LVL 23

Author Comment

by:ahammar
ID: 17105352
Thank you All!

Albert
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 17106831

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

0
 
LVL 23

Author Comment

by:ahammar
ID: 17107248
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
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now