0

I have a folder, and inside I have an .ico file that I want to set up as the icon to the main folder.

Here's my problem, if I do this manually and input this code

[.ShellClassInfo]
ConfirmFileOp=0  
NoSharing=1  
IconFile=folder.ico
IconIndex=0
InfoTip=Some sensible information.

in a desktop.ini file it works great.

But if a create a bat file with the following code it does not.

ECHO [.ShellClassInfo] >desktop.ini  
ECHO ConfirmFileOp=0 >>desktop.ini  
ECHO NoSharing=1 >>desktop.ini  
ECHO IconFile=folder.ico >>desktop.ini  
ECHO IconIndex=0 >>desktop.ini  
ECHO InfoTip=Some sensible information. >>desktop.ini 

The Output is exactly the same. I also assigned the +r to the folder because without it it doesn't work either way.

So what is wrong here?

1 Answers1

1

It's due to several non-escaped special characters in your commands. If you run the batch first, then open desktop.ini to see its content, you'll find it's far from your expectation.

Problems:

  1. Excessive blank space at the end of each line.

    A appears on the left of >, which means an extra blank space to be added to the file.

    To solve this, simply remove this space. Like ECHO ConfirmFileOp=0>>desktop.ini.

  2. Un-escaped numbers

    ECHO ConfirmFileOp=0>>desktop.ini means write ConfirmFileOp= to the command window and pipe stdout to desktop.ini. 0 is a piping token.

    To solve this, escape the numbers by ^0, ^1 or so. Reference - Escape angle brackets in a Windows command prompt

    An easier way is by writing output redirecting instruction at the beginning of the line -

    >>desktop.ini echo ConfirmFileOp=0
    
  3. Improper file attributes

    desktop.ini should be hidden, system, and NOT archived. Reference - https://superuser.com/a/396051/333430 You can change the attributes of desktop.ini by adding the following line to the batch script:

    attrib desktop.ini -a +h +s
    
Community
  • 1
  • 1
Yvon
  • 2,903
  • 1
  • 14
  • 36
  • Thank you for the response Yvon, but that didn't solve it. I know desktop.ini its a hidden file. The curious thing is, if I imput the same code to a txt file and then convert that file using another bat file with the following ren *.txt *.ini It works and the icon shows up. But If I put that same code in the end of the previous code It doesn´t work, that's awkward. – João Lagoas Aug 11 '14 at 11:40
  • @JoãoLagoas did you log off and log in again after this process? – Yvon Aug 11 '14 at 14:16
  • @JoãoLagoas It also happens to me that, when I first created such a file in a new folder, nothing happened; when I first changed the icon in "properties" (of another new folder), any following operations (enable icon, disable icon, change icon, etc. ) worked. I'm not sure why this occurs, but Windows seems to be immune to auto-generated desktop.ini, in case of malware or virus. User input such as writing .txt file will create the file with explorer.exe in the first place; this may be the difference. – Yvon Aug 11 '14 at 14:33