Ordner Icon ändern

  • ändert das Icon eines beliebigen Ordners,
    auch im Netzwerk (was Windows so eigentlich nicht vorsieht)
    Wenn der Ordner nicht existiert, wird er erstellt.

    Beispiel zum Erstellen eines "versteckten" Ordners ist dabei :D

    Spoiler anzeigen
    [autoit]

    #include-once

    [/autoit] [autoit][/autoit] [autoit]

    ; #INDEX# =======================================================================================================================
    ; Title .........: _FolderSetIcon
    ; AutoIt Version.: 3.0.1++
    ; Language.......: English
    ; Description....: Function that changes a Folder Icon.
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _FolderSetIcon()
    ; Description ...: Set a new Icon for an given Folder
    ; Syntax.........: _FolderSetIcon($FolderPath, $IconDll[, $IconIndex])
    ; Parameters ....: $FolderPath - the complete Path to Folder (if the folder not exists it will be created)
    ; $IconDll - The Path to an dll-file containig the Icon (when not set, then the Standard Folder-Icon from Shell32.dll is set)
    ; $IconIndex - Index of the Icon in the dll-file, default is 1
    ; Return values .: Success: - 1
    ; Failure: - 0
    ; @error - 1
    ; @Extended - 1 = given .dll-/.ico-File don't exist
    ; - 2 = can't create Folder
    ; - 3 = can't set attributes of the Folder (+S)
    ; - 4 = can't write in ini-Section of Desktop.ini
    ; - 5 = can't set attributes of Desktop.ini (+SH)
    ; Author ........: Schnuffel at autoit.de
    ; Modified.......:
    ; Remarks .......: no remarks
    ; Related .......:
    ; Link ..........:
    ; Example .......: Yes
    ; Example 1......: _FolderSetIcon("C:\new", @SystemDir & "\Shell32.dll", 23)
    ; changes the icon for the given Folder, if the folder not exists it will be created
    ;
    ; Example 2......: _FolderSetIcon(@ScriptDir & "\" & CHR(160), @SystemDir & "\Shell32.dll", 50)
    ; creates an Folder with "NoName" and "NoIcon", Foldername = CHR(160)
    ;
    ; Example 3......: _FolderSetIcon(@ScriptDir&"\" & "My New Folder",@WindowsDir & "\SetupIcon.ico")
    ; changes the icon for the given Folder, if the folder not exists it will be created. The given Icon can be an .ico File
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    Func _FolderSetIcon($pFSI, $fFSI = "%SystemRoot%\system32\SHELL32.dll", $nIconFI = 0)
    Local $bFSIFC = False, $sFSIOD, $sFSIODHdl, $nFSIErr = 0, $pFSIDO = $pFSI & "\Desktop.ini"
    If $fFSI = "%SystemRoot%\system32\SHELL32.dll" Then $nIconFI = 4
    If StringRight($fFSI,3) = "ico" Then $nIconFI = 0
    Do
    If Not FileExists($fFSI) Then
    $nFSIErr = 1
    ExitLoop
    EndIf
    If Not FileExists($pFSI) Then
    DirCreate($pFSI)
    If @error Then
    $nFSIErr = 2
    ExitLoop
    EndIf
    $bFSIFC = True
    Else
    If FileExists($pFSIDO) Then $sFSIOD = FileRead($pFSIDO)
    EndIf
    FileSetAttrib($pFSI, "+S")
    If @error Then
    $nFSIErr = 3
    ExitLoop
    EndIf
    Switch @OSVersion
    Case "WIN_2008R2", "WIN_7", "WIN_2008", "WIN_VISTA"
    IniWriteSection($pFSIDO, ".ShellClassInfo", "LocalizedResourceName=" & $fFSI & "," & $nIconFI)
    If @error Then
    $nFSIErr = 4
    ExitLoop
    EndIf
    Case "WIN_2003", "WIN_XP", "WIN_XPe", "WIN_2000"
    IniWriteSection($pFSIDO, ".ShellClassInfo", "IconFile=" & $fFSI & @LF & "IconIndex=" & $nIconFI)
    If @error Then
    $nFSIErr = 4
    ExitLoop
    EndIf
    EndSwitch
    FileSetAttrib($pFSIDO, "+SH")
    If @error Then
    $nFSIErr = 5
    ExitLoop
    EndIf
    ExitLoop
    Until 1
    If $nFSIErr = 0 Then
    Return 1
    Else
    If $bFSIFC = True Then
    DirRemove($pFSI,1)
    ElseIf $sFSIOD <> "" Then
    $sFSIODHdl = FileOpen($pFSIDO,2)
    FileWrite($sFSIODHdl, $sFSIOD)
    FileClose($sFSIODHdl)
    EndIf
    Return SetError(1,$nFSIErr,0)
    EndIf
    EndFunc

    [/autoit]


    Edit:
    - Errorabfrage und Prüfung Betriebssystemversion eingebaut
    - Example für einbinden einer .ico-Datei als Icon eingefügt
    Edit2:
    - FilePrüfung eingefügt, Errorhandling optimiert

    Dateien

    MfG Schnuffel

    "Sarkasmus ist die niedrigste Form des Witzes, aber die höchste Form der Intelligenz."
    Val McDermid

    ein paar Infos ...

    Wer mehr als "nur" Hilfe benötigt, kann sich gern im Forum "Programmieranfragen" an uns wenden. Wir helfen in allen Fällen, die die Forenregeln zulassen.

    Für schnelle Hilfe benötigen wir ein ! lauffähiges ! Script, dass wir als Demonstration des Problems testen können. Wer von uns erwartet ein Teilscript erstmal lauffähig zu bekommen, der hat
    1. keine wirkliche Not
    2. keinen Respekt vor Menschen die ihm in ihrer Freizeit Ihre Hilfe anbieten
    3. oder ist einfach nur faul und meint wir coden das für ihn

    In solchen Fällen erlaube ich mir, die Anfrage einfach zu ignorieren. ;)

    4 Mal editiert, zuletzt von Schnuffel (7. April 2010 um 19:34)

  • kann ich mich nur anchliessen.

    Besonders zum erstellen von Programm biblitheken ist das bestimmt nützlich.
    (Für den Wiedererkannungseffekt.)

    Super Sache :thumbup:

    mfg Ubuntu

  • Hallo

    Sorry das ich den alten Post ausgrabe...
    Wenn ich das Bsp. Script aus der UDF laufen lasse...

    [autoit]

    $return = _FolderSetIcon("C:\new", @SystemDir & "\Shell32.dll", 23)
    If @error Then
    MsgBox(0,"",@extended)
    EndIf

    [/autoit]

    ...wird bei mir ein Ordner unter C:\ mit dem Namen "C:\Windows\SysWOW64\Shell32.dll,23" erstellt?
    Icon ist das normale Ordner Icon...
    Danke für Antwort...

    MFG chris :D