public class ShellLink extends Object implements NativeLibraryClient
ShellLink.cpp
. Modifier and Type | Field and Description |
---|---|
static int |
ALL_USERS
the constant to use for selecting the all users.
|
private String |
allUsersLinkPath
Path to the location where links for all users are stored.
|
private String |
arguments |
static int |
CURRENT_USER
CURRENT_USER = 0; the constant to use for selecting the current user.
|
private String |
currentUserLinkPath
Path to the location where links for the current user are stored.
|
private String |
description |
static int |
DESKTOP
This type of shortcut shows on the desktop
|
private String |
dummyString
there seems to be an error in JNI that causes an access violation if a String that is
accessed from native code borders on another type of variable.
|
private String |
groupName |
static int |
HIDE
Hide the window when starting.
|
private int |
hotkey |
private int |
iconIndex |
private String |
iconPath |
private boolean |
initializeSucceeded |
private static String |
LINK_EXTENSION
the extension that must be used for link files
|
private String |
linkDirectory
Contains the directory where the link file is stored after any save operation that needs to
create that directory.
|
private String |
linkFileName
this is the fully qualified name of the link on disk.
|
private String |
linkName |
private int |
linkType |
private static int |
MAX_SHOW |
private static int |
MAX_TYPE |
static int |
MAXIMIZED
Show the window maximized when starting.
|
private static int |
MIN_SHOW |
private static int |
MIN_TYPE |
static int |
MINIMIZED
Show the window minimized when starting.
|
static int |
MINNOACTIVE
Show the window minimized when starting.
|
private int |
nativeHandle
This handle links us to a specific native instance.
|
static int |
NORMAL
Show the window 'normal' when starting.
|
static int |
PROGRAM_MENU
This type of shortcut shows in the program menu
|
private int |
showCommand |
private static int |
SL_ERROR
Unspecific return if a native call was not successful
|
private static int |
SL_INITIALIZED
Return value from native initialization functions if already initialized
|
private static int |
SL_NO_IPERSIST
Return value from native uninitialization functions if nohandle for the IPersist interface
could be obtained
|
private static int |
SL_NO_SAVE
Return value from native uninitialization functions if the save operation fort the link
failed
|
private static int |
SL_NOT_INITIALIZED
Return value from native uninitialization functions if never initialized
|
private static int |
SL_OK
Returned from native calls if the call was successful
|
private static int |
SL_OUT_OF_HANDLES
Return value from native uninitialization functions if there are no more interface handles
available
|
private static int |
SL_WRONG_DATA_TYPE
Return value if the function called had to deal with unexpected data types.
|
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
|
private String |
targetPath |
private static int |
UNINITIALIZED |
private int |
userType |
private String |
workingDirectory |
Constructor and Description |
---|
ShellLink(int type,
int userType,
String group,
String name)
Creates an instance of
ShellLink from an existing shell link on disk. |
ShellLink(int type,
String name)
Creates an instance of
ShellLink of a specific type. |
ShellLink(String name,
int userType)
Creates an instance of
ShellLink from an existing shell link on disk. |
Modifier and Type | Method and Description |
---|---|
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.
|
private void |
FreeLibrary(String name)
This method is used to free the library at the end of progam execution.
|
private String |
fullLinkName(int userType)
Constructs and returns the fully qualified name for the link file.
|
private String |
fullLinkPath(int userType)
Constructs and returns the full path for the link file.
|
private void |
get()
Gets all members from the native side.
|
String |
getallUsersLinkPath()
Returns the path for allusersLink
|
String |
getArguments()
Returns the command line that the link passes to the target.
|
private int |
GetArguments() |
String |
getcurrentUserLinkPath()
Returns the path for currentusersLink
|
String |
getDescription()
Returns the description for the link.
|
private int |
GetDescription() |
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.
|
private int |
GetFullLinkPath(int usertype,
int linktype) |
int |
getHotkey()
Retruns the hotkey that can be used to activate the link.
|
private int |
GetHotkey() |
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.
|
private int |
GetIconLocation() |
private int |
getInterface() |
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.
|
private int |
GetPath() |
int |
getShowCommand()
Returns the initial condition of the target window (HIDE, NORMAL, MINIMIZED, MAXIMIZED).
|
private int |
GetShowCommand() |
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.
|
private int |
GetWorkingDirectory() |
private void |
initialize()
Initializes COM and gets an instance of the IShellLink interface.
|
private int |
initializeCOM() |
private int |
loadLink(String name) |
private int |
releaseCOM() |
private int |
releaseInterface() |
private int |
Resolve() |
void |
save()
Saves this link.
|
void |
save(String name)
Saves this link to any desired location.
|
private int |
saveLink(String name) |
private void |
set()
Sets all members on the native side.
|
private void |
setAllLinkPaths()
sets currentUsersLinkPath and allUsersLinkPath.
|
private int |
SetArguments() |
void |
setArguments(String arguments)
Sets the command line arguments that will be passed to the target when the link is activated.
|
private int |
SetDescription() |
void |
setDescription(String description)
Sets the description string that is used to identify the link in a menu or on the desktop.
|
private int |
SetHotkey() |
void |
setHotkey(int hotkey)
Sets the hotkey that can be used to activate the link.
|
private int |
SetIconLocation() |
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
|
private int |
SetPath() |
void |
setProgramGroup(String groupName)
Sets the name of the program group this ShellLinbk should be placed in.
|
private int |
SetShowCommand() |
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
|
private int |
SetWorkingDirectory() |
void |
setWorkingDirectory(String dir)
Sets the working directory for the link target.
|
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
private static final int MIN_SHOW
private static final int MAX_SHOW
public static final int DESKTOP
public static final int PROGRAM_MENU
public static final int START_MENU
public static final int STARTUP
private static final int MIN_TYPE
private static final int MAX_TYPE
private static final int SL_OK
private static final int SL_ERROR
private static final int SL_INITIALIZED
private static final int SL_NOT_INITIALIZED
private static final int SL_OUT_OF_HANDLES
private static final int SL_NO_IPERSIST
private static final int SL_NO_SAVE
private static final int SL_WRONG_DATA_TYPE
private static final int UNINITIALIZED
private static final String LINK_EXTENSION
public static final int CURRENT_USER
public static final int ALL_USERS
private int nativeHandle
private String currentUserLinkPath
private String allUsersLinkPath
private String linkFileName
private String linkDirectory
null
.private String description
private String targetPath
private String workingDirectory
private String dummyString
set()
For this reason, the dummy string is placed here. Observed with version:
java version "1.3.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C) Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
private int hotkey
private int iconIndex
private int showCommand
private int linkType
private int userType
private boolean initializeSucceeded
public ShellLink(int type, String name) throws Exception, IllegalArgumentException
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.IllegalArgumentException
- if any of the call parameters are incorrect, or if no
linkPaths are returned.Exception
- if problems are encountered in initializing the native interfacepublic ShellLink(String name, int userType) throws Exception, IllegalArgumentException
ShellLink
from an existing shell link on disk.name
- the fully qualified file name of the link.userType
- the type of user for the link path.IllegalArgumentException
- if the name was nullException
- if problems are encountered in reading the fileCURRENT_USER
,
ALL_USERS
public ShellLink(int type, int userType, String group, String name) throws Exception, IllegalArgumentException
ShellLink
from an existing shell link on disk.type
- 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.IllegalArgumentException
- if any of the call parameters are incorrectException
- if problems are encountered in initializing the native interfaceCURRENT_USER
,
ALL_USERS
private int initializeCOM()
private int releaseCOM()
private int getInterface()
private int releaseInterface()
private int GetArguments()
private int GetDescription()
private int GetHotkey()
private int GetIconLocation()
private int GetPath()
private int GetShowCommand()
private int GetWorkingDirectory()
private int Resolve()
private int SetArguments()
private int SetDescription()
private int SetHotkey()
private int SetIconLocation()
private int SetPath()
private int SetShowCommand()
private int SetWorkingDirectory()
private int GetFullLinkPath(int usertype, int linktype)
private void FreeLibrary(String name)
private void initialize() throws Exception
Exception
- if problems are encounteredprotected void finalize()
public void freeLibrary(String name)
freeLibrary
in interface NativeLibraryClient
name
- the name of the library to free. Use only the name and extension but not the
path.NativeLibraryClient.freeLibrary(java.lang.String)
private String fullLinkPath(int userType)
userType
- the type of user for the link path.CURRENT_USER
,
ALL_USERS
private String fullLinkName(int userType)
userType
- the type of user for the link path.CURRENT_USER
,
ALL_USERS
private void set() throws Exception
Exception
- if any problem is encountered during this operation.private void get() throws Exception
Exception
- if any problem is encountered during this operation.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 passedUnsupportedEncodingException
public 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_USERS
public 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 save(String name) throws Exception
name
- the fully qualified file name for the linkIllegalArgumentException
- if the parameter was nullException
- if the save operation could not be carried outprivate void setAllLinkPaths() throws IllegalArgumentException
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses