Jump to content

Tray check, startup


Recommended Posts

Hello

I want to make a function that if make a trayitem that i could "check". and if it is checked it i want the script to start on evry startup until i uncheck it.

$checkitem = TrayCreateItem("Checked")

$exititem = TrayCreateItem("Exit")

TraySetState()

While 1

$msg = TrayGetMsg()

Select

Case $msg = 0

ContinueLoop

Case $msg = $checkitem

TrayItemSetState($checkeditem,$TRAY_CHECKED)

Case $msg = $exititem

ExitLoop

EndSelect

WEnd

Exit

i gues i have to use this line in some way??

RegWrite ("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "myscript000", "REG_SZ", @ScriptFullPath)

Link to comment
Share on other sites

This is how I handle that

Opt("TrayMenuMode", 1)

Global $StartUp = IniRead(@ScriptDir & "Settings.ini", "Settings", "StartUp", "off")

$checkitem = TrayCreateItem("Run @StartUp = " & $StartUp)
$exititem = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $checkitem
            StartUp()

        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

Exit

; Functions

Func StartUp()
    If $StartUp = "Off" Then
        $StartUp = "On"
        TrayItemSetText($checkitem, "StartUp = " & $StartUp)
        ; set the shortcut here
    Else
        $StartUp = "Off"
        TrayItemSetText($checkitem, "StartUp = " & $StartUp)
        ; remove the shortcut here
    EndIf
EndFunc   ;==>StartUp

Except I always use On-Event-Mode for the tray

8)

NEWHeader1.png

Link to comment
Share on other sites

You pretty much already had it.

$checkitem  = TrayCreateItem("Checked")
$exititem    = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $checkitem
            TrayItemSetState($checkeditem,$TRAY_CHECKED)
            RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "myscript000", "REG_SZ", @ScriptFullPath)
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

Exit

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

You pretty much already had it.

$checkitem  = TrayCreateItem("Checked")
$exititem    = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $checkitem
            TrayItemSetState($checkeditem,$TRAY_CHECKED)
            RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "myscript000", "REG_SZ", @ScriptFullPath)
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

Exit
... and to "Uncheck" ???

8)

EDIT:

Generally, I do not like people going into my registry and putting crap in there. With the code I gave you, I place a shortcut in the startup folder. There is no need to write to the registry.

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Oops! I didn't look through the whole thing. I went back and did it my own way.

#Include <Constants.au3>

Opt("traymenumode", 1)
Opt("trayoneventmode", 1)

$checkitem= TrayCreateItem("Checked", -1, -1, 1)
TrayItemSetOnEvent(-1, "editregistry")
$exititem= TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "end")
$checked = "false"
TraySetState()

While 1
    Sleep(100)
WEnd

Func editregistry()
    If $checked = "false" Then
        $checked = "true"
        TrayItemSetState($checkitem, $TRAY_UNCHECKED)
        RegDelete("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "myscript000")
    ElseIf $checked = "true" Then
        $checked = "false"
        TrayItemSetState($checkitem, $TRAY_CHECKED)
        RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "myscript000", "REG_SZ", @ScriptFullPath)
    EndIf
EndFunc

Func end()
    Exit
EndFunc

Though I do agree that shortcuts in the startup folder are better. I hate having to go into the registry to stop some stupid program from running on startup.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

You don't have to use a variable to check the state (look here, i also thought that we need to):

#include <Constants.au3>

Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1)

$CheckItem = TrayCreateItem("Checked")
TrayItemSetOnEvent(-1, "EditRegistry")
$ExitItem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "End")

TraySetState()

While 1
    Sleep(100)
WEnd

Func EditRegistry()
    If BitAND(TrayItemGetState($CheckItem), $TRAY_CHECKED) <> $TRAY_CHECKED Then
        TrayItemSetState($CheckItem, $TRAY_CHECKED)
        ;RegDelete("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "myscript000")
    Else
        TrayItemSetState($CheckItem, $TRAY_UNCHECKED)
        ;RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "myscript000", "REG_SZ", @ScriptFullPath)
    EndIf
EndFunc

Func End()
    Exit
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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...