AutoHotkey Community

It is currently May 27th, 2012, 2:42 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Program stops executing?
PostPosted: November 22nd, 2009, 11:59 pm 
Offline

Joined: October 20th, 2009, 2:03 am
Posts: 10
Hi!
As a kind of joke to my little sister ( she's 8 ) I told her that I would keep her from installing anything on her computer until my dad entered a password. (Yes, she installs a bunch of random stuff.) I came up with this, but after I correctly enter the password, it seems to just go idle. No new setups are detected, etc.

Can anyone spot something wrong with this?

Code:
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetBatchLines, -1


SetTimer, EmptyMem, 60000

WatchListCount = 2

WatchList[1] = setup.exe
WatchList[2] = msiexec.exe

Loop ; Keep repeating the checks
{

  Loop %WatchListCount% ; Check for each in the list
  {
    Gui, Destroy
    CurrentItem := WatchList[%A_Index%]
    ; MsgBox, %CurrentItem%
    Process, Exist, %CurrentItem%
    ErrorLevelDump = %ErrorLevel%
    If ( ErrorLevel <> 0 ) ; ErrorLevel is not blank or zero
    {
      WinGetTitle, InstallTitle, ahk_pid %ErrorLevelDump%
      TextCenter := A_ScreenWidth-50
      Gui +AlwaysOnTop -SysMenu +Owner
      Menu, Tray, NoIcon
      Gui, Font, s20
      Gui, Add, Text, Center W%TextCenter%, Install Detected!`nA password is required to continue! ; 20 px margin on each side
      Gui, Add, Edit, Center W%TextCenter% +Password vPassword,
      Gui, Add, Button, Center W%TextCenter% gSubmit, Authorize
      Gui, Add, Text, Center W%TextCenter%, Installation Window Title: %InstallTitle%
      Gui, Show, W%A_ScreenWidth% H%A_ScreenHeight% NoActivate, Install Detected!
      return

      Submit:
      Gui, Submit
      Gui, Destroy
      If (Password = "password")
      {
      MsgBox, Password Correct! The installation may continue.
      }
      else
      {
      Gui +AlwaysOnTop -SysMenu +Owner
      Menu, Tray, NoIcon
      Gui, Font, s20 cRed
      Gui, Add, Text, Center W%TextCenter%, Password Incorrect! ; 20 px margin on each side
      Gui, Font, s20 cBlack
      Gui, Add, Text, Center W%TextCenter%, Install Detected!`nA password is required to continue! ; 20 px margin on each side
      Gui, Add, Edit, Center W%TextCenter% +Password vPassword,
      Gui, Add, Button, Center W%TextCenter% gSubmit, Authorize
      Gui, Add, Text, Center W%TextCenter%, Installation Window Title: %InstallTitle%
      Gui, Show, W%A_ScreenWidth% H%A_ScreenHeight% NoActivate, Install Detected!
      }
      return
    }
  }

}

EmptyMem:
EmptyMem()
SetTimer, EmptyMem, 60000
return


All criticism welcomed, I'm new to AutoHotKey.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2009, 12:15 am 
Code:
SetTimer, EmptyMem, 60000
Waiting a minute just to jump to a lable to wait for another minute ... ???


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2009, 3:55 am 
Offline

Joined: October 20th, 2009, 2:03 am
Posts: 10
Yes, except in that label is the EmptyMem() function, so it acts as a loop.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2009, 8:23 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
No []'s in arrays

Code:
WatchList[1] = setup.exe
WatchList[2] = msiexec.exe
CurrentItem := WatchList[%A_Index%]

   |
   v

WatchList1 = setup.exe
WatchList2 = msiexec.exe
CurrentItem := WatchList%A_Index%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2009, 2:38 pm 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
Dont define the whole gui within the loop. Define it just once at the beginning and show and hide it when necessary.
Also you should add an Abort-button.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2009, 5:05 pm 
Offline

Joined: October 25th, 2009, 6:10 pm
Posts: 17
Unless you really, really need to use AHK for this, you could use the Users control panel to create a passworded new account for installing (called Administr8or or some such) and make all of the other accounts Limited accounts. It's a safer way to run. There are some nuisances to running like this, but many other problems go away (like your sister's installs).

When actually installing, it's best to change your account from Limited to Administrator, do the install, and then change back.

Later, when you are satisfied with this strategy, you can use AHK to change user rights for when you want to do your own installs.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, rbrtryn and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group