Ticket #1680: WhatIE.au3

File WhatIE.au3, 4.7 KB (added by willichan, 12 years ago)
Line 
1#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
2#AutoIt3Wrapper_icon=WhatIE.ico
3#AutoIt3Wrapper_outfile=WhatIE.exe
4#AutoIt3Wrapper_Compression=4
5#AutoIt3Wrapper_Res_Fileversion=0.0.0.40
6#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
7#AutoIt3Wrapper_Res_Language=1033
8#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
9
10Global Const $debug = False
11Opt("MustDeclareVars", 1)
12Opt("TrayAutoPause", 0)
13Opt("TrayMenuMode", 0)
14Opt("TrayIconHide", 0)
15
16#include <OneInstance.au3>
17
18_ConfigInitialize()
19
20#include <GuiToolBar.au3>
21Global $MaxWaitTime = 5 * 60 * 1000
22Global $SleepTime = 500
23Global $databasefile = "\\serverx\sharey\WhatIE.db"
24_WaitForHibun()
25
26#include <SQLite.au3>
27#include <SQLite.dll.au3>
28
29_WaitForDatabase()
30
31Global $sSQliteDll = _SQLite_Startup()
32Global $sSQLiteDB = _SQLite_Open($databasefile)
33
34Global $iepath, $iever, $splitver, $major, $minor, $revision, $build, $sql, $err, $query
35Global $attempt = 0
36
37$iepath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IE Setup\Setup", "Path") & "\iexplore.exe"
38$iepath = StringReplace($iepath, "%programfiles%", EnvGet("programfiles"))
39$iever = FileGetVersion(FileGetLongName($iepath))
40$splitver = StringSplit($iever, ".")
41$major = "0"
42$minor = "0"
43$revision = "0"
44$build = "0"
45If $splitver[0] > 0 Then
46        $major = $splitver[1]
47        If $splitver[0] > 1 Then
48                $minor = $splitver[2]
49                If $splitver[0] > 2 Then
50                        $revision = $splitver[3]
51                        If $splitver[0] > 3 Then
52                                $build = $splitver[4]
53                        EndIf
54                EndIf
55        EndIf
56EndIf
57Do
58        $attempt += 1
59        If _DataExists(@ComputerName) Then
60                $query = "UPDATE OR REPLACE iever SET "
61                $query &= "path = '" & $iepath & "', "
62                $query &= "major = '" & $major & "', "
63                $query &= "minor = '" & $minor & "', "
64                $query &= "revision = '" & $revision & "', "
65                $query &= "build = '" & $build & "', "
66                $query &= "WHERE (hostname='" & StringLower(@ComputerName) & "');"
67        Else
68                $query = "INSERT OR REPLACE INTO iever VALUES ("
69                $query &= "'" & StringLower(@ComputerName) & "', "
70                $query &= "'" & $iepath & "', "
71                $query &= "'" & $major & "', "
72                $query &= "'" & $minor & "', "
73                $query &= "'" & $revision & "', "
74                $query &= "'" & $build & "');"
75        EndIf
76        $sql = _SQLite_Exec($sSQLiteDB, $query)
77        $err = @error
78Until (Not $err) Or ($attempt = 3)
79If $err Then MsgBox(48, @ScriptName, "Error writing to database:  " & $err & "[" & $sql & "]" & @CRLF & "Please report these numbers to the Help Desk", 5)
80Exit
81
82Func _DataExists($host)
83        Local $h = StringLower($host)
84        Local $res = _SQLite_Exec($sSQLiteDB, "SELECT * FROM iever WHERE hostname=" & $h)
85        If $res = $SQLITE_OK Then
86                Return True
87        Else
88                Return False
89        EndIf
90EndFunc   ;==>_DataExists
91
92Func _WaitForHibun()
93        Local $iSystray_IconText
94        Local $doneloop = False
95        Local $waittime = 0
96        Local $HibunPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\HITACHI\HIBUN-AE\0801\PathName", "Path00")
97        If Not StringRight($HibunPath, 1) = "\" Then $HibunPath &= "\"
98        Do
99                Sleep($SleepTime)
100                $waittime += $SleepTime
101                If $waittime > $MaxWaitTime Then $doneloop = True
102                $iSystray_IconText = Get_Systray_IconText("HIBUN AE Server")
103                If StringInStr($iSystray_IconText, "- Connected") > 0 Then $doneloop = True
104        Until $doneloop
105EndFunc   ;==>_WaitForHibun
106
107Func _WaitForDatabase()
108        Local $doneloop = False
109        Local $waittime = 0
110        Do
111                Sleep($SleepTime)
112                $waittime += $SleepTime
113                If $waittime > $MaxWaitTime Then $doneloop = True
114                If FileExists($databasefile) Then $doneloop = True
115        Until $doneloop
116        If Not FileExists($databasefile) Then
117                MsgBox(48, "Prescript", "Unable to locate database" & @CRLF & "Please notify the Help Desk",5)
118        EndIf
119EndFunc   ;==>_WaitForDatabase
120
121Func Get_Systray_IconText($sToolTipTitle)
122        ; Find systray handle
123        Local $hSystray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
124        If @error Then
125                Return ""
126        EndIf
127        ; Get systray item count
128        Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSystray_Handle)
129        If $iSystray_ButCount = 0 Then
130                Return ""
131        EndIf
132        ; Look for wanted tooltip
133        Local $iSystray_ButtonNumber
134        For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
135                Local $sText = _GUICtrlToolbar_GetButtonText($hSystray_Handle, $iSystray_ButtonNumber)
136                If StringInStr($sText, $sToolTipTitle) = 1 Then Return $sText
137        Next
138        Return SetError(1, 0, "")
139EndFunc   ;==>Get_Systray_IconText
140
141Func _ConfigInitialize()
142        If @OSVersion = "WIN_2003" Then Exit
143        OnAutoItExitRegister("_ConfigDestroy")
144
145        Global $MyName = StringLeft(@ScriptFullPath, StringInStr(@ScriptFullPath, ".", 0, -1) - 1)
146        $MyName = StringRight($MyName, StringLen($MyName) - StringInStr($MyName, "\", 0, -1))
147EndFunc   ;==>_ConfigInitialize
148
149Func _ConfigDestroy()
150        _SQLite_Close()
151        _SQLite_Shutdown()
152EndFunc   ;==>_ConfigDestroy