Hi @all
Ich habe vor kurzem mal mit dem autostart rumgetan und habe mir ein par functionen gemacht
Die Udf :
Spoiler anzeigen
#include-once
[/autoit] [autoit][/autoit] [autoit]; #UDFFILE# ====================================================================================================================
; Name...........: AutoRun Udf
; Description ...: This is an Udf for the Autorun with AutoIt
; Beschreibung ..: Dies ist eine Udf für den AutoStart in AutoIt
; Author(s) .....: Simon Buchner (http://www.autoit.de | simon )
; Remarks .......: The functions haven't Command's to know all about it but some Nots up the Function
; Idea(s) .......: The Idea of my first Function was from FireTiger (http://www.firetiger.de)
; Linenumber ....: 424 Lines
; Functions .....: This Udf contains seven Functions for the AutoRun
; ===============================================================================================================================
; #CURRENT# ===================================================================
; _AutoRun_SetProgramm
; _AutoRun_GetProgramms
; _AutoRun_DelProgramm
; _AutoRun_Error
; _AutoRun_GetRegProgramms
; _AutoRun_GetAllProgramms
; _AutoRun_SearchProgramm
; #End #CURRENT# ==============================================================
; #FUNCTION# ===================================================================
; Name .............: _AutoRun_SetProgramm
; Description ......: Sets a Programm to the Autostart
; Beschreibung .....: Setzt ein Programm in den Autostart
; Function Version .: V1.1
; Syntax ...........: _AutoRun_SetProgramm($aPogramm)
; Parameter(s): ....: $aProgramm = Programm to Set into the Autostart
; Return Value .....: error - (-1)
; - (-2)
; Success - (+0)
; Author(s) ........: Simon Buchner
; ==============================================================================
Func _AutoRun_SetProgramm($aProgramm)
Local $iProgramm , $name , $iLength , $iName , $iSplit , $aName
If FileExists(StringReplace($aProgramm,"/","\")) Then
$iProgramm = StringReplace($aProgramm,"/","\")
$name = STringSplit($iProgramm,".")
$iLength = StringLen($name[$name[0]])
$iName = StringLeft($iProgramm,StringLen($iProgramm) - $iLength -1)
$iSplit = StringSplit($iName,"\")
$aName = $iSplit[$iSplit[0]]
FileCreateShortcut($aProgramm,@DesktopDir & "\"& $aName & ".lnk")
FileMove(@DesktopDir & "\"&$aName & ".lnk","C:\Users\" & @UserName & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\")
If @error Then
return -1
_AutoRun_Error("_AutoRun_SetProgramm","Error To move the .lnk Datei into the AutoRun")
else
return 1
Endif
else
return -2
_AutoRun_Error("_AutoRun_SetProgramm","The Proramm couldn't be founded")
Endif
EndFunc
; #FUNCTION# ===================================================================
; Name .............: _AutoRun_DelProgramm
; Description ......: Delets a Programm of the Autorun
; Beschreibung .....: Löscht ein Programm aus dem Autostart
; Function Version .: V1.1
; Syntax ...........: _AutoRun_DelProgramm($aPogramm)
; Parameter(s): ....: $aProgramm = Programm to Delete from the Autostart
; Return Value .....: error - (-1)
; - (-2)
; - (-3)
; Success - (+0)
; Author(s) ........: Simon Buchner
; ==============================================================================
Func _AutoRun_DelProgramm($aProgramm)
Local $iProgramm , $name , $iLength , $iName , $iSplit , $aName
$iProgramm = StringReplace($aProgramm,"/","\")
$name = STringSplit($iProgramm,".")
$iLength = StringLen($name[$name[0]])
$iName = StringLeft($iProgramm,StringLen($iProgramm) - $iLength -1)
$iSplit = StringSplit($iName,"\")
$aName = $iSplit[$iSplit[0]]
If Not @error Then
If FileExists("C:\Users\" & @UserName &"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\" & $aName & ".lnk") Then
FileDelete("C:\Users\" & @UserName & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\" & $aName & ".lnk")
If Not @error Then
return 0
else
return -1
_AutoRun_Error("_AutoRun_DelProgramm","Error To Delete the .lnk Datei")
Endif
else
return -2
_AutoRun_Error("_AutoRun_DelProgramm","Error The Programm doesn't be in the AutoRun")
Endif
else
return -3
_AutoRun_Error("_AutoRun_DelProgramm","Error in getting the Programm")
Endif
EndFunc
; #FUNCTION# ===================================================================
; Name .............: _AutoRun_GetProgramms
; Description ......: Views all Programms in the Autorun
; Beschreibung .....: Zeigt alle Programme aus dem Autostart
; Function Version .: V1.3
; Syntax ...........: _AutoRun_GetProgramms($iFlag)
; Parameter(s): ....: $iFlag = Flag for Array
; | 0 = All Files in The AutoRun Folder
; | 1 = Only .lnk Files of the Folder
; $iFormat = Format of the return
; | 0 = Normal, with extension
; | 1 = Without Extension
; Return Value .....: $array = Returns an Array with this parts:
; | $array[0] = Number of AutoRun Programms
; | $array[n] = AutoRun Programm Name
; error - (-1)
; - (-2)
; - (-3)
; Author(s) ........: Simon Buchner
; ==============================================================================
Func _AutoRun_GetProgramms($iFlag = 0,$iFormat = 0)
dim $array[1]
Local $list , $i,$a = 0 , $split , $Length
dim $list[1]
$file = FileFindFirstFile("C:\Users\" & @UserName & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\" & "*.*")
If @error Then
return -3
_AutoRun_Error("_AutoRun_GetProgramms","Error to Finde the Folder of the Autorun")
Endif
While 1
$a += 1
$next = FileFindNextFile($file)
If @error Then
ExitLoop
else
If $iFlag = 0 Then
$split = StringSplit($next,".")
If $iFormat = 1 Then
If $split[0] > 1 Then
$Length = StringLen($split[$split[0]])
$next = StringTrimRight($next,$Length + 1)
Endif
Endif
Redim $list[$a + 1]
$list[0] = $a
$list[$a] = $next
elseif $iFlag = 1 Then
if $iFormat = 1 Then
If StringInStr($next,".lnk") Then
$next = StringReplace($next,".lnk","")
Redim $list[$a + 1]
$list[0] = $a
$list[$a] = $next
else
$a -= 1
Endif
elseif $iFormat = 0 Then
Redim $list[$a + 1]
$list[0] = $a
$list[$a] = $next
Endif
Endif
Endif
WEnd
FileClose($file)
If @error Then
return -2
_AutoRun_Error("_AutoRun_GetProgramms","Error to search for the Files")
else
For $i = 1 to $list[0]
ReDim $array[$i + 1]
$array[0] = $i
$array[$i] = $list[$i]
Next
If @error Then
return -1
_AutoRun_Error("_AutoRun_GetProgramms","Error to Finde the Files of The Autostart Folder")
else
return $array
Endif
Endif
EndFUnc
; #INTERNAL_USE_ONLY# ==========================================================
; Name .............: _AutoRun_Error
; Description ......: AutoRun Error Func
; Beschreibung .....: Error Function von AutoRun
; Function Version .: V1.0
; Syntax ...........: _AutoRun_Error($iFunc,$iError)
; Parameter(s): ....: $iFunc = Function with the Error
; $iError = Error of the Function
; Return Value .....: No
; Author(s) ........: Simon Buchner
; ==============================================================================
Func _AutoRun_Error($iFunc,$iError)
Local $iText = ""
$iText &= "- ==================================================================================" & @Crlf
$iText &= "+ AutoRun Error with the Function: " & $iFunc & @Crlf
$iText &= "! Error: "& $iError & @Crlf
$iText &= "- ==================================================================================" & @Crlf
ConsoleWrite($iText)
EndfUnc
; #FUNCTION# ===================================================================
; Name .............: _AutoRun_GetRegProgramms
; Description ......: Searchs for AutoRun Programms by the RegEdit
; Beschreibung .....: Sucht AutoStart Programme über die Regedit
; Function Version .: V1.3
; Syntax ...........: _AutoRun_GetRegProgramms()
; Parameter(s): ....: No
; Return Value .....: $array = Returns an 2D Array with this parts
; |$array[0][0] = Number of AutoRun Programms
; |$array[n][0] = Programm Name
; |$array[n][n] = Programm Path
; error - (-1)
; Author(s) ........: Simon Buchner
; ==============================================================================
Func _AutoRun_GetRegProgramms()
Local $iReg_Key , $i = 1
Dim $array[1][1]
$array[0][0] = 0
$iReg_Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
While 1
$iReg_Read = RegEnumVal($iReg_Key,$i)
If @error Then
Exitloop
Endif
Redim $array[$i + 1][2]
$array[0][0] = $i
$array[$i][0] = $iReg_Read
$aReg_Read = RegRead($iReg_Key,$iReg_Read)
$array[$i][1] = $aReg_Read
$i+=1
WEnd
If $array[0][0] > 0 Then
return $array
else
return -1
_AutoRun_Error("_AutoRun_GetRegProgamms","Not Possible to search for the Regedit AutoRun Programms")
Endif
EndFUnc
; #FUNCTION# ===================================================================
; Name .............: _AutoRun_GetAllProgramms
; Description ......: Searchs for AutoRun Programms in RegEdit and the Folder
; Beschreibung .....: Sucht AutoStart Programme über die Regedit und den Ordner
; Function Version .: V1.2
; Syntax ...........: _AutoRun_GetAllProgramms($iFlag,$iFormat)
; Parameter(s): ....: $iFlag = Flag for Array
; | 0 = All Files in The AutoRun Folder
; | 1 = Only .lnk Files of the Folder
; $iFormat = Format of the return
; | 0 = Normal, with extension
; | 1 = Without Extension
; Return Value .....: $return = Returns an 1D Array with this parts
; |$array[0] = Number of AutoRun Programms
; |$array[n] = Programm Name
; error - (-1)
; - (-2)
; - (-3)
; - (-4)
; Author(s) ........: Simon Buchner
; ==============================================================================
Func _AutoRun_GetAllProgramms($iFlag = 0,$iFormat = 0)
Local $array2[1]
Local $array3[1]
$array = _AutoRun_GetRegProgramms()
If $array = -1 Then
return -1
_AutoRun_Error("_AutoRun_GetAllProgramms","Error with finding the Regedit Autorun Programms")
else
$array1 = _AutoRun_GetProgramms($iFlag,$iFormat)
If $array1 = -1 Or $array1 = -2 Or $array1 = -3 Then
return -2
_AutoRun_Error("_AutoRun_GetAllProgramms","Error with getting Folder Autorun Programms")
else
For $i = 1 To $array[0][0]
ReDim $array2[$i + 1]
$array2[0] = $i
$array2[$i] = $array[$i][0]
Next
For $a = 1 To $array1[0]
Redim $array3[$a + 2]
$array3[0] = $a
$array3[$a] = $array1[$a]
next
if @error Then
return -3
_AutoRun_Error("_AutoRun_GetAllProgramms","Error to create two arrays")
else
Dim $return[1]
Local $b = 0
For $c = 1 To $array2[0] + $array3[0]
If $c < ($array2[0] +1) Then
ReDim $return[$c + 1]
$return[0] = $c
$return[$c] = $array2[$c]
else
If $c > $array2[0] Then
$b += 1
If $b > $array3[0] Then
Exitloop
else
redim $return[$return[0] + 2]
$return[$c] = $array3[$b]
$return[0] = $i
Endif
Endif
Endif
Next
If @error Then
return -4
_AutoRun_Error("_AutoRun_GetAllProgramms","Error To Make form two arrays One Array")
else
If $iFlag <> 1 Then
$return[0] = $return[0] + 1
Endif
return $return
Endif
Endif
Endif
Endif
EndFUnc
; #FUNCTION# ===================================================================
; Name .............: _AutoRun_SearchProgramm
; Description ......: Searchs If a programm is in the Autorun
; Beschreibung .....: Sucht ob ein Programm im AutoStart ist
; Function Version .: V1.1
; Syntax ...........: _AutoRun_SearchProgramm($aPogramm)
; Parameter(s): ....: $aProgramm = Programm to search for
; Return Value .....: error - (-1)
; - (-2)
; Sucess:
; | 0 = The Programm couldn't be found
; | 1 = The Programm could be found so it is in the AutoRun
; Author(s) ........: Simon Buchner
; ==============================================================================
Func _AutoRun_SearchProgramm($aProgramm)
Dim $array[1]
Dim $array1[1]
$array = _AutoRun_GetAllProgramms()
If $array = -1 Or $array = -2 Or $array = -3 Or $array = -4 Then
return -1
_AutoRun_Error("_AutoRun_SearchProgramm","Error to Search for a Programm")
else
Local $search = 0
If StringInStr($aProgramm,"/") Then
$aPogramm = StringReplace($aProgramm,"/","\")
Endif
If StringInStr($aProgramm,"\") Then
Local $split = StringSplit($aProgramm,"\")
$aName = $split[$split[0]]
else
$aName = $aProgramm
Endif
For $i = 1 To $array[0]
If $aName = $array[$i] Then
$search = 1
ExitLoop
else
ContinueLoop
Endif
next
If @error Then
return -2
_AutoRun_Error("_AutoRun_SearchProgramm","Error to Compare the Array")
else
Return $search
Endif
Endif
EndFunc