Package com.install4j.api.windows
Class WinEnvVars
java.lang.Object
com.install4j.api.windows.WinEnvVars
Collection of static methods to get and modify environment variables on Windows.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendToPath(String value) Appends one or more directories to the PATH environment variable.static voidappendToUserPath(String value) Appends one or more directories to the user-specific PATH environment variable.static Propertiesgetenv()Returns all environment variables.static StringReturns a single environment variable.static StringgetFromRegistry(String key, boolean userSpecific) Return an environment variable as set in the Windows registry.static voidprependToPath(String value) Prepends one or more directories to the PATH environment variable.static voidprependToUserPath(String value) Prepends one or more directories to the user-specific PATH environment variable.static voidSets a global environment variable.static voidsetUserSpecific(String key, String value) Sets a user-specific environment variable.
-
Constructor Details
-
WinEnvVars
public WinEnvVars()
-
-
Method Details
-
set
Sets a global environment variable. Needs Administrator rights.- Parameters:
key- the name of the environment variablevalue- the value of the environment variable- Throws:
IOException- if the environment variable could not be set
-
setUserSpecific
Sets a user-specific environment variable.- Parameters:
key- the name of the environment variablevalue- the value of the environment variable- Throws:
IOException- if the environment variable could not be set
-
getenv
Returns a single environment variable.- Parameters:
key- the name of the environment variable. Case does not matter.- Returns:
- the value of the environment variable or
nullif not defined
-
getenv
Returns all environment variables.- Returns:
- a property map with all environment variables and its values
-
getFromRegistry
Return an environment variable as set in the Windows registry. The user-specific setting may be different from the value returned ingetenv(). For example, thePATHenvironment variable is modified by the install4j launcher and is not equal to the system setting. In addition, the value returned forPATHwill have no variable substitutions performed.- Parameters:
userSpecific- Iftruethe user-specific variant should be retrieved. Otherwise, the global setting will be returned.- Returns:
- the value of the environment variable or
nullif not defined - Throws:
IOException- if the environment variable could not be retrieved
-
appendToPath
Appends one or more directories to the PATH environment variable. Needs Administrator rights.- Parameters:
value- the value to be appended to the path- Throws:
IOException- if the environment variable could not be set
-
prependToPath
Prepends one or more directories to the PATH environment variable. Needs Administrator rights.- Parameters:
value- the value to be appended to the path- Throws:
IOException- if the environment variable could not be set
-
appendToUserPath
Appends one or more directories to the user-specific PATH environment variable.- Parameters:
value- the value to be appended to the path- Throws:
IOException- if the environment variable could not be set- See Also:
-
prependToUserPath
Prepends one or more directories to the user-specific PATH environment variable.- Parameters:
value- the value to be appended to the path- Throws:
IOException- if the environment variable could not be set- See Also:
-