Solved

prevent change of date and time

Posted on 2006-07-12
14
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

696 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