How to customize a folder programatically on Windows 7 - winapi

Windows 7 offers the possibility to customize folder icons and pictures by right clicking on the folder, choosing the "Properties" command and then the "Customize" tab, as explained for example here.
Can this be done programatically ?

Yes, you can create a desktop.ini file programmatically. The file is documented here.
You could, for instance, rename the folder in an internationalization scenario (e.g. a folder named "users" could me displayed to the user as utilisateurs on a French OS, or Benutzer on a German OS), by creating a file with the following contents:
[.ShellClassInfo]
LocalizedResourceName=#C:\foo\bar.dll,-100
which would take the name of the folder in the bar.dll string resource ID 100.

Related

When changing the icon of the Hard Drive in MacOS - where are the icns-file actually stored?

Long story short - I bought a new computer and decided not to do a migration from my old Mac to the new one. Still - there are some things I would like to keep and the icon I found years ago to replace the "Macintosh HD" icon is something I very much would like to find.
So my question is - where are these icons actually stored? I've searched "everywhere". It's not in /System/Library/CoreServices/C­oreTypes.bundle/Contents/Resou­rces where the system icons is stored.
Anyone out there with the same level of OCD as me who can help me out?
I'm running Catalina 10.15.1 if relevant.
First of all:
Custom icons that you use to override System default ones will never be stored inside /System/Library/.. as this is a System reserved folder.
On macOS when you paste a custom icon to a folder or file using the Finder Info panel these are stored in the resource fork of the extended attributes of a file/folder.
Now regarding your use case:
In order to see these you need to show the hidden files and you will see
.VolumeIcon.icns on your / local drive (Macintosh HD):
As this is a write protected path (SIP) you cannot store custom data there and instead this .VolumeIcon.icns alias is there and will point to the actual icon file.
If you are still not able to locate the icon file you can always use this next trick. Open the Finder "Info Panel" for your MacintoshHD that has the custom icon and click on the icon representation and copy it to the clipboard (cmd + C) and then open Preview and select "File > New from Clipboard" and then save the icon as icns. Done!

Are "Desktop", "Documents", etc. folders localized on filesystem level on Windows?

An user of my program can select a new filename in "Documents" directory using "Save As" dialog (Python's tkinter.filedialog.asksaveasfilename), but they can't complete the operation, because system gives following error:
It looks like this problem has to do with French used as Windows language.
The user says that they can save into parent directory (ie. into home directory), but not under "Documents" and "Desktop".
Any ideas how this situation can occur and how to solve it?
On which level does the special folder localization happen? Is "Desktop" directory translated in filesystem?

What is the path of "my computer" folder on windows?

I am working on a C++ windowsform project, using visual Studio IDE.
I use CFileDialog class to ask the user to select a file to open.
It display an usual open file selection windows.
I would like the default folder displayed to be the same as the one accessed when clicked on "My computer", where the harddrives, USB drives, dvd drives etc. are displayed.
I can define default folder by writting its path tolpstrInitialDir member, but I don't find the path for such a folder. I tried "\", "explorer.exe", "", none of them gave me the expected result.
The application will be used by several users, so the solution must not include the user name in the path. i.e "C:\Documents and Settings[user]\Desktop\My Computer" may work but is not correct for my application.
Does anyone know of to define the "root" path of windows (i.e the root of C:\) ?
I searched on SO and internet but maybe I have used wrong keywords because I couldn't find appropriate content.
My Computer is a virtual shell folder that doesn't correspond to any file system directory. There's no file system path that would correspond to that location.
Fortunately, file dialogs do speak "shellese", so you can use the CLSID (not to be confused with the GUID KNOWNFOLDERID or the CSIDL) of the shell folder. Sample in C# Winforms, but really, the only important part is the ::CLSID):
var ofd = new OpenFileDialog();
ofd.InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
ofd.ShowDialog();
Disclaimer: I couldn't find any relevant documentation for the virtual folder CLSID, or this behaviour of the File dialog. So this is most likely not contractual, and could possibly change in future versions of Windows.
In the explorer, in the search bar copy the address of
This PC
and then select the text
This PC
and paste. Normally we get the
Ce PC ":: {CLSID}"
and then just copy
:: {CLSID}
and paste it wherever we want.
Path should be: C:\Users\UserName\Desktop\Computer.lnk

Always save specific file type in windows to one location?

I'm trying to do the following I'm not sure if it's possible using VB.NET.
I want to specify default saving point for all files type for example:
In my program you choose the path "C:\Users\Markus\Pictures" for pictures and everytime you download pictures files from website, or using skype or any other program when Save File Dialog opens up (external one not via my program or connected to vb.net just the windows default one) then it will show "C:\Users\Markus\Pictures" always for .jpg .gif type of files etc...
Thanks a lot.
This bits of codes should solve your problem
SaveFileDialog1.InitialDirectory = #"C:\Users\Markus\Pictures"
InitialDirectory property represents the directory to be displayed when the open file dialog appears first time.
SaveFileDialog1.Filter = "txt files (*.jpg)|*.jpg|All files (*.*)|*.*"
Filter property represents the filter on an open file dialog that is used to filter the type of files to be loaded during the browse option in an open file dialog.
refer to this link for more info
You can programmatically modify the paths of the Windows special directories (My Pictures, etc) in the registry key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
However, your app will have to be granted permissions to do so (see RegistryPermission Class)
Of course, this will work for those file types that have entries in this registry key, and only if an external application uses this key

Creating a web shortcut on user desktop programmatically

There are quite a few resources for programmatically creating .lnk type shortcuts to files and programs on the desktop but I'm wondering how to create a shortcut to a web URL.
From what I can gather, the web URL shortcut is a text file ending in .URL and contains a ini-like definition such as:
[InternetShortcut]
URL=http://www.google.com/
However, it's not enough to just create the file, it seems you also need to change its meta URL properties to include the same link.
Any idea how to create these?
Any sample code from .Net/Perl/batch is welcome.
You can create .lnk shortcuts to any URI, including web addresses. Just create the shortcut and make the target your web address instead of a file location.
See this other question for how to do it programmatically:
Creating application shortcut in a directory

Resources