Jump to content

Ho to set a password to exit my script ?


Recommended Posts

TrayCreateItem ( text [, menuID [, menuentry [, menuradioitem]]] )

Link to comment
Share on other sites

TrayCreateItem ( text [, menuID [, menuentry [, menuradioitem]]] )

??

If I'm right you actually want to create anIcon in a GUI...

in which case, use Bs_Icon style on a button (check out helpfile for more)

on click bring up an input box, which if the correct passwrd is enetered, end script

eg:

GUICreate ("GUI", 100, 100)
$Button = GuiCtrlCreateButton ("Exit", 50, 50)
GUISetState ()

While 1
Select
   Case GuiGetMsg() = $Button
      $PassBox = InputBox ("ExitScript", "Please enter the password to exit the sscript.", "", "*M")
      If $PassBox = "Password" Then
         Exit
      Else
         MsgBox (48, "Error", "Incorrect password has been entered")
      EndIf
   Case Else
     ;;;
EndSelect
wend
Edited by mdiesel
Link to comment
Share on other sites

Thanks but i won't the button to exit on a window but in the option icon place ( TrayCreateItem("Close with password") ):D

?? Not sure what you mean here, I presume you want the same to happen but for the tray Icon...

Just use exactly the same code, and replace The case $Button with $Traymenuitem or whatever you've made the handle.

Link to comment
Share on other sites

not hard:

Opt("TrayMenuMode",1)

GUICreate ("GUI", 100, 100)
$Button = GuiCtrlCreateButton ("Exit", 50, 50)
GUISetState ()
$close  = TrayCreateItem("Close", -1)

While 1
Select
   Case TrayGetMsg() = $Close
      $PassBox = InputBox ("ExitScript", "Please enter the password to exit the sscript.", "", "*M")
      If $PassBox = "Password" Then
         Exit
      Else
         MsgBox (48, "Error", "Incorrect password has been entered")
      EndIf
   Case GuiGetMsg() = $Button
      $PassBox = InputBox ("ExitScript", "Please enter the password to exit the sscript.", "", "*M")
      If $PassBox = "Password" Then
         Exit
      Else
         MsgBox (48, "Error", "Incorrect password has been entered")
      EndIf
   Case Else
    ;;;
EndSelect
wend
Link to comment
Share on other sites

Good, now I use :

CODE
Opt("TrayMenuMode",1)

GUISetState ()

$close = TrayCreateItem("Close", -1)

While 1

Select

Case TrayGetMsg() = $Close

$PassBox = InputBox ("Quitter le filtrage", "Entrez votre mot de passe parental", "", "*M")

If $PassBox = "Password" Then

Exit

Else

MsgBox (48, "Erreur", "Mot de passe incorrect")

EndIf

Case Else

;;;

EndSelect

wend

But, is it possible to use this in a function and not a while ? cause my script stay in the while and doesn't continue.

Link to comment
Share on other sites

yes, just put in the loop CloseScript ()

and add:

Func CloseScript ()
Local $PassBox
$PassBox = InputBox ("Quitter le filtrage", "Entrez votre mot de passe parental", "", "*M")
If $PassBox = "Password" Then
Exit
Else
MsgBox (48, "Erreur", "Mot de passe incorrect")
EndIf
EndFunc

to give you:

Opt("TrayMenuMode",1)

GUISetState ()
$close = TrayCreateItem("Close", -1)

While 1
Select
Case TrayGetMsg() = $Close
CloseScript ()

Case Else
;;;
EndSelect
wend

Func CloseScript ()
Local $PassBox
$PassBox = InputBox ("Quitter le filtrage", "Entrez votre mot de passe parental", "", "*M")
If $PassBox = "Password" Then
Exit
Else
MsgBox (48, "Erreur", "Mot de passe incorrect")
EndIf
EndFunc

you are going to have to include a loop somewhere though, and just build it into the loop.

Link to comment
Share on other sites

I know but I never want exit this loop when my script is started, possible ?

maybe use a script who control another script...

kk...so you need

a) to constantly check for something in an infinite loop

B ) to have a GUI

c) to close GUI with tray icon.

look for alternatives - put it in the same loop, but just hide the GUI? or maybe GUIDelete?

lol cant use B and ) :D

Edited by mdiesel
Link to comment
Share on other sites

Yes, my checking informations code is the loop...

CODE
Opt("TrayMenuMode",1)

Func CloseScript ()

Local $PassBox

$PassBox = InputBox ("Quitter le filtrage", "Entrez votre mot de passe parental", "", "*M")

If $PassBox = "Password" Then

Exit

Else

MsgBox (48, "Erreur", "Mot de passe incorrect")

EndIf

EndFunc

GUISetState ()

$close = TrayCreateItem("Close", -1)

While 1

Select

Case TrayGetMsg() = $Close

CloseScript ()

Case Else

;My checking informations loop

while 1

;checking code with never Exitloop

Wend

EndSelect

wend

Link to comment
Share on other sites

no, becouse autoit must finish a line and then move onto the next.

Opt("TrayMenuMode",1)

GUICreate ("GUI", 100, 100)
$Button = GuiCtrlCreateButton ("Exit", 50, 50)

GUISetState ()
$close = TrayCreateItem("Close", -1)

;My checking informations loop
while 1
;checking code with never Exitloop
If TrayGetMsg () = $close Then
$PassBox = InputBox ("Quitter le filtrage", "Entrez votre mot de passe parental", "", "*M")
If $PassBox = "Password" Then
GUISetState (@SW_HIDE)
Else
MsgBox (48, "Erreur", "Mot de passe incorrect")
EndIf
EndIf
Wend

notice how the icon is still there after you click close, and autoit.exe is still in the process list? the script is still running but the GUI Is gone!

magic!

now you can also make it show again the same way

Opt("TrayMenuMode",1)

GUICreate ("GUI", 100, 100)
$Button = GuiCtrlCreateButton ("Exit", 50, 50)

GUISetState ()
$close = TrayCreateItem("Close", -1)
$open = TrayCreateItem("Open", -1)

;My checking informations loop
while 1
  ;checking code with never Exitloop
   If TrayGetMsg () = $close Or GUIGETMSG () = $Button Then
      $PassBox = InputBox ("Quitter le filtrage", "Entrez votre mot de passe parental", "", "*M")
      If $PassBox = "Password" Then
         GUISetState (@SW_HIDE)
      Else
         MsgBox (48, "Erreur", "Mot de passe incorrect")
      EndIf
   ElseIf TrayGetMsg () = $Open Then
      GUISetState (@SW_SHOW)
   EndIf
Wend
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...