Export (0) Print
Expand All

Manipulating Folders and Files by Using .inf Files

Cc939921.chap_18(en-us,TechNet.10).gif Cc939921.image(en-us,TechNet.10).gif

You can manipulate files and folders in several ways by using .inf files:

  • Create folders and links in folders.

  • Manage long file names.

  • Set attributes for files and folders.

  • Copy files to the Program Files folder.

Creating Folders and Links in Folders

After a component is installed, Windows creates a folder in the Program Files folder or creates links in a folder. The setup program looks in the Setup.ini file for a [progman.groups] section and then parses it to create folders and links in those folders.

If you are installing a component that requires a folder or links in the Program Files folder, you need to create an [UpdateInis] section in an .inf file that will create the proper entries in the Setup.ini file.

Use the following syntax in the Setup.ini file to create folders and links. Note that folders are relative to the Start menu:

[progman.groups] folder_1 = Folder_1_Name folder_2 = Folder_2_Name : folder_n = Folder_n_Name

[folder_1] link-name , .exe-name , icon-file-name , icon-index , profile

If you specify NULL as the profile, the link is always added to the folder.

If you specify NULL as the .exe name, the name will be deleted from the group if it exists there.

Note If a folder or link has a space in its description, you must use double quotation marks.

Managing Long File Names

To support backwards compatibility, the setup engine in Windows 32-bit versions of the browser is a 16-bit dynamic link library (.dll) file. Because of this, the Windows setup engine can only copy files that have 8.3 file names.

The setup engine runs a 32-bit program when it exits that manages files with long names. The 32-bit program gets its instructions from predefined paths in the registry.

The following is the path for rename operations in the registry:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RenameFiles

The following is the path for delete operations in the registry:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\DeleteFiles

Each group of rename and delete operations is added to entries under each path. Each group of operations is limited to renaming or deleting files in a single folder. For each rename or delete operation, you must include a minimum of two entries in each subkey: the folder path for the files to be renamed or deleted, and the actual rename or delete operation.

The first element in each group of operations is the folder entry. Each rename operation in the folder entry has the following form:

" old_short_name "=" new_long_name ,[ attrib_flag ]"

You can use the optional attrib_flag to set file attributes during the rename operation. The flag is composed of the following values:

1READONLY2HIDDEN3SYSTEM

To set multiple attributes for a file or folder, the flags are added together. For example, to set the READONLY and HIDDEN attributes, attrib_flag would be 3.

The following examples are from an AddReg section that sets the SYSTEM and HIDDEN attributes for the \Windows\System\Sample folder:

HKLM,Software\Microsoft\Windows\CurrentVersion\RenameFiles\Sys,,,%11% 

HKLM,Software\Microsoft\Windows\CurrentVersion\RenameFiles\Sys,SAMPLE,,"SAMPLE,6"

Each delete operation in the folder entry has the following form:

" arbitrary_key_name "=" long_name_to_delete "

The following example shows an AddReg entry that performs these tasks:

  • Renames the Oldname.txt file as the New Long Name.txt file in the C:\Samples folder.

  • Renames the Myreadme.txt file to the My App Readme.txt file in the Windows folder.

[MyAppShort2Long] 
HKLM,Software\Microsoft\Windows\CurrentVersion\RenameFiles\Samples,,,C:\Samples
HKLM,Software\Microsoft\Windows\CurrentVersion\RenameFiles\
Samples,oldname.txt,,"New Long Name.txt"
HKLM,Software\Microsoft\Windows\CurrentVersion\RenameFiles\Win,,,%25% 
HKLM,Software\Microsoft\Windows\CurrentVersion\RenameFiles\Win,myreadme.txt,,"My App Readme.txt" 

The following example shows an AddReg entry that performs these tasks:

  • Deletes the New Long Name.txt file from the C:\Samples folder.

  • Deletes the My App Readme.txt file from the Windows folder.

[MyAppDelLong] 
HKLM,Software\Microsoft\Windows\CurrentVersion\DeleteFiles\Samples,,,C:\Samples 
HKLM,Software\Microsoft\Windows\CurrentVersion\DeleteFiles\Samples,oldname.txt,,"New Long Name.txt"

HKLM,Software\Microsoft\Windows\CurrentVersion\DeleteFiles\Win,,,%25% 
HKLM,Software\Microsoft\Windows\CurrentVersion\DeleteFiles\Win,myreadme.txt,,"My App Readme.txt"

After these rename and deletion operations have been processed, the entries are removed from the registry.

Note During the rename operation, the destination file is deleted before any files are renamed. If the same rename operation is queued twice, it could result in a loss of the file. For example, a bitmap that needs to be renamed from Picture.bmp to Windows Screen Picture.bmp might get deleted before the rename operation happens if Windows Screen Picture.bmp already exists from an earlier rename operation. The exception to this rule is when the existing destination file name is a folder.

Setting Attributes for Files and Folders

To set the attributes for a file or folder, you use the same convention as when you create long file names by using an optional flag. For more information, see "Managing Long File Names" earlier in this chapter.

Copying Files to the Program Files Folder

Because copying Windows files is a 16-bit operation, only short (8.3) file names can be used. Therefore, to access the Program Files folder, you need to use the 8.3 equivalent, "24,PROGRA~1", in the [DestinationDirs] section of an .inf file. Similarly, the short file name equivalent must be used to access any folders with long file names that are in the Program Files folder.

The following example copies three files to the \Program Files\Accessories folder and creates links to one of the files:

[WordPadInstall]
CopyFiles = WordPadCopyFiles 
UpdateInis = WordPadInis

[DestinationDirs]
WordPadCopyFiles = 24,%PROGRAMF%\%ACCESSOR%

[WordPadCopyFiles] 
mswd6_32.wpc 
wordpad.exe
write32.wpc

[WordPadInis]
setup.ini, progman.groups,, "group4=%APPS_DESC%" 
;creates Accessories folder (if not already there) 
setup.ini, group4,, """%WORDPAD_LINK%"", ""%24%\%PROGRAMF%\%ACCESSOR%\WORDPAD.EXE""" 
;creates link in Accessories folder

[Strings] 
APPS_DESC = "Accessories" 
WORDPAD_LINK = "WordPad" 
; Folder names - note that the short versions must match the truncated 
; 8-character names for the long versions, or there will be problems. 
PROGRAMF = "Progra~1" ; first 6 chars of Program_Files, + "~1" 
ACCESSOR = "Access~1" ; first 6 chars of Accessories, + "~1" 

Limitations of .inf Files

The following are limitations of .inf files:

  • You cannot delete a directory.

  • You cannot move a file to a different location by using the RenFiles entry. ( RenFiles only renames a file in place.)

  • You cannot copy a file to another location on your hard disk by using the CopyFiles entry. ( CopyFiles only copies files from the source disk to the destination directory.)

.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft