Jump to content

Tray icon when startup.


 Share

Recommended Posts

Hello my friends.

I have problem with my script. When i excute my cript, i click tray icon, script work successfully( show gui ). But if i logoff my computer and then i logon, script run with startup, tray icon in tray, i click tray icon but script not work successfully(gui not show). Only command run "_RunDos("Net stop _Au3@Service")" , i can't understand why. Please give my your opinion. Thanks you so much.

This is my script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
#include <Constants.au3>
#include <Process.au3>
#include <Services.au3>
#include <ServicesConstants.au3>
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "SpecialEvent")
TraySetClick(8)
Global $objWMIService
Global $strComputer = "."
Const $OWN_PROCESS = 16 ;16 is own process
Const $INTERACTIVE = true ;True changes the $Own_Process to 272 is interact with desktop
Const $NORMAL_ERROR_CONTROL = 1
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Close Station", 193, 112, 192, 124);, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX))
$Group1 = GUICtrlCreateGroup(" Change time close station ", 8, 8, 177, 97)
$hour = GUICtrlCreateInput("", 56, 32, 33, 21)
$minute = GUICtrlCreateInput("", 104, 32, 33, 21)
$Label1 = GUICtrlCreateLabel(":", 94, 33, 8, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Time", 15, 35, 27, 17)
$apply= GUICtrlCreateButton("Apply", 56, 64, 81, 25) ; 6/42
GUICtrlCreateGroup("", -99, -99, 1, 1)
#EndRegion ### END Koda GUI section ###
$var4 = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName)
If Not $var4 <> "" Then
RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
EndIf
$var2 = RegRead("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@Service", "ImagePath")
If not $var2 <> "" Then
$SrvAny = @ScriptDir&"\srvany.exe"
$Script = @ScriptDir&"\servicengam.exe"
$objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$objService = $objWMIService.Get("Win32_BaseService")
$errReturn = $objService.Create("_Au3@Service" ,"_Au3@Service" , $SrvAny, $OWN_PROCESS, $NORMAL_ERROR_CONTROL, _
"Automatic", $INTERACTIVE, "LocalSystem", "" )
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@Service", "ImagePath", "REG_EXPAND_SZ", $SrvAny)
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@Service\Parameters", "AppDirectory", "REG_SZ", @WorkingDir)
RegWrite("HKLM\SYSTEM\CurrentControlSet\Services\_Au3@Service\Parameters", "Application", "REG_SZ", $Script)
Sleep(250)
EndIf


While 1

$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUISetState(@SW_HIDE)
TraySetState(1)
_RunDos("Net start _Au3@Service")
$statusservice = _Service_QueryStatus("_Au3@Service")
While $statusservice[1] <> 4
Sleep(5000)
$statusservice = _Service_QueryStatus("_Au3@Service")
WEnd
Case $apply
GUISetState(@SW_HIDE)
TraySetState(1)
$hx = GUICtrlRead($hour)
$mx = GUICtrlRead($minute)
Local $file_open = FileOpen("var.ini",2)
While $file_open= -1
Local $file_open = FileOpen("var.ini",0)
Sleep(5000)
WEnd
FileWrite("var.ini", $hx&$mx)
FileClose($file_open)
Sleep(250)
_RunDos("Net start _Au3@Service")
$statusservice = _Service_QueryStatus("_Au3@Service")
While $statusservice[1] <> 4
Sleep(5000)
$statusservice = _Service_QueryStatus("_Au3@Service")
WEnd
Sleep(250)
EndSwitch
WEnd
;ConsoleWrite("2")
;**************************************************************************************************
;** Fuctions **************************************************************************************
;**************************************************************************************************
Func MakePacket($d)
Local $p=""
While $d
$p&=Chr(Dec(StringLeft($d,2)))
$d=StringTrimLeft($d,2)
WEnd
Return $p
EndFunc
;**************************************************************************************************
Func UnsignedHexToDec($n)
$ones=StringRight($n,1)
$n=StringTrimRight($n,1)
Return dec($n)*16+dec($ones)
EndFunc
;**************************************************************************************************
Func SpecialEvent()
_RunDos("Net stop _Au3@Service")
Sleep(250)
Local $file_open = FileOpen("var.ini",0)
While $file_open= -1
Local $file_open = FileOpen("var.ini",0)
Sleep(2000)
WEnd
$tex = FileRead("var.ini", 4)
FileClose($file_open)
$hxr = StringLeft($tex, 2)
$mxr = StringRight($tex, 2)
GUICtrlSetData($hour,$hxr)
GUICtrlSetData($minute,$mxr)
GUISetState(@SW_SHOW)
Sleep(250)
EndFunc ;==>SpecialEvent
Edited by hvl
Link to comment
Share on other sites

Hi,

You need to debug your script (e.g: MsgBox function), I'm pretty sure that your script is blocked in the while (from the SpecialEvent function).

Br, FireFox.

Thanks for your help! when i check my script again, i detect my script not run with startup. All code not work. Any body has another opinion .

Edited by hvl
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...