stamandster Posted October 19, 2012 Posted October 19, 2012 (edited) So as you know Windows Vista & 7, Server 2008 & 2008 R2 doesn't display a different shared folder icon like previous versions. It's a nice visual cue and some users miss it (I do!). I know there's other ways of finding this information out but who wants to do that! Below is a quick and dirty script I put together. Of course, no guarantee this won't screw up your OS, but it shouldn't (just creating a Desktop.ini). It will ONLY change the icon for user shared folders NOT Admin Shares, etc (http://msdn.microsoft.com/en-us/library/aa394435%28VS.85%29.aspx). Usage (use parameters for extra options): SharedFolderIcon.exe --> Will change all user created shares to the same icon as the script exe (useful if you're the only one using it), uses script exe for icon path SharedFolderIcon.exe 1 --> Will extract the Icon file that was used to SFI.ico in the same directory as the script (so you can put it somewhere else you want to on multiple servers and call it with the defined parameters) SharedFolderIcon.exe "C:PathtoIcon.dll" --> Will use a defined icon. No index is supplied so a defaul index of 0 is used. Icon can be almost anything exe,dll,sys,ico. SharedFolderIcon.exe "%SystemRoot%system32SHELL32.dll,9" --> Will use a defined icon with an index of 9, use a comma to signify. The icon path utilizes a system variable. Attached is the icon used in the fileinstall. The largest this icon will show is "Medium" in Explorer. expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Default.ico #AutoIt3Wrapper_Outfile=SharedFolderIcon.exe #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <array.au3> ; ; ; ; ; So we can pass through %windir%, etc. AutoItSetOption("ExpandEnvStrings",1) ; ; ; ; ; VARIABLES DIM $command = 0, $ico_local = "", $ic, $icon = "", $ico_index = "" DIM $icon_name = "SFI.ico" ; Default Icon Name for Export DIM $icon_Default = StringTrimRight(@ScriptFullPath,3) & "exe" ; Use Script Executable for ICON ; ; ; ; ; Query commands IF isarray($CmdLine) then ; Make sure you get an Array If $CmdLine[0] <> 0 then ; check that you actually have parameters For $ic = 1 to Ubound($CmdLine)-1 IF StringLen($CmdLine[$ic]) = 1 Then ; IsNumber won't work for here, too lazy to figure out how to look for only numbers in a string $command = $CmdLine[$ic] Else $icon = $CmdLine[$ic] Endif Next endif endif ; ; ; ; ; Parse command(s) Select Case $command = 1 ; Extract Default Icon FileInstall("Default.ico",$icon_name) Exit Case $command = "" and $icon = "" ; Use default "installed" Icon when parameter = 0 or nothing and ICON path is not supplied $ico_local = $icon_Default $ico_index = 0 IF NOT FileExists($ico_local) then Exit ; if default icon wasn't installed then EXIT Case $command = 0 and $icon <> "" ; User defined Icon when a string is supplied IF StringInStr($icon,",") Then ; Check to see if INDEX is supplied with ICON path $usericon = StringSplit($icon,',') $ico_local = $usericon[1] if StringInStr($ico_local,"@CurrDir") Then $ico_local = StringReplace($ico_local,"@CurrDir",@scriptdir) ; Can use @CurrDir for current directory running from $ico_index = $usericon[2] Else ; If INDEX is not supplied then use 0 $ico_local = $icon $ico_index = 0 endif IF NOT FileExists($ico_local) then Exit ; if user defined icon does not exist EXIT EndSelect ; ; ; ; ; Start Setting Icon for Shared Folders $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 DIM $colItems = "" DIM $Output = "" DIM $strComputer = "localhost" DIM $InfoTip = "" $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootCIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Share", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems ; Check to see if the share is a DISK Type shared folder ; http://msdn.microsoft.com/en-us/library/aa394435%28VS.85%29.aspx IF $objItem.Type = 0 Then IF $objItem.Description = "" Then $Share_InfoTip = $objItem.Caption Else $Share_InfoTip = $objItem.Description endif _SetFolderIcon($objItem.Path,$ico_local,$ico_index,$Share_InfoTip) Endif $InfoTip = "" Next Endif ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FUNCTIONS FUNC _SetFolderIcon($sfi_folder,$sfi_icon,$sfi_iconindex ="",$sfi_infotip="") ; Make sure the location exists If FileExists($sfi_folder) then ; Get "Folder" Attributes $SFI_GetAttrib = FileGetAttrib($sfi_folder) Select ; If System Drive or Folder then return Case StringinStr($SFI_GetAttrib,"S") return False ; If not a folder then return Case NOT StringinStr($SFI_GetAttrib,"D") return False EndSelect ; Check to see if Icon is already configured for Folder if Desktop.ini Already exists If FileExists($sfi_folder & "" & "Desktop.ini") Then $sfi_icoexists = IniRead($sfi_folder & "" & "Desktop.ini",".ShellClassInfo","IconFile","") IF $sfi_icoexists = $sfi_icon then Return True EndIf ; Create Desktop.INI to change Icon IniWriteSection($sfi_folder & "" & "Desktop.ini", ".ShellClassInfo", _ "IconFile=" & $sfi_icon & @LF & _ "IconIndex="& $sfi_iconindex & @LF & _ "InfoTip="& $sfi_infotip) FileSetAttrib($sfi_folder, "+R") IF FileSetAttrib($sfi_folder & "" & "Desktop.ini", "+HSA") = 1 Then Return True Endif EndFunc Default.ico Edited July 11, 2014 by stamandster
highend Posted February 7, 2013 Posted February 7, 2013 If I run this script with SciTE4AutoIt3 (AutoIt version = 3.3.8.0) I get the following error: >Running AU3Check (1.54.22.0) from:D:\Tools\AutoIt\App +>13:33:28 AU3Check ended.rc:0 >Running:(3.3.8.0):D:\Tools\AutoIt\App\autoit3_x64.exe "D:\Tools\.Scripts\.AutoIt\SharedFolderIcon\SharedFolderIcon.au3" D:\Tools\.Scripts\.AutoIt\SharedFolderIcon\SharedFolderIcon.au3 (74) : ==> Variable must be of type "Object".: $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Share", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) $colItems = $objWMIService^ ERROR ->13:33:28 AutoIT3.exe ended.rc:1 >Exit code: 1 Time: 0.920
stamandster Posted July 11, 2014 Author Posted July 11, 2014 Is WMI working for you at all?? This has only been tested on Server 2008 R2 and 7.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now