In continuation with a post that I had made
earlier, I have tried to put together a script but somehow it doesn’t function as intended.
As mentioned in my earlier post, I have compiled two separate but related scripts into
EXE files. The first file is run only once to authorize the second file and if authorized then allow it to run. Currently, these two scripts work fine and the script allows me to define the
amount of days from installation till which the file should function.
My request in the earlier post was to be able to fine tune the script whereby I could set the exact date on which the script (exe file) should
stop functioning (
instead of the current setting whereby I can only specify the amount of days for which to function) and preferably
self delete once that date has arrived.
The (initial) working code for the above two files is –
File One –
Code:
#NoTrayIcon
InputBox, InputPass, Script Permit, Please enter password, HIDE,,120,,,, 20
If ErrorLevel
ExitApp
MyPass = apple
If (InputPass = MyPass)
{
RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, Software\Microsoft\BunchOBS\, Banana, %A_NowUTC%
SplashTextOn, 100, 40,, Enabled Ok.
}
Else
{
RegDelete, HKEY_LOCAL_MACHINE, Software\Microsoft\BunchOBS,
SplashTextOn, 100, 40,, Disabled Ok.
}
Sleep, 1000
SplashTextOff
File Two –
Code:
RegRead, RunOk, HKEY_LOCAL_MACHINE, Software\Microsoft\BunchOBS, Banana
RunOk += 90, days
If (ErrorLevel or A_NowUTC > RunOk)
ExitApp
Return
Like I mentioned above this works perfectly – File One when given the correct password (
apple in my code above) will insert
Banana in the Registry and File Two will work for
only 90 days from the date of installation provided it reads Banana in the Registry.
The new code that I am now trying to incorporate in
File Two (which does
not work) is as under –
Code:
CheckExpiry:
FormatTime, CurrentYear , YYYY, yyyy
FormatTime, CurrentMonth , MM, M
FormatTime, CurrentDay , dd, d
If (CurrentYear > 2007 Or CurrentMonth > 9 or CurrentDay > 10) ; valid till 10/Sep/2007.
RegDelete, HKEY_LOCAL_MACHINE, Software\Microsoft\BunchOBS,
If A_IsCompiled {
FileAppend,
(
Wscript.Sleep 2000
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.GetFile("%A_ScriptFullPath%")
MyFile.Delete
'Delete the currently executing script
Dim objFSO 'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile WScript.ScriptFullName
Set objFSO = Nothing
)
, %A_Temp%\selfDelete.VBS
Run, %A_Temp%\selfDelete.VBS
ExitApp
}
Else
RegRead, RunOk, HKEY_LOCAL_MACHINE, Software\Microsoft\BunchOBS, Banana
RunOk += 90, days
If (ErrorLevel or A_NowUTC > RunOk)
ExitApp
Return
(
The rest of File Two contains my Hotkeys)
Now this is what I thought and desired the code
would do but unfortunately it
doesn’t – when the exe file loads, I would like it to first check the Expiry date as set by me (as per the code given above in
blue). In my code above the Expiry date is set for 10/Sep/2007. Hence, if the date is before 10/Sep/2007, the file should function as normal. If the date is beyond 10/Sep/2007, the file should self-delete (as per the code given above in
brown). The codes given in
red are taken from the original two files – that is – if the date is beyond 10/Sep/2007, before running the self-delete command, it should remove the Registry Entry that had been entered earlier by File One and the code in
red after the code in
brown is for the file to read from the Registry and authorize the functioning.
Somehow the Expiry code and the RegRead code do
not seem to work in tandem – mostly it must be because I haven’t coded it correctly. The Expiry code by itself works fine as does the Self-Delete code and obviously the RegRead code has been working fine as I have been using it thus far. If both the codes are together in the same file (as intended) the Expiry code (in
blue) supersedes the RegRead code (in
red) and works even if the Registry entry (
Banana in my example) is
not there.
This nullifies the authorization process, which is not desired. Instinctively, I feel there needs to be an IF and an ELSE and perhaps other commands that would make the script do – If the date is beyond 10/Sep/2007, delete the Registry Entry and delete yourself; else RegRead the Registry Entry and if it matches let the file load and function.
Ideally the code that I would like to have would be – (Hoping that the Expiry and Self-Delete codes given above in
blue and
brown is in order), which would effectively give me better flexibility over making the exe file terminate on a pre-decided date, the option of
RunOk += 90, days can be completely eliminated from the new code.
There is no point in having two different options in the same file to specify when the exe file must stop functioning.
My requirement would be –
1. As before, File One should make a Registry Entry to authorize File Two to function.
2. File Two should be able to read the Registry made by File One and function only if the entry matches.
3. File Two should have the code whereby I can set the exact Expiry date for the exe file to stop functioning (instead of the amount of days) and once that date has arrived – File Two should first remove the Registry Entry made by File One and then delete itself.
Intuitively all the above codes seems quite correct and it is right there but all in different parts – I just need someone to please help put it all together so that it can work as intended?
Sincere Gratitude