• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

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
0
ahammar
Asked:
ahammar
  • 5
  • 4
  • 2
  • +3
1 Solution
 
nffvrxqgrcfqvvcCommented:
Look up WM_TIMECHANGE, you can subclass for this message which will let you know when the time has been changed.
0
 
EDDYKTCommented:
0
 
Hit_MNCommented:

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Mark_FreeSoftwareCommented:

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

then user's can't open the time propertys anymore
0
 
EDDYKTCommented:
>>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
 
dancebertCommented:
>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
 
ahammarAuthor Commented:
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
 
Mark_FreeSoftwareCommented:

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

Thanks!
Cheers!
ahammar
0
 
Mark_FreeSoftwareCommented:

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

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

Albert
0
 
Mark_FreeSoftwareCommented:

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

Albert
0

Featured Post

Industry Leaders: 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!

  • 5
  • 4
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now