AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Oops! How do I put this all together - PLEASE HELP!!!

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Varun
Guest





PostPosted: Fri Aug 31, 2007 5:22 pm    Post subject: Oops! How do I put this all together - PLEASE HELP!!! Reply with quote

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
Back to top
Guest






PostPosted: Fri Aug 31, 2007 7:01 pm    Post subject: Reply with quote

Code:
If (CurrentYear > "2007" Or CurrentMonth > "9" or CurrentDay > "10")


Do those explict "s make a difference at all? Sorry I can't really help much more
Back to top
rockNme2349



Joined: 31 Aug 2007
Posts: 3

PostPosted: Fri Aug 31, 2007 8:21 pm    Post subject: Reply with quote

Code:
If (CurrentYear > 2007 Or CurrentMonth > 9 or CurrentDay > 10) ; valid till 10/Sep/2007.


Unless I'm missing something you incorrectly worded your condition. Right now it will fire if the year is past 2007, or if it is past september in whatever year, or if it is past the 10th in whatever month. What you want is

Code:
If (CurrentYear > 2007 And CurrentMonth > 9 And CurrentDay > 10) ; valid till 10/Sep/2007.

_________________
There are 10 types of people. Those that understand binary and those that don't.
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1373

PostPosted: Fri Aug 31, 2007 11:58 pm    Post subject: Reply with quote

Code:
FormatTime, PartialDate,, yyyyMMddHHmmss
EndTime = 20070929000000

TimeRemaining := EndTime - PartialDate

If TimeRemaining < 0
{
   MsgBox, Thank you for trying out appname. Please be sure to try out all future updates
   ExitApp
}


that specifies the time 00:00:00 on 29th september 2007:

Code:
EndTime = 20070929000000
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2699
Location: Australia, Qld

PostPosted: Sat Sep 01, 2007 3:00 am    Post subject: Reply with quote

rockNme2349 wrote:
Code:
If (CurrentYear > 2007 And CurrentMonth > 9 And CurrentDay > 10) ; valid till 10/Sep/2007.
Actually, that won't fire until at least 2008 (> 2007), at least October (>9) and at least the 11th (>10). It won't even fire on 1/Jan/2010.

This:
Code:
If A_IsCompiled {
...
}

Else

RegRead, RunOk, HKEY_LOCAL_MACHINE, Software\Microsoft\BunchOBS, Banana
RunOk += 90, days
If (ErrorLevel or A_NowUTC > RunOk)
ExitApp
Return
is the same as:
Code:
If A_IsCompiled {
...
}
Else
{
    RegRead, RunOk, HKEY_LOCAL_MACHINE, Software\Microsoft\BunchOBS,
}
Banana
RunOk += 90, days
If (ErrorLevel or A_NowUTC > RunOk)
ExitApp
Return
Is that what you intended?
Back to top
View user's profile Send private message
Varun
Guest





PostPosted: Sat Sep 01, 2007 6:43 pm    Post subject: Reply with quote

To begin with, the code given above in blue for Checking Expiry along with the Self-Delete code (in brown) runs perfectly together as intended if the file is running as a compiled EXE file and provided it doesn’t have to do the RegRead option.

Therefore, a script having the following code will run perfectly till 10/Sep/2007 and will self-delete if accessed beyond 10/Sep/2007 –

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.

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

#SingleInstance Force

~Capslock Up::
SetCapsLockState Off
Return

Delete::
  SetTitleMatchMode, 2
  IfWinActive, Microsoft Word
  SendInput, !of
  Else
  SendInput, {Delete}
Return

Insert::
  SetTitleMatchMode, 2
  IfWinActive, Microsoft Word
  SendInput, !is
  Else
  SendInput, {Insert}
Return


(This is followed by other Hotkeys)

I have given two sample Hotkeys just to highlight what the script would look like.

Once again - Please Note – Whereas up-front the above code might not seem to work it is only because it is in AHK mode. When compiled in to an EXE file, the file does stop working and self-delete as intended once the date is beyond 10/Sep/2007.
If there is a way to make it stop even in AHK mode – I am not aware of that – and though it would be a welcome addition to the code – the above works fine in EXE mode, which is what I want.

I think the code given by tic above (though not tested) seems to be an alternative to the CheckExpiry code given by me in blue above. The code that I have used can set the date and if beyond would self-delete the file whereas the code given by tic seems to perhaps be able to even set the exact time on the day and if beyond then pop-up a message box and stop functioning by exiting the application.

Unfortunately, I cannot figure out what lexikos is trying to offer from his code.

From the above, the main thing that is lacking is for incorporating the RegRead option somewhere in the code, which authorizes the script to function as per the Registry Entry made by File One.

Hence my requirement for the code is quite simple actually, it’s just that I cannot seem to put it all together. What I need is –

1. As before, File One should make a Registry Entry to authorize File Two to function.
(This takes care of the first part towards authorizing the file to function)

2. File Two should be able to read the Registry Entry made by File One and function only if the entries match – else – it should exit and preferably self-delete (this is a new addition from the previous post) – that is – besides self-deleting on the Expiry date – the file should self-delete even if the Registry Entry doesn’t match.
(This takes care of the second part towards authorizing the file to function)

3. When the Expiry date (as set by the CheckExpiry code in blue) arrives, the exe file should stop functioning, remove the Registry Entry made by File One and self-delete.
(Currently, the file in exe mode can stop functioning and self-delete but it cannot remove the Registry Entry made by File One)

4. Up until now the code (given in red in my previous post) that I have been using thus far allows me to set the amount of days from installation on which the exe file will stop functioning. This was done by the code RunOk += 90. With the CheckExpiry code (given in blue) I can now set the exact date on which the file must stop functioning and hence the RunOk += 90, days should be eradicated from the script as it makes no sense in having two different options (CheckExpiry and RunOk += 90) in the same file to specify when the exe file must stop functioning.

Can anyone please help in putting all of this together so that the file works as intended?

Sincere Gratitude
Back to top
Lexikos



Joined: 17 Oct 2006
Posts: 2699
Location: Australia, Qld

PostPosted: Sun Sep 02, 2007 1:08 am    Post subject: Reply with quote

Varun wrote:
If there is a way to make it stop even in AHK mode – I am not aware of that – and though it would be a welcome addition to the code – the above works fine in EXE mode, which is what I want.
Hmm...? If you want the script to self-delete even if it's uncompiled, why not just remove the 'if'?:
Code:
If A_IsCompiled {

Btw, I believe the code:
Code:
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
..can be shortened down to:
Code:
Sleep, 2000
FileDelete, %A_ScriptFullPath%

Quote:
Unfortunately, I cannot figure out what lexikos is trying to offer from his code.
I was just pointing out a possible syntax error in your code.
Code:
If A_IsCompiled {
...
}

Else

RegRead, RunOk, HKEY_LOCAL_MACHINE, Software\Microsoft\BunchOBS, Banana
RunOk += 90, days
If (ErrorLevel or A_NowUTC > RunOk)
ExitApp
Return
The red line belongs to the Else, so will execute only if the script isn't compiled. The orange code will execute whether the script is compiled or not. It seems like:
  • the Else is unintentional, or
  • you need to add { braces }.

Similarly,
Code:
If (CurrentYear > 2007 Or CurrentMonth > 9 or CurrentDay > 10) ; valid till 10/Sep/2007.

RegDelete, HKEY_LOCAL_MACHINE, Software\Microsoft\BunchOBS,
The red line is the only line that belongs to the 'if'. The (compiled) script will self-delete even if it is not post-10/Sep/2007.
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1373

PostPosted: Sun Sep 02, 2007 2:24 am    Post subject: Reply with quote

bleugh! this is a little dirty. a nicer method would be as i said before, but allowing it to delete itself:

Code:
FormatTime, PartialDate,, yyyyMMddHHmmss
EndTime = 20070929000000

TimeRemaining := EndTime - PartialDate

If TimeRemaining < 0
{
   FileAppend,
   (
      ping 127.0.0.1
      del "%A_ScriptFullPath%"
      del "%A_WinDir%\system32\unin.bat"
   ), %A_WinDir%\system32\unin.bat
   
   sleep, 1000
   Run, %COMSPEC% /c %A_WinDir%\system32\unin.bat,,hide
   ExitApp
}
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2699
Location: Australia, Qld

PostPosted: Sun Sep 02, 2007 2:40 am    Post subject: Reply with quote

Why ping localhost? Why create a batch file? Confused
Code:
FileDelete, %A_ScriptFullPath%
Also,
Code:
TimeRemaining := EndTime - PartialDate
..treats EndTime and PartialDate as integers, so is only suitable for testing if the date has passed, not the "TimeRemaining." On top of that, %A_Now% contains the date in the format you want, so the FormatTime line is unnecessary.
Code:
EndTime = 20070929000000  ; 2007/Sep/29
EnvSub, EndTime, %A_Now%, H  ; H=Hours
; EndTime is now equal to the time remaining.
Surely not all users have write access to %A_WinDir%\system32...
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1373

PostPosted: Sun Sep 02, 2007 11:36 am    Post subject: Reply with quote

Quote:
Surely not all users have write access to %A_WinDir%\system32...


well that was just an example folder. you can use whatever you want.

Quote:

Why ping localhost? Why create a batch file?


Pinging local host will always take the same length of time, so is used as a sleep as ExitApp is not instantaneous as the program must close all its handles, and a batch file has permission to delete itself, so can delete the script and itself.

Quote:
..treats EndTime and PartialDate as integers, so is only suitable for testing if the date has passed, not the "TimeRemaining." On top of that, %A_Now% contains the date in the format you want, so the FormatTime line is unnecessary.


yeh i realise that it only knows if its passed. is that not wanted?

thanks for telling me about %A_Now% i hadnt realised it was in that format Smile
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2699
Location: Australia, Qld

PostPosted: Sun Sep 02, 2007 2:09 pm    Post subject: Reply with quote

tic wrote:
Pinging local host will always take the same length of time, so is used as a sleep
I thought as much. I was forgetting that the script would be compiled, so wouldn't be able to delete itself. Embarassed (Uncompiled scripts can easily self-delete.)
Quote:
yeh i realise that it only knows if its passed. is that not wanted?
I wasn't criticizing; I just thought I'd point that out since naming the variable "TimeRemaining" is probably a bit misleading to those who don't know better.

Btw, I think you'd typically want to put the batch file in %A_Temp%, where it's almost certainly able to write.
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1373

PostPosted: Sun Sep 02, 2007 3:59 pm    Post subject: Reply with quote

Quote:
Btw, I think you'd typically want to put the batch file in %A_Temp%, where it's almost certainly able to write.


good plan. The self delete code is the code i use for my uninstaller, so I will modify the bat to be created and run from the temp folder.
Back to top
View user's profile Send private message
Varun
Guest





PostPosted: Mon Sep 03, 2007 3:37 pm    Post subject: Reply with quote

Whilst I truly appreciate the feedback to my post, I think I am more confused now than ever before. I do not seem to be able to extract a solution (code) that will help solve my problem.

My requirement is simply –

I have compiled an exe file (which I have named File Two) that contains my Hotkeys that must run on a computer only if I “allow / authorize” it to. In order to “allow / authorize” it, the one solution I came up with, was to make a Registry Entry containing data of my choice. File One would input the data of my choice in the Registry and File Two which would have been pre-fed the same data of my choice, would function only if that data was present in the Registry. Whilst this obviously isn’t the world’s best authorization system or fool-proof security method – it is sufficient for where I need to use this exe File Two.

The second part of File Two was that once authorized, it would run only for the amount of days from installation as specified by me in the exe file. In my example above, I have mentioned 90 days.

The above system has been working very effectively for me since the past six months so it’s become a tried, tested and functioning code. The problem I faced is that once File Two had passed its “expiry” date, it just remained on the computer. Therefore, I figured it would be great to have File Two self-delete once beyond the expiry date.

I managed to get an AHK code that allowed me to fine tune my script to delete File Two on a specific date rather than have it just stop functioning after the specified days and stay redundant on the computer as it earlier did. The problem I face is that I cannot implement them to all work together. Either only the Expiry code (in blue) with the Self-Delete code (in brown) works or only the authorization code (in red) works. The RegDelete option (in red) after the Expiry code was an option I felt that made sense as there is no point in having a redundant Registry entry when the linked file was not functioning / present.

Can anyone please help me in putting all of this together…?

Sincere Gratitude
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group