Results 1 to 8 of 8

Thread: Change system date

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    4

    Arrow Change system date

    I have a sheet set up to expire after a certain date in Excel. The biggest flaw in this is someone changing the system date back. Is there a way to make sure the system date is current before the workbook will open? Thanks for any help you can offer.
    Code:
    Private Sub Workbook_Open()
    'ThisWorkbook code! double click ThisWorkbook and enter this code
    Dim Message$, Title$, Default$, myUnLock$, myTest$
    
    Sheet1.Visible = True
    myTest = Sheet1.Range("IV1").Value
    If (myPW = "gabriel" And myTest = myPW) Then End
    
    myUnLock = "gabriel"
    Sheet1.Unprotect Password:=myUnLock
    
    If (Date > #2/28/2007# And _
    Sheet1.Visible <> xlVeryHidden And _
    myUnLock <> myTest) Then
    MsgBox "You need a password to continue"
    Sheet1.Protect Password:=myUnLock
    Sheet1.Visible = xlVeryHidden
    End If
    
    If (Date > #2/28/2007# And _
    Sheet1.Visible = xlVeryHidden) Then
    Message = "Enter your Un-Lock code below:" ' Set prompt.
    Title = "Unlock Sheet!" ' Set title.
    Default = "" ' Set default.
    myPW = InputBox(Message, Title, Default)
    End If
    
    If myPW = myUnLock Then
    Sheet1.Unprotect Password:=myUnLock
    Sheet1.Visible = True
    
    'Optional permanent UnLock by password:
    'comment the line below to lock each time opened after date!
    Sheet1.Range("IV1").Value = myPW
    
    Sheet1.Select
    End If
    
    End Sub
    
    Sub mySheets()
    Sheet1.Visible = True
    Sheet1.Select
    Sheet1.Unprotect Password:="gabriel"
    'Worksheets("Sheet1").Protect Password:="gabriel"
    End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Change system date

    Welcome to the Forums.

    There are several things you could do.

    Write the system date to the registry, but disguised or encrypted so the user cant find it and change it, on the first run
    of the program. Then each time it is run you chech against the system date and compare the registry date. If the
    system date is before the registry date then they changed it back, etc.

    You could have it check out to the internet to a time server and compare the actual date to the system date.

    You could also check in MartinLiss' signature for "A Program Registration Scheme" demo code project.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    4

    Re: Change system date

    Quote Originally Posted by RobDog888
    Welcome to the Forums.

    There are several things you could do.

    Write the system date to the registry, but disguised or encrypted so the user cant find it and change it, on the first run
    of the program. Then each time it is run you chech against the system date and compare the registry date. If the
    system date is before the registry date then they changed it back, etc.
    This sounds the easiest. Can you point me in the right direction on how to do this?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Change system date

    You would need to use the GetSetting and SaveSetting functions. They only read/write to the VB and VBA Program Settings
    key but in there you can name it however you want. If you want to read/write to other areas in the registry you may
    come accross issues where the user does not have registry permissions.


    VB Code:
    1. 'Read:
    2. Dim sInstallDate as string
    3. sInstallDate = GetSetting("AppName", "Section", "InstallDate", "Default")
    4.  
    5. 'Write:
    6. SaveSetting "AppName", "Section", InstallDate", CStr(Date))
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    4

    Re: Change system date

    Yeah that would be a problem. I am sure that some of the people who will use my workbook won't have administrator rights. People tend to panic when you mess with the registry.

    "You could have it check out to the internet to a time server and compare the actual date to the system date."

    I would love to use this, but too many people have web pages blocked. The simplest pages i.e. google are blocked with a program called we-block.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Change system date

    No, I was referring to the other areas of the registry. The VB and VBA program and settings key does not need
    special prividgels because of the way its designed for programs to write to by default using the get and save settings.

    Edit: There is also somewhere on the forums a 30 day trial code if I remember correctly.
    Last edited by RobDog888; Apr 24th, 2005 at 08:26 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    4

    Re: Change system date

    VB Code:
    1. 'Read:
    2. Dim sInstallDate as string
    3. sInstallDate = GetSetting("AppName", "Section", "InstallDate", "Default")
    4.  
    5. 'Write:
    6. SaveSetting "AppName", "Section", InstallDate", CStr(Date))

    Could you give me an example of how these sections might be filled in, or is the code the way it is suppose to be already? ("AppName", "Section", "InstallDate", "Default") I would really like to try this.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Change system date

    Sure, no problem. Its just about as you would need it but you may want to change the key name so they dont
    know what it means and encrypt the value.

    VB Code:
    1. 'Read:
    2. Dim sInstallDate as string
    3. sInstallDate = GetSetting("MyExcelAppTitle", "Settings", "InstallDate", "")
    4.  
    5. 'Write:
    6. SaveSetting "MyExcelAppTitle", "Settings", InstallDate", CStr(Date))
    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width