Windows Shell

Windows shell commands

SYNOPSIS

package require twapi
get_shell_folder CSIDL ?-create?
CloseThemeData
GetCurrentThemeName
GetThemeColor
GetThemeFont
invoke_url_shortcut SHORTCUTPATH ?options?
IsAppThemed
IsThemeActive
OpenThemeData
read_shortcut SHORTCUTPATH ?options?
read_url_shortcut SHORTCUTPATH
recycle_file FILENAME ?-confirm BOOLEAN? ?-showerror BOOLEAN?
shell_execute ?options?
shell_object_properties_dialog OBJECTPATH ?options?
write_shortcut SHORTCUTPATH ?options?
write_url_shortcut SHORTCUTPATH URL ?-missingprotocol usedefault|guess?

DESCRIPTION

This module provides procedures related to the Windows shell.

Item Identifiers

The Windows shell identifies objects in its namespace, including non-file objects such as Control Panel applets and printers, using an item ID. Similar to a file system path, an object resides within the shell namespace object hierarchy and the entire path to the object is defined by item identifier list.

Folder Paths

The command get_shell_folder returns the path to the directory specified by a Windows Shell CSIDL.

File Operations

The command shell_execute allows invocation of any operation of a file or resource as from Windows Explorer, for example, opening a URL in a browser, searching a directory, starting a program and so on.

The command recycle_file sends the specified file to the Windows Recycle Bin.

Shell Dialogs

The command shell_object_properties_dialog displays the property page dialogs for the specified shell objects.

Themes

The commands OpenThemeData, CloseThemeData, IsThemeActive, IsAppThemed, GetCurrentThemeName, GetThemeColor and GetThemeFont provide access to information related to the current theme if the underlying platform supports themes. See the Windows SDK for documentation about these. TwapiThemeDefineValue is a utility function that translates various theme-related symbols described in the SDk to their integer values to be passed to the above functions.

Shortcuts

The commands read_shortcut and write_shortcut allow reading and writing of shell shortcuts.

The commands read_url_shortcut and write_url_shortcut allow reading and writing of URL shortcuts. A URL shortcut can be invoked by invoke_url_shortcut.

Commands

get_shell_folder CSIDL ?-create?
Returns the path to the file system directory corresponding to the Windows shell folder identified by CSIDL. The path is always returned in native format.

CSIDL must be one of the following symbols or the corresponding integer values values as defined in the Windows SDK: csidl_admintools, csidl_common_admintools, csidl_appdata, csidl_common_appdata, csidl_common_desktopdirectory, csidl_common_documents, csidl_common_favorites, csidl_common_music, csidl_common_pictures, csidl_common_programs, csidl_common_startmenu, csidl_common_startup, csidl_common_templates, csidl_common_video, csidl_cookies, csidl_desktopdirectory, csidl_favorites, csidl_history, csidl_internet_cache, csidl_local_appdata, csidl_mymusic, csidl_mypictures, csidl_myvideo, csidl_nethood, csidl_printhood, csidl_profile, csidl_profiles, csidl_programs, csidl_program_files, csidl_program_files_common, csidl_recent, csidl_sendto, csidl_startmenu, csidl_startup, csidl_system, csidl_templates, csidl_windows.

Refer to the documentation in the Windows SDK for the meaning of each of these identifiers.

If the option -create is specified, the folder will be created if it does not currently exist.

On some platforms, some of the above CSIDL's may be invalid. In this case, the command will attempt to return equivalent paths through other means such as environment variable settings.

The command will return an empty string if the CSIDL does not exist on the platform or if its value cannot be retrieved.
CloseThemeData
See Themes.
GetCurrentThemeName
See Themes.
GetThemeColor
See Themes.
GetThemeFont
See Themes.
invoke_url_shortcut SHORTCUTPATH ?options?
Invokes a URL shortcut. SHORTCUTPATH specifies the path of the URL shortcut itself. The following options may be specified.
-allowui Allows user interaction.
-hwin HWIN Specifies the parent window handle for user interaction. This is ignored if -verb is specified or if -allowui is not specified.
-verb VERB Specifies the verb to invoke on the shortcut, for example open, edit etc.
IsAppThemed
See Themes.
IsThemeActive
See Themes.
OpenThemeData
See Themes.
read_shortcut SHORTCUTPATH ?options?
Reads a shortcut. SHORTCUTPATH specifies the path of the shortcut itself. The contents of the shortcut are returned as a keyed list with the following fields.
-args Command line arguments for the link.
-desc Description of the shortcut. This is the string that is visible to the user as the label of the shortcut.
-hotkey The hotkey associated with the shortcut. This is an integer as described in the documentation of the IShellLink::Hotkey command in the Platform SDK.
-iconindex The index of the icon within the icon file specifies by the -iconpath field.
-iconpath The path to the file from which the icon for the shortcut is to be taken.
-idl The item identifier list for the object pointed to by the shortcut.
-path The file system path in the case that the shortcut points to a file.
-showcmd The initial state of the window.
-workdir The working directory of the shortcut.
Note that the field names are the same as the options for the write_shortcut command so you can modify a shortcut by reading it, changing the specific fields and passing the same list to write_shortcut.

The content format and operation of the command may be controlled through the following options.
-hwin HWIN Identifies the window to be used as the parent of the dialog box that pops up to ask the user for more information when the shortcut cannot be resolved.
-install Calls the MSI installer if the shortcut is an advertised shortcut and the target has not been installed yet.
-nolinkinfo Disables distributed link tracking.
-nosearch Normally, the command will search for the target if it cannot be found in the location pointed to by the shortcut. Specifying this option disables this search.
-notrack Specifies that distributed link tracking to be not used.
-noui Specifies that no dialog box should be displayed even if the link cannot be resolved.
-rawpath Normally, the command resolves any embedded environment variables contained in the returned -path field and verifies the path exists. Specifying this option disables both these features and returns raw path contained in the shortcut.
-shortnames The path contained in the returned -path field uses short name (8.3) format.
-timeout TIMEOUT Specifies the timeout, in milliseconds, for resolving the link. This option has no effect unless the -noui is also specified.
-uncpath The path contained in the returned -path field is in UNC format.
read_url_shortcut SHORTCUTPATH
Returns the URL pointed to by a URL shortcut. SHORTCUTPATH specifies the path of the URL shortcut itself.
recycle_file FILENAME ?-confirm BOOLEAN? ?-showerror BOOLEAN?
Sends the specified file to the Windows Recycle Bin. Returns true on success and false if user aborted the command. Any errors will generate a Tcl exception.
-confirm BOOLEAN If true, a confirmation dialog is displayed to the user. Default is false.
-showerror BOOLEAN If true, an error dialog is displayed to the user in case of errors. Default is false.
shell_execute ?options?
The shell_execute command is a wrapper around the Windows ShellExecuteEx function that allows invocation of various operations on file and other resources in the same manner as exposed by Windows Explorer as shown in the examples below.

The command supports the options shown in the table below and returns an empty string unless the -getprocesshandle option is specified.
-asyncok BOOLEAN TBD.
-class BOOLEAN TBD.
-connect BOOLEAN TBD.
-dir PATH Path of the working directory. Defaults to the current directory.
-getprocesshandle BOOLEAN Normally, the command returns an empty string. If this option is specified, the command returns a handle to the process, if any, that was created by the shell to handle the request. If no such process was required to be created, or was already running, an empty string is returned. If a non-empty handle is returned, it must be closed by calling close_handle.
-hicon HANDLE TBD.
-hkeyclass BOOLEAN TBD.
-hmonitor HANDLE Specifies a handle to a monitor on multiple-monitor systems. Cannot be used with the -hicon option.
-hotkey BOOLEAN TBD.
-hwin BOOLEAN Specifies the parent window handle, if any, for dialogs that are displayed. By default, no parent window is specified.
-idl BOOLEAN
-invokeidlist BOOLEAN Normally, the shell will look up the registry for the list of verbs applicable for a file. If this option is specified as true, the shell will look up verbs dynamically added by shell extensions. See examples below. Default is false.
-logusage BOOLEAN If true, the invocation will add to the counter maintained by Windows for determining the applications that show up on the Start menu. Default is false. Requires Windows XP or later and will generate an error on earlier versions of Windows.
-noconsole BOOLEAN If true, the current process is not used for any processes created for the operation. A new console window is created if required. Default is false.
-noui BOOLEAN If true, no user interaction, such as error display is done. Default is false.
-nozonechecks BOOLEAN TBD.
-params STRING Contains the parameter string to be passed to the invoked application. Use standard Windows syntax for separating parameters using spaces and quotes.
-path STRING Path of the file or object on which the action is to be invoked. If unspecified, defaults to the current directory.
-show STRING Specifies how the application invoking the action is to be displayed. Must be one of hide, shownormal, normal, showminimized, showmaximized, maximize, shownoactivate, show, minimize, showminnoactive, showna, restore, showdefault, or forceminimize. See the Windows SDK documentation of ShellExecute for details. Default is normal.
-substenv BOOLEAN If true, any environment variables present in the values of the -path and -dir options are expanded. Default is false.
-unicode BOOLEAN TBD.
-verb ACTION Specifies the action to invoke on the resource, for example open, edit etc. See the examples below.
-wait BOOLEAN Wait for the action to complete before returning. The exact effect of this depends on the action being invoked and the application handling the action. Default is false.
-waitforinputidle BOOLEAN If specified as true, the command will wait up to one minute for any processes that are created as part of the invocation to enter the idle loop. Default is false.
Examples: Start up an application (notepad.exe):
shell_execute -path notepad.exe
Start up an application with parameters:
shell_execute -path notepad.exe -params {sample.txt}
Invoke the default action for a particular document. In most cases, this will open the application associated with the document type:
shell_execute -path sample.doc
Invoke a non-default action on a document (printing using the associated application):
shell_execute -path sample.doc -verb print
Invoke a non-default action (search) on a directory:
shell_execute -path c:/temp -verb find
Open a document in the home directory using environment variables:
shell_execute -path {%HOMEDRIVE%\%HOMEPATH%\My Documents\darknet.pdf} -substenv true
Launch a browser for a URL:
shell_execute -path http://www.google.com
Compose a email message:
shell_execute -path mailto:[email protected]
Invoke a dynamic action on a file. This will bring up the property sheet for notepad.exe instead of executing it.
shell_execute -path notepad.exe -verb properties -invokeidlist true
shell_object_properties_dialog OBJECTPATH ?options?
Displays the shell property dialog for the specified object which may be a file, a printer or a volume. OBJECTPATH is the path or the name of the object. The following options may be specified:
-hwin HWIN If specified, HWIN is the handle to the window to be used as the parent for the dialog.
-type file|printer|volume Specifies the type of the object identified by OBJECTPATH. If this option is not specified, the command will attempt to figure out the object type and display the appropriate dialog.
write_shortcut SHORTCUTPATH ?options?
Writes or creates a shortcut. SHORTCUTPATH specifies the path of the shortcut itself. The following options control the contents of the shortcut.
-args ARGUMENTS Specifies the command line arguments for the link.
-desc DESCRIPTION Specifies the description of the shortcut. This is the string that is visible to the user as the label of the shortcut.
-hotkey HOTKEY Specifies the hotkey to be associated with the shortcut. HOTKEY should be an integer as described in the documentation of the IShellLink::Hotkey command in the Platform SDK or a symbolic string as described in the register_hotkey command.
-iconindex INDEX Specifies INDEX as the index of the icon within the icon file specifies by the -iconpath option.
-iconpath ICONPATH Specifies ICONPATH as the path to the file from which the icon for the shortcut is to be taken.
-idl IDL Specifies that the shortcut should point to the object identified by the item identifier list IDL. This is useful in cases where the target of the short cut is not a file.
-path TARGETPATH Specifies TARGETPATH as the file system path to which the shortcut points. This must be a full absolute path else Windows will return an error.
-showcmd WINDOWSTATE Specifies the initial state of the window. WINDOWSTATE should be one of minimized, maximized or normal.
-workdir DIRPATH Specifies DIRPATH as the working directory of the shortcut.
write_url_shortcut SHORTCUTPATH URL ?-missingprotocol usedefault|guess?
Writes or creates a URL shortcut. SHORTCUTPATH specifies the path of the URL shortcut itself. URL is the URL to which the shortcut should point.

If the -missingprotocol option is specified, the system will attempt to fill in the protocol if URL itself does not specify a protocol. If the value of this option is guess, the system will attempt to guess the protocol based on the URL string. If the option value is usedefault, the system will use the default protocol scheme.

COPYRIGHT

Copyright © 2004-2009 Ashok P. Nadkarni

Tcl Windows API 3.0.29 Privacy policy