|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.izforge.izpack.util.os.ShellLink
public class ShellLink
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
| Field Summary | |
|---|---|
static int |
ALL_USERS
ALL_USERS = 1; the constant to use for selecting the all users. |
static int |
CURRENT_USER
CURRENT_USER = 0; the constant to use for selecting the current user. |
static int |
DESKTOP
This type of shortcut shows on the desktop |
static int |
HIDE
Hide the window when starting. |
static int |
MAXIMIZED
Show the window maximized when starting. |
static int |
MINIMIZED
Show the window minimized when starting. |
static int |
MINNOACTIVE
Show the window minimized when starting. |
static int |
NORMAL
Show the window 'normal' when starting. |
static int |
PROGRAM_MENU
This type of shortcut shows in the program menu |
static int |
START_MENU
This type of shortcut shows in the start menu |
static int |
STARTUP
This type of shortcut is executed at OS launch time |
| Constructor Summary | |
|---|---|
ShellLink(int linkType,
int userType,
String group,
String name,
Librarian librarian)
Creates an instance of ShellLink from an existing shell link on disk. |
|
ShellLink(int type,
String name,
Librarian librarian)
Creates an instance of ShellLink of a specific type. |
|
ShellLink(String name,
int userType,
Librarian librarian)
Creates an instance of ShellLink from an existing shell link on disk. |
|
| Method Summary | |
|---|---|
protected void |
finalize()
Destructor, releases COM and frees native resources. |
void |
freeLibrary(String name)
This method is used to free the library at the end of progam execution. |
String |
getallUsersLinkPath()
Returns the path for allusersLink |
String |
getArguments()
Returns the command line that the link passes to the target. |
String |
getcurrentUserLinkPath()
Returns the path for currentusersLink |
String |
getDescription()
Returns the description for the link. |
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. |
String |
getFileName()
Returns the fully qualified file name under which the link is saved on disk. |
int |
getHotkey()
Retruns the hotkey that can be used to activate the link. |
int |
getIconIndex()
Returns the index of the icon with the icon or resource file |
String |
getIconLocation()
Returns the path and file name of the file that contains the icon that is associated with the link. |
String |
getLinkName()
Returns the name shown in a menu or on the desktop for the link. |
String |
getLinkPath(int userType)
Returns the path where the links of the selected type are stroed. |
int |
getLinkType()
Returns the user type for the link. |
boolean |
getRunAsAdministrator()
Determines if the shortcut target should be run with administrator privileges. |
int |
getShowCommand()
Returns the initial condition of the target window (HIDE, NORMAL, MINIMIZED, MAXIMIZED). |
String |
getTargetPath()
Retruns the absolute path of the link target |
int |
getUserType()
Returns the (ShellLink) user type for the link. |
String |
getWorkingDirectory()
Retruns the working deirectory for the link target. |
protected void |
moveFileTo(File srcFileObj,
File destFileObj)
Moves a file to a given destination. |
void |
save()
Saves this link. |
void |
save(String name)
Saves this link to any desired location. |
void |
setArguments(String arguments)
Sets the command line arguments that will be passed to the target when the link is activated. |
void |
setDescription(String description)
Sets the description string that is used to identify the link in a menu or on the desktop. |
void |
setHotkey(int hotkey)
Sets the hotkey that can be used to activate the link. |
void |
setIconLocation(String path,
int index)
Sets the location of the icon that is shown for the shortcut on the desktop. |
void |
setLinkName(String name)
Sets the name shown in a menu or on the desktop for the link. |
void |
setLinkType(int type)
Sets the type of link |
void |
setProgramGroup(String groupName)
Sets the name of the program group this ShellLinbk should be placed in. |
void |
setRunAsAdministrator(boolean runAsAdministrator)
Determines if the shortcut target should be run with administrator privileges. |
void |
setShowCommand(int show)
Sets the show command that is passed to the target application when the link is activated. |
void |
setTargetPath(String path)
Sets the absolute path to the shortcut target. |
void |
setUserType(int type)
Sets the (ShellLink) user type for link |
void |
setWorkingDirectory(String dir)
Sets the working directory for the link target. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int HIDE
public static final int NORMAL
public static final int MINIMIZED
Newer IShellLink only allows Normal, MinNoActive, Maximized.
public static final int MAXIMIZED
public static final int MINNOACTIVE
public static final int DESKTOP
public static final int PROGRAM_MENU
public static final int START_MENU
public static final int STARTUP
public static final int CURRENT_USER
public static final int ALL_USERS
| Constructor Detail |
|---|
public ShellLink(int type,
String name,
Librarian librarian)
throws Exception
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.
type - The type of link desired. The following values can be set:ShellLink.DESKTOP
ShellLink.PROGRAM_MENU
ShellLink.START_MENU
ShellLink.STARTUP
name - The name that the link should display on a menu or on the desktop. Do not include
a file extension.librarian - the librarian
IllegalArgumentException - if any of the call parameters are incorrect, or if no
linkPaths are returned.
Exception - if problems are encountered in initializing the native interface
public ShellLink(String name,
int userType,
Librarian librarian)
throws Exception
ShellLink from an existing shell link on disk.
name - the file name of the link. May be fully qualified or relativeuserType - the type of user for the link path.librarian - the librarian
IllegalArgumentException - if the name was null
Exception - if problems are encountered in reading the fileCURRENT_USER,
ALL_USERS
public ShellLink(int linkType,
int userType,
String group,
String name,
Librarian librarian)
throws Exception
ShellLink from an existing shell link on disk.
linkType - the type of link, one of the following values: ShellLink.DESKTOP
ShellLink.PROGRAM_MENU
ShellLink.START_MENU
ShellLink.STARTUP
userType - the type of user for the link path.group - The program group (directory) of this link. If the link is not part of a program
group, pass an empty string or null for this parameter. (...\\Desktop\\group).name - The file name of this link. Do not include a file extension.librarian - the librarian
IllegalArgumentException - if any of the call parameters are incorrect
Exception - if problems are encountered in initializing the native interfaceCURRENT_USER,
ALL_USERS| Method Detail |
|---|
protected void finalize()
throws Throwable
finalize in class ObjectThrowablepublic void freeLibrary(String name)
freeLibrary in interface NativeLibraryClientname - the name of the library to free. Use only the name and extension but not the
path.NativeLibraryClient.freeLibrary(java.lang.String)public void setProgramGroup(String groupName)
groupName - the name of the program grouppublic void setArguments(String arguments)
arguments - the command line argumentsgetArguments()public void setDescription(String description)
description - the descriptiojn stringgetDescription()public void setHotkey(int hotkey)
hotkey - a valid Windows virtual key code. Modifiers (e.g. for alt or shift key) are
added in the upper byte. Note that only the lower 16 bits for tis parameter are used.getHotkey()
public void setIconLocation(String path,
int index)
path - a fully qualified file name of a file that contains the icon.index - the index of the specific icon to use in the file. If there is only one icon in
the file, use an index of 0.getIconLocation()public void setTargetPath(String path)
path - the fully qualified file name of the targetgetTargetPath()public void setShowCommand(int show)
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.HIDE doesn't work in Win98 and newer systems.
show - the show command. Valid settings are: ShellLink.HIDE (deprecated)
ShellLink.NORMAL
ShellLink.MINNOACTIVE
ShellLink.MAXIMIZED
getShowCommand()public void setWorkingDirectory(String dir)
dir - the working directorygetWorkingDirectory()public void setLinkName(String name)
name - The name that the link should display on a menu or on the desktop. Do not include
a file extension.
public void setLinkType(int type)
throws IllegalArgumentException,
UnsupportedEncodingException
type - The type of link desired. The following values can be set:IllegalArgumentException - if an an invalid type is passed
UnsupportedEncodingExceptionpublic int getLinkType()
setLinkType(int)
public void setUserType(int type)
throws IllegalArgumentException
type - the type of user for the link.
IllegalArgumentException - if an an invalid type is passedCURRENT_USER,
ALL_USERSpublic int getUserType()
CURRENT_USER or
ALL_USERS
setUserType(int)public String getLinkPath(int userType)
userType - the type of user for the link path. One of CURRENT_USER or
ALL_USERS
public String getArguments()
setArguments(java.lang.String)public String getDescription()
setDescription(java.lang.String)public int getHotkey()
setHotkey(int)public String getIconLocation()
setIconLocation(java.lang.String, int)public int getIconIndex()
setIconLocation(java.lang.String, int)public String getTargetPath()
setTargetPath(java.lang.String)public int getShowCommand()
setShowCommand(int)public String getWorkingDirectory()
setWorkingDirectory(java.lang.String)public String getFileName()
public String getDirectoryCreated()
null
if no save operation was carried out or there was no need to create a directory during the
previous save operation.
null if no
save operation was carried out or there was no need to create a directory during the previous
save operation.public String getLinkName()
public String getcurrentUserLinkPath()
public String getallUsersLinkPath()
public void save()
throws Exception
Exception - if problems are encounteredpublic void setRunAsAdministrator(boolean runAsAdministrator)
runAsAdministrator - if true, run the target with administrator privileges.public boolean getRunAsAdministrator()
true, if the target will run with administrator privileges
public void save(String name)
throws Exception
name - the fully qualified file name for the link
IllegalArgumentException - if the parameter was null
Exception - if the save operation could not be carried out
protected void moveFileTo(File srcFileObj,
File destFileObj)
srcFileObj - source file to be moved.destFileObj - destination file object.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||