Results 1 to 9 of 9

Thread: [RESOLVED] make your system will expire in a certain period

  1. #1

    Thread Starter
    Lively Member nthski's Avatar
    Join Date
    Aug 2014
    Posts
    83

    Resolved [RESOLVED] make your system will expire in a certain period

    Code:
    Private Sub Form_Load()
    If DateValue(Label2.Caption) < Date Then
    MsgBox ("you need to contact the author for updates")
    DeleteFile ("prj1.exe")
    Else
    Label3.Caption = DateValue(Label2.Caption) - Date
    End If
    End Sub
    code in module
    Code:
    Declare Function DeleteFile Lib "kernel32.dll" Alias "DeleteFile" _
    (ByVal lpFileName As String) As Long
    good day sir / mam i have an project that will check an expiration i have code this above but it cant be delete itself file can someone hellp me i need when form load check expiration then if expired it will delete me
    Last edited by nthski; Sep 15th, 2014 at 10:49 AM.
    You can measure a programmer's perspective by noting his attitude on the continuing vitality of FORTRAN.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: make your system will expire in a certain period

    You can't delete a file while it is open.

    There is also no reason to delete your exe, if you want to do a timed trial you would just have the program close if the time is up.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: make your system will expire in a certain period

    No, you cannot delete an executable file that is, well, 'executing'. Really no need to delete it, just close it...like:
    Code:
    Private Sub Form_Load()
    If DateValue(Label2.Caption) < Date Then
    MsgBox ("you need to contact the author for updates")
    unload me
    Else
    Label3.Caption = DateValue(Label2.Caption) - Date
    End If
    End Sub
    EDIT: Sorry....just saw DM's post...same as mine.....

  4. #4

    Thread Starter
    Lively Member nthski's Avatar
    Join Date
    Aug 2014
    Posts
    83

    Re: make your system will expire in a certain period

    thanks thnks hmm no other way to remove own file if expired ?
    You can measure a programmer's perspective by noting his attitude on the continuing vitality of FORTRAN.

  5. #5
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    Re: make your system will expire in a certain period

    If the executable is run from a directory to which the user has update access then yes, but you have to use a script to side-step the fact that a running program can't be deleted (even by itself). You could have your program create a .bat file with a "sleep" command and an "erase" command in it, shell that from your program and then close the program as quickly as you can.
    Might work. Wouldn't rely on it, though.

    If the executable is installed, i.e. run from a directory somewhere under C:\Program Files*, then the only way to get rid of it is to uninstall it.

    Far, far, better to simply "deactivate" functionality within the program after your expiry period.

    Regards, Phill W.

  6. #6

    Thread Starter
    Lively Member nthski's Avatar
    Join Date
    Aug 2014
    Posts
    83

    Re: make your system will expire in a certain period

    thanks thanks
    You can measure a programmer's perspective by noting his attitude on the continuing vitality of FORTRAN.

  7. #7

    Thread Starter
    Lively Member nthski's Avatar
    Join Date
    Aug 2014
    Posts
    83

    Re: make your system will expire in a certain period

    call shell temp.bat then del/f/a prj1.exe
    is that correct ?
    You can measure a programmer's perspective by noting his attitude on the continuing vitality of FORTRAN.

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: make your system will expire in a certain period

    Yes as long as the exe has already closed


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  9. #9
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    Re: make your system will expire in a certain period

    Just to reiterate:

    Something like this should work:
    Code:
     
    delete  C:\Users\Fred\Documents\prj1.exe

    Something like this will not:
    Code:
     
    delete  C:\Program Files\ACME\prj1\prj1.exe
    (Assuming that your program is properly written, i.e. doesn't run "as Administrator", and that U.A.C. is enabled on the machine).

    Regards, Phill W.

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