(z.B. erst nachdem bei HomeOffice-Arbeiten der VPN-Tunnel verbunden wurde).
Programme die bereits gestartet wurden und Netzlaufwerke, die bereits verbunden sind,
sollen natürlich nicht noch einmal gestartet bzw. verbunden werden.
Dazu soll das Unterprogramm "ActStatus" jede Sekunde das UNTERE ListView (vLV_Drives) aktualisieren.
Über Tooltip lass' ich mir versuchsweise die Variablen anzeigen und ich sehe,
dass der Status eines Netzlaufwerks auf "invalid" springt, wenn es mal verbunden war,
und bei laufendem Programm mit Hilfe des Dateimanagers getrennt wird.
Jedoch die LV-Anzeige bleibt auf "Ready" stehen.
Fragen: warum ist das so und wie muss das Unterpgrogramm gestaltet sein, damit der LV aktualisiert wird?
Code: Select all
If !(A_iscompiled)
Hotkey, ESC, Beenden, on
#Include core.ahk ; http://ahkscript.org/boards/viewtopic.php?f=6&t=1108&p=7986&hilit=+encrypt#p7986
aZelle := []
aNetWorkDrives := []
Changed := 0
ButtonEnd := 0
StringLower, UserName, A_UserName
StartUpIniFile := A_ScriptDir . "\StartUp.ini" ; ini-File ist im Verzeichnis, in dem auch das Script gespeichert ist
NetworkDrives := A_ScriptDir . "\NetworkDrives.ini" ; ini-File ist im Verzeichnis, in dem auch das Script gespeichert ist
SetTimer, ActStatus, 1000
StringSplit, OS, A_OSVersion,.
if (OS1=10)
officeVer:="office16"
else
officeVer:="office15"
IfNotExist, %StartUpIniFile% ; wenn Ini-File noch nicht existiert, eines erstellen mit einem Standard-Eintrag
{
IniText=
(LTrim
C:\Program Files (x86)\Microsoft Office\%OfficeVer%\lync.exe
C:\Program Files (x86)\Avaya\Avaya one-X Communicator\onexcui.exe
C:\Users\%A_UserName%\AppData\Roaming\PresenceApp\PresenceApp.exe
)
FileAppend, %IniText%, %StartUpIniFile%
}
IfNotExist, %NetworkDrives% ; wenn Ini-File noch nicht existiert, eines erstellen mit einem Standard-Eintrag
{
IniText=
(LTrim
U:;\\NU01FS01\%A_UserName%$;;;YES
)
FileAppend, %IniText%, %NetworkDrives%
}
for Prozess in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
ProcessList .= Prozess.CommandLine . "`n"
gosub, MakeStartUpList
MakeStartUpList:
; lese Datei aus
FileRead, StartUpIniFileText, %StartUpIniFile%
StringReplace, StartUpIniFileText, StartUpIniFileText, `r`n,|, All
aFileText := StrSplit(StartUpIniFileText,"|")
Rows := aFileText.MaxIndex()
; lese Datei NetworkDrives aus
FileRead, NetworkDrivesText, %NetworkDrives%
StringReplace, NetworkDrivesText, NetworkDrivesText, `r`n,|, All
aDrivesText := StrSplit(NetworkDrivesText,"|")
DrivesRows := aDrivesText.MaxIndex() + 1
Gui, StartUp:new
Gui, StartUp:Add, Text, x10, Starte diese Programme ...
Gui, StartUp:Add, ListView, x10 w600 r%Rows% vLV_StartUps, Nr|Programm|Status
loop, % aFileText.MaxIndex()
{
if InStr(ProcessList, aFileText[A_Index])
LV_Add("", A_Index, aFileText[A_Index], "gestartet")
else
LV_Add("", A_Index, aFileText[A_Index], "")
LV_ModifyCol(A_Index, "AutoHdr")
}
Gui, StartUp:Add, Button, x+10 yp+24 w100 h30 gEdit, Bearbeiten
Gui, StartUp:Add, Text,,
Gui, StartUp:Add, Text, x10, Verbinde diese Laufwerke ...
Gui, StartUp:Add, ListView, x10 w600 r%DrivesRows% vLV_Drives, LW:|Share|[User]|[Password]|[erneut verbinden]|Status
loop, % aDrivesText.MaxIndex()
{
DriveGet, Status, Status, % aZelle[A_Index, 1]
RadioPers := Zelle[4]
aZelle[A_Index] := StrSplit(aDrivesText[A_index], ";")
LV_Add("", aZelle[A_Index, 1], aZelle[A_Index, 2], aZelle[A_Index, 3], aZelle[A_Index, 4], aZelle[A_Index, 5], Status)
LV_ModifyCol(A_Index, "AutoHdr")
}
Gui, StartUp:Add, Button, x+10 yp+24 w100 h30 gEditDrives, Bearbeiten
GUI, StartUp:Add, text, x+10 w200
Gui, StartUp:Add, Button, x10 w100 h30 gStart vStart Default, Run
Gui, StartUp:Add, Button, x+10 w100 h30 gExit, Beenden
GUI, StartUp:Add, text, x+10 w200 vBeendenText,
Gui, StartUp:Show, w740 y30, StartUp
return
Start:
gosub, ActStatus
; Modifiziere LV_StartUps
Gui, StartUp:ListView, LV_StartUps
loop,read,%StartUpIniFile%
{
If A_LoopReadLine!
break
LV_GetText(Status, A_index, 3)
if (Status <> "gestartet")
{
Run, %A_LoopReadLine%
LV_Modify(A_index,,,A_LoopReadLine,"gestartet")
LV_ModifyCol()
}
}
; Modifiziere LV_StartUps
Gui, StartUp:ListView, LV_Drives
loop, % aDrivesText.MaxIndex()
{
LV_GetText(Status, A_index, 6)
if !(Status="Ready")
{
Drive:=aZelle[A_Index, 1]
Share:=aZelle[A_Index, 2]
UserN:=aZelle[A_Index, 3]
PassW:=decryptStr(aZelle[A_Index, 4], UserName)
Persi:=aZelle[A_Index, 5]
if (UserN)
RunWait, cmd /c net use %Drive% %Share% /USER:%UserN% %PassW% /persistent:%Persi%
else
RunWait, cmd /c net use %Drive% %Share% /persistent:%Persi%
DriveGet, Status, Status, % aZelle[A_Index, 1]
if !(Status="ready")
MsgBox Could not connect %Drive%
else
LV_Modify(A_Index,,,,,,,"Ready")
}
}
return
ActStatus:
ToolTipText:=""
Gui StartUp: ListView, LV_Drives
loop, % aDrivesText.MaxIndex()
{
DriveGet, CurStatus, Status, % aZelle[A_Index, 1]
LV_GetText(LastStatus,A_Index,6)
LV_Modify(A_Index,,,,,,,CurStatus)
ToolTipText .= " | " . A_index . ": " . CurStatus
ToolTip, %ToolTipText%
}
return
Edit:
Gui, StartUp: destroy
RunWait, notepad.exe %StartUpIniFile%
gosub, MakeStartUpList
return
EditDrives:
CurDrive := 1
Gui, StartUp: destroy
FileRead, text, %NetworkDrives%
loop, parse, text, `n, `r
aNetWorkDrives[A_Index] := StrSplit(A_LoopField,";")
Gui, EditDrives: new
Gui, EditDrives: Add, Text, x10 w145, Laufwerks-Buchstabe
Gui, EditDrives: Add, Text, x+10 w145, ändern
Gui, EditDrives: Add, Edit, x10 w145 vEditDrives1 , % aNetWorkDrives[1,1]
gosub, CheckAvailDrives
Gui, EditDrives: Add, DropDownList, x+10 10 w145 r8 vEditDrives6 gChangeDrive, % DrivesPossible
Gui, EditDrives: Add, Text, x10 w300, \\Server\Share (optional:\\Server.de.bosch.com\Share)
Gui, EditDrives: Add, Edit, x10 w300 vEditDrives2, % aNetWorkDrives[1,2]
Gui, EditDrives: Add, Text, x10 w300, UserName [optional]
Gui, EditDrives: Add, Edit, x10 w300 vEditDrives3, % aNetWorkDrives[1,3]
Gui, EditDrives: Add, Text, x10 w300, Password [optional]
Gui, EditDrives: Add, Edit, x10 w300 vEditDrives4 Password, % aNetWorkDrives[1,4]
Gui, EditDrives: Add, Text, x10 w300, Persistent [optional]
gosub, CheckPersistence
Gui, EditDrives: Add, DropDownList, x10 w300 r3 vEditDrives5 Choose%ChoosenListBoxItem%, |YES|NO
Gui, EditDrives: Add, Button, w50 gBackward vBackward, <
Gui, EditDrives: Add, Text, x+10 w20 vEditDrivesText1, % CurDrive . "/" . aNetWorkDrives.MaxIndex()
Gui, EditDrives: Add, Button, x+10 w50 gForward vForward, >
Gui, EditDrives: Add, Button, x+10 w70 gAddDrive vAddDrive, +
Gui, EditDrives: Add, Button, x+10 w70 gSaveDrives vSaveDrivesButton, Save
GuiControl, EditDrives:, Focus, EditDrives1
GuiControl, Disable, SaveDrivesButton
Gui, EditDrives: show, w340, EditDrives
return
EditDrivesGuiClose:
EditDrivesGuiEscape:
Gui, EditDrives: Destroy
gosub, MakeStartUpList
return
CheckAvailDrives:
DriveGet, DrivesInUse, List
DrivesPossible := "DEFGHIJKLMNOPQRSTUVWXYZ"
loop, % StrLen(DrivesInUse)
{
if InStr(DrivesPossible, Substr(DrivesInUse, A_index, 1))
{
StringSplit, String, DrivesPossible, % Substr(DrivesInUse, A_index, 1)
DrivesPossible := String1 . String2
}
}
loop, % StrLen(DrivesPossible)
string .= SubStr(DrivesPossible, A_index, 1) . ":|"
StringTrimRight, DrivesPossible, string, 1
return
CheckPersistence:
if !(aNetWorkDrives[CurDrive,5])
ChoosenListBoxItem := 1
if (aNetWorkDrives[CurDrive,5]="YES")
ChoosenListBoxItem := 2
if (aNetWorkDrives[CurDrive,5]="NO")
ChoosenListBoxItem := 3
return
ChangeDrive:
Gui, EditDrives: submit, nohide
if (EditDrives6)
GuiControl,, EditDrives1, % EditDrives6
return
Forward:
; Prüfe, ob User etwas geändert hat
Gui, EditDrives: submit, nohide
loop, % aNetWorkDrives[1].MaxIndex()
if (EditDrives%A_index% <> aNetWorkDrives[CurDrive, A_Index])
{
aNetWorkDrives[CurDrive, A_Index] := EditDrives%A_index%
Changed:=1
GuiControl, Enable, SaveDrivesButton
}
CurDrive +=1
If (CurDrive > aNetWorkDrives.MaxIndex())
CurDrive := 1
GuiControl, EditDrives:, EditDrives1, % aNetWorkDrives[CurDrive, 1]
GuiControl, EditDrives:, EditDrives2, % aNetWorkDrives[CurDrive, 2]
GuiControl, EditDrives:, EditDrives3, % aNetWorkDrives[CurDrive, 3]
GuiControl, EditDrives:, EditDrives4, % aNetWorkDrives[CurDrive, 4]
gosub, CheckPersistence
GuiControl, EditDrives:, EditDrives5, % ChoosenListBoxItem
gosub, CheckAvailDrives
GuiControl, Choose, EditDrives6, % DrivesPossible
; Aktualisierung Datensatz+# (n/max)
GuiControl, EditDrives:, EditDrivesText1, % CurDrive . "/" . aNetWorkDrives.MaxIndex()
return
Backward:
; Prüfe, ob User etwas geändert hat
Gui, EditDrives: submit, nohide
loop, % aNetWorkDrives[1].MaxIndex()
if (EditDrives%A_index% <> aNetWorkDrives[CurDrive, A_Index])
{
aNetWorkDrives[CurDrive, A_Index] := EditDrives%A_index%
Changed:=1
GuiControl, Enable, SaveDrivesButton
}
CurDrive -=1
If (CurDrive = 0)
CurDrive := aNetWorkDrives.MaxIndex()
GuiControl, EditDrives:, EditDrives1, % aNetWorkDrives[CurDrive, 1]
GuiControl, EditDrives:, EditDrives2, % aNetWorkDrives[CurDrive, 2]
GuiControl, EditDrives:, EditDrives3, % aNetWorkDrives[CurDrive, 3]
GuiControl, EditDrives:, EditDrives4, % aNetWorkDrives[CurDrive, 4]
gosub, CheckPersistence
GuiControl, EditDrives:, EditDrives5, % ChoosenListBoxItem
gosub, CheckAvailDrives
GuiControl, Choose, EditDrives6, % DrivesPossible
; Aktualisierung Datensatz+# (n/max)
GuiControl, EditDrives:, EditDrivesText1, % CurDrive . "/" . aNetWorkDrives.MaxIndex()
return
AddDrive:
GuiControl, Enable, SaveDrivesButton
CurDrive := aNetWorkDrives.MaxIndex() + 1
GuiControl, EditDrives:, EditDrives1, % aNetWorkDrives[CurDrive, 1]
GuiControl, EditDrives:, EditDrives2, % aNetWorkDrives[CurDrive, 2]
GuiControl, EditDrives:, EditDrives3, % aNetWorkDrives[CurDrive, 3]
GuiControl, EditDrives:, EditDrives4, % aNetWorkDrives[CurDrive, 4]
gosub, CheckPersistence
GuiControl, EditDrives:, EditDrives5, % ChoosenListBoxItem
gosub, CheckAvailDrives
GuiControl, Choose, EditDrives6, % DrivesPossible
; Aktualisierung Datensatz+# (n/max)
GuiControl, EditDrives:, EditDrivesText1, % CurDrive . "/" . aNetWorkDrives.MaxIndex()
; Deaktiviere Vor-, Zurück-, und Add-Button
GuiControl, Disable, Forward
GuiControl, Disable, Backward
GuiControl, Disable, AddDrive
return
SaveDrives:
Gui, EditDrives: submit
loop, % aNetWorkDrives[1].MaxIndex()
{
aNetWorkDrives[CurDrive, A_Index] := EditDrives%A_Index%
if (EditDrives4)
{
string := encryptStr(EditDrives4, UserName)
StringTrimRight, string, string, 2
aNetWorkDrives[CurDrive, 4] := string
}
}
; Text aus Array aText[Zeile, Spalte] holen
text:=""
loop, % aNetWorkDrives.MaxIndex()
{
Zeile := A_Index
loop, % aNetWorkDrives[1].MaxIndex()
text .= aNetWorkDrives[Zeile, A_Index] . fEnde(aNetWorkDrives.MaxIndex(), aNetWorkDrives[1].MaxIndex(), Zeile, A_Index)
}
FileDelete, %NetworkDrives%
FileAppend, %Text%, %NetworkDrives%
gosub, MakeStartUpList
return
; Funktion zum Erstellen eines passenden Zeilenendes
fEnde(Zn,Sn,Z,S)
{
; Spaltenende noch nicht erreicht
if (S < Sn)
EndString := ";"
; Spaltenende erreicht, aber noch nicht in letzer Zeile
if (S=Sn AND Z<Zn)
EndString := "`n"
; absolut letzte Zelle erreicht
if (S=Sn AND Z=Zn)
EndString := ""
return EndString
}
StartUpGuiClose:
StartUpGuiEscape:
Beenden:
Exit:
gui,StartUp: Destroy
ExitApp
return