| |
|
| java.lang.Object com.izforge.izpack.util.os.ShellLink
ShellLink | public class ShellLink implements NativeLibraryClient(Code) | | This class represents a MS-Windows shell link, aka shortcut. It supports creation, modification
and deletion as well as reporting on details of shell links. This class uses a number of native
methods to access the MS-Windows registry and load save and manipulate link data. The native code
is contained in the file ShellLink.cpp .
For more detailed information on Windows shortcuts read the win32 documentation from Microsoft on
the IShellLink interface. There are also useful articles on this topic on the MIcrosoft website.
Using
Shell Links in Windows 95
The
IShellLink interface
IShellLink
version: 0.0.1 / 1/21/02 author: Elmar Grom |
Field Summary | |
final public static int | ALL_USERS ALL_USERS = 1; the constant to use for selecting the all users. | final public static int | CURRENT_USER CURRENT_USER = 0; the constant to use for selecting the current user. | final public static int | DESKTOP | final public static int | HIDE Hide the window when starting. | final public static int | MAXIMIZED Show the window maximized when starting. | final public static int | MINIMIZED Show the window minimized when starting. | final public static int | MINNOACTIVE Show the window minimized when starting. | final public static int | NORMAL Show the window 'normal' when starting. | final public static int | PROGRAM_MENU | final public static int | STARTUP | final public static int | START_MENU |
Constructor Summary | |
public | ShellLink(int type, String name) Creates an instance of ShellLink of a specific type. | public | ShellLink(String name, int userType) Creates an instance of ShellLink from an existing shell link on disk. | public | ShellLink(int type, int userType, String group, String name) Creates an instance of ShellLink from an existing shell link on disk.
Parameters: type - The type of link, one of the following values:
ShellLink.DESKTOP ShellLink.PROGRAM_MENU ShellLink.START_MENU ShellLink.STARTUP
Parameters: userType - the type of user for the link path. Parameters: group - The program group (directory) of this link. |
Method Summary | |
protected void | finalize() Destructor, releases COM and frees native resources. | public void | freeLibrary(String name) This method is used to free the library at the end of progam execution. | public String | getArguments() Returns the command line that the link passes to the target. | public String | getDescription() Returns the description for the link. | public String | getDirectoryCreated() Returns the path of the directory where the link file is stored, if it was necessary during
the previous save operation to create the directory. | public String | getFileName() Returns the fully qualified file name under which the link is saved on disk. | public int | getHotkey() Retruns the hotkey that can be used to activate the link. | public int | getIconIndex() | public String | getIconLocation() Returns the path and file name of the file that contains the icon that is associated with the
link. | public String | getLinkName() Returns the name shown in a menu or on the desktop for the link. | public String | getLinkPath(int userType) Returns the path where the links of the selected type are stroed. | public int | getLinkType() Returns the user type for the link. | public int | getShowCommand() Returns the initial condition of the target window (HIDE, NORMAL, MINIMIZED, MAXIMIZED). | public String | getTargetPath() | public int | getUserType() Returns the (ShellLink) user type for the link. | public String | getWorkingDirectory() Retruns the working deirectory for the link target. | public String | getallUsersLinkPath() | public String | getcurrentUserLinkPath() | public void | save() Saves this link. | public void | save(String name) Saves this link to any desired location. | public void | setArguments(String arguments) Sets the command line arguments that will be passed to the target when the link is activated. | public void | setDescription(String description) Sets the description string that is used to identify the link in a menu or on the desktop. | public void | setHotkey(int hotkey) Sets the hotkey that can be used to activate the link.
Parameters: hotkey - a valid Windows virtual key code. | public void | setIconLocation(String path, int index) Sets the location of the icon that is shown for the shortcut on the desktop.
Parameters: path - a fully qualified file name of a file that contains the icon. Parameters: index - the index of the specific icon to use in the file. | public void | setLinkName(String name) Sets the name shown in a menu or on the desktop for the link.
Parameters: name - The name that the link should display on a menu or on the desktop. | public void | setLinkType(int type) Sets the type of link
Parameters: type - The type of link desired. | public void | setProgramGroup(String groupName) Sets the name of the program group this ShellLinbk should be placed in. | public void | setShowCommand(int show) Sets the show command that is passed to the target application when the link is activated.
The show command determines if the the window will be restored to the previous size,
minimized, maximized or visible at all. | public void | setTargetPath(String path) Sets the absolute path to the shortcut target. | public void | setUserType(int type) | public void | setWorkingDirectory(String dir) Sets the working directory for the link target. |
ALL_USERS | final public static int ALL_USERS(Code) | | ALL_USERS = 1; the constant to use for selecting the all users.
|
CURRENT_USER | final public static int CURRENT_USER(Code) | | CURRENT_USER = 0; the constant to use for selecting the current user.
|
DESKTOP | final public static int DESKTOP(Code) | | This type of shortcut shows on the desktop
|
HIDE | final public static int HIDE(Code) | | Hide the window when starting. This is particularly useful when launching from a *.bat file,
because no DOS window and no button for the DOS window on the task bar will show!
Note: this option is not available through the Windows 98+ UI!
|
MAXIMIZED | final public static int MAXIMIZED(Code) | | Show the window maximized when starting.
|
MINIMIZED | final public static int MINIMIZED(Code) | | Show the window minimized when starting. The window will not show but a corresponding button
in the task bar will.
Newer IShellLink only allows Normal, MinNoActive, Maximized.
|
MINNOACTIVE | final public static int MINNOACTIVE(Code) | | Show the window minimized when starting. Note: for win98 and newer, use MINNOACTIVE instead
of MINIMIZED.
|
NORMAL | final public static int NORMAL(Code) | | Show the window 'normal' when starting. Restores the window properties at the last shut-down.
|
PROGRAM_MENU | final public static int PROGRAM_MENU(Code) | | This type of shortcut shows in the program menu
|
STARTUP | final public static int STARTUP(Code) | | This type of shortcut is executed at OS launch time
|
START_MENU | final public static int START_MENU(Code) | | This type of shortcut shows in the start menu
|
ShellLink | public ShellLink(int type, String name) throws Exception, IllegalArgumentException(Code) | | Creates an instance of ShellLink of a specific type. Initializes
currentUserLinkPath and allUsersLinkPath.
A LinkPath is empty if the combination of linkType and userType, are not valid.
Note: If a linkPath is empty, the userType is reset to the other userType.
If both linkPaths are empty, an IllegalArgumentException is thrown.
Parameters: type - The type of link desired. The following values can be set:
ShellLink.DESKTOP ShellLink.PROGRAM_MENU ShellLink.START_MENU ShellLink.STARTUP
Parameters: name - The name that the link should display on a menu or on the desktop. Do not includea file extension. exception: IllegalArgumentException - if any of the call parameters are incorrect, or if nolinkPaths are returned. exception: Exception - if problems are encountered in initializing the native interface |
ShellLink | public ShellLink(int type, int userType, String group, String name) throws Exception, IllegalArgumentException(Code) | | Creates an instance of ShellLink from an existing shell link on disk.
Parameters: type - The type of link, one of the following values:
ShellLink.DESKTOP ShellLink.PROGRAM_MENU ShellLink.START_MENU ShellLink.STARTUP
Parameters: userType - the type of user for the link path. Parameters: group - The program group (directory) of this link. If the link is not part of a programgroup, pass an empty string or null for this parameter. (...\\Desktop\\group). Parameters: name - The file name of this link. Do not include a file extension. See Also: ShellLink.CURRENT_USER See Also: ShellLink.ALL_USERS exception: IllegalArgumentException - if any of the call parameters are incorrect exception: Exception - if problems are encountered in initializing the native interface |
finalize | protected void finalize() throws Throwable(Code) | | Destructor, releases COM and frees native resources.
|
freeLibrary | public void freeLibrary(String name)(Code) | | This method is used to free the library at the end of progam execution. After this call, any
instance of this calss will not be usable any more! Note that this method does NOT
return!
DO NOT CALL THIS METHOD DIRECTLY!
It is used by the librarian to free the native library before physically deleting it from its
temporary loaction. A call to this method will freeze the application irrecoverably!
Parameters: name - the name of the library to free. Use only the name and extension but not thepath. See Also: com.izforge.izpack.util.NativeLibraryClient.freeLibrary |
getDirectoryCreated | public String getDirectoryCreated()(Code) | | Returns the path of the directory where the link file is stored, if it was necessary during
the previous save operation to create the directory. This method returns null
if no save operation was carried out or there was no need to create a directory during the
previous save operation.
the path of the directory where the link file is stored or null if nosave operation was carried out or there was no need to create a directory during the previoussave operation. |
getFileName | public String getFileName()(Code) | | Returns the fully qualified file name under which the link is saved on disk. Note:
this method returns valid results only if the instance was created from a file on disk or
after a successful save operation.
the fully qualified file name for the shell link |
getHotkey | public int getHotkey()(Code) | | Retruns the hotkey that can be used to activate the link.
the virtual keycode for the hotkey See Also: ShellLink.setHotkey |
getIconLocation | public String getIconLocation()(Code) | | Returns the path and file name of the file that contains the icon that is associated with the
link.
the path to the icon See Also: ShellLink.setIconLocation |
getLinkName | public String getLinkName()(Code) | | Returns the name shown in a menu or on the desktop for the link.
the name |
getLinkPath | public String getLinkPath(int userType)(Code) | | Returns the path where the links of the selected type are stroed. This method is useful for
discovering which program groups already exist.
Parameters: userType - the type of user for the link path. One of ShellLink.CURRENT_USER orShellLink.ALL_USERS the path to the type of link set for this instance. |
getShowCommand | public int getShowCommand()(Code) | | Returns the initial condition of the target window (HIDE, NORMAL, MINIMIZED, MAXIMIZED).
the target show command See Also: ShellLink.setShowCommand |
getallUsersLinkPath | public String getallUsersLinkPath()(Code) | | Returns the path for allusersLink
allusersLinkPath |
getcurrentUserLinkPath | public String getcurrentUserLinkPath()(Code) | | Returns the path for currentusersLink
currentUsersLinkPath |
save | public void save(String name) throws Exception(Code) | | Saves this link to any desired location.
Parameters: name - the fully qualified file name for the link exception: IllegalArgumentException - if the parameter was null exception: Exception - if the save operation could not be carried out |
setArguments | public void setArguments(String arguments)(Code) | | Sets the command line arguments that will be passed to the target when the link is activated.
Parameters: arguments - the command line arguments See Also: ShellLink.getArguments |
setDescription | public void setDescription(String description)(Code) | | Sets the description string that is used to identify the link in a menu or on the desktop.
Parameters: description - the descriptiojn string See Also: ShellLink.getDescription |
setHotkey | public void setHotkey(int hotkey)(Code) | | Sets the hotkey that can be used to activate the link.
Parameters: hotkey - a valid Windows virtual key code. Modifiers (e.g. for alt or shift key) areadded in the upper byte. Note that only the lower 16 bits for tis parameter are used. See Also: ShellLink.getHotkey |
setIconLocation | public void setIconLocation(String path, int index)(Code) | | Sets the location of the icon that is shown for the shortcut on the desktop.
Parameters: path - a fully qualified file name of a file that contains the icon. Parameters: index - the index of the specific icon to use in the file. If there is only one icon inthe file, use an index of 0. See Also: ShellLink.getIconLocation |
setLinkName | public void setLinkName(String name)(Code) | | Sets the name shown in a menu or on the desktop for the link.
Parameters: name - The name that the link should display on a menu or on the desktop. Do not includea file extension. |
setProgramGroup | public void setProgramGroup(String groupName)(Code) | | Sets the name of the program group this ShellLinbk should be placed in.
Parameters: groupName - the name of the program group |
setShowCommand | public void setShowCommand(int show)(Code) | | Sets the show command that is passed to the target application when the link is activated.
The show command determines if the the window will be restored to the previous size,
minimized, maximized or visible at all.
Note:
Using HIDE will cause the target window not to show at all. There is not even
a button on the taskbar. This is a very useful setting when batch files are used to launch a
Java application as it will then appear to run just like any native Windows application.
Note1:
HIDE doesn't work in Win98 and newer systems.
use MINIMIZED (MINNOACTIVE), instead.
Parameters: show - the show command. Valid settings are:
ShellLink.HIDE (deprecated)ShellLink.NORMAL ShellLink.MINNOACTIVE ShellLink.MAXIMIZED
See Also: ShellLink.getShowCommand |
setTargetPath | public void setTargetPath(String path)(Code) | | Sets the absolute path to the shortcut target.
Parameters: path - the fully qualified file name of the target See Also: ShellLink.getTargetPath |
|
|
|