public class WindowsUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
WindowsUtils.RegKeyValue |
Modifier and Type | Field and Description |
---|---|
private static java.util.Properties |
env |
private static java.util.logging.Logger |
LOG |
private static java.lang.String |
reg |
static java.lang.Boolean |
regVersion1 |
private static java.lang.String |
taskkill |
private static boolean |
THIS_IS_WINDOWS |
private static java.io.File |
wbem |
private static java.lang.String |
wmic |
Constructor and Description |
---|
WindowsUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
deleteRegistryValue(java.lang.String key) |
static java.lang.Class<?> |
discoverRegistryKeyType(java.lang.String key) |
static boolean |
doesRegistryValueExist(java.lang.String key) |
private static java.lang.String |
executeCommand(java.lang.String commandName,
java.lang.String... args) |
static java.lang.String |
findReg()
Finds reg.exe
|
static java.io.File |
findSystemRoot()
Finds the system root directory, e.g.
|
static java.lang.String |
findTaskKill()
Finds taskkill.exe
|
static java.io.File |
findWBEM()
Finds the WBEM directory in the systemRoot directory
|
static java.lang.String |
findWMIC()
Finds WMIC.exe
|
static java.lang.String |
getEnvVarIgnoreCase(java.lang.String var) |
private static java.lang.String |
getEnvVarPath(java.lang.String envVar,
java.lang.String defaultValue) |
private static java.lang.String |
getFullPath(java.lang.String parent,
java.lang.String child) |
static java.lang.String |
getLocalAppDataPath()
Returns the path to Local AppData.
|
static com.google.common.collect.ImmutableList<java.lang.String> |
getPathsInProgramFiles(java.lang.String childPath) |
static java.lang.String |
getProgramFiles86Path() |
static java.lang.String |
getProgramFilesPath()
Returns the path to the Windows Program Files.
|
static boolean |
isRegExeVersion1() |
static void |
kill(java.lang.String[] cmdarray)
Searches the process list for a process with the specified command line and kills it
|
static void |
killByName(java.lang.String name)
Kill processes by name
|
static void |
killPID(java.lang.String processID)
Kills the specified process ID
|
static java.util.Properties |
loadEnvironment()
Returns the current process environment variables
|
static void |
main(java.lang.String[] args) |
static java.util.Map<java.lang.String,java.lang.String> |
procMap()
Returns a map of process IDs to command lines
|
static boolean |
readBooleanRegistryValue(java.lang.String key) |
static int |
readIntRegistryValue(java.lang.String key) |
static java.lang.String |
readStringRegistryValue(java.lang.String key) |
private static java.lang.String |
runRegQuery(java.lang.String key)
Executes reg.exe to query the registry
|
static boolean |
thisIsWindows()
Returns true if the current OS is MS Windows; false otherwise
|
static void |
traceWith(java.util.logging.Logger log) |
static void |
tryToKillByName(java.lang.String name)
Kill processes by name, log and ignore errors
|
static void |
writeBooleanRegistryValue(java.lang.String key,
boolean data) |
static void |
writeIntRegistryValue(java.lang.String key,
int data) |
static void |
writeStringRegistryValue(java.lang.String key,
java.lang.String data) |
public static java.lang.Boolean regVersion1
private static java.util.logging.Logger LOG
private static final boolean THIS_IS_WINDOWS
private static java.lang.String wmic
private static java.io.File wbem
private static java.lang.String taskkill
private static java.lang.String reg
private static java.util.Properties env
public static void main(java.lang.String[] args) throws java.lang.Exception
args
- command line argumentsjava.lang.Exception
- possible IO exceptionpublic static void traceWith(java.util.logging.Logger log)
public static void killByName(java.lang.String name)
name
- name of the process to killpublic static void tryToKillByName(java.lang.String name)
name
- name of the process to killpublic static void kill(java.lang.String[] cmdarray) throws java.lang.Exception
cmdarray
- the array of command line argumentsjava.lang.Exception
- if something goes wrong while reading the process list or searching for your
command linepublic static void killPID(java.lang.String processID)
processID
- PID to killpublic static java.util.Map<java.lang.String,java.lang.String> procMap() throws java.lang.Exception
java.lang.Exception
- - if something goes wrong while reading the process listpublic static java.util.Properties loadEnvironment()
public static java.lang.String getProgramFilesPath()
public static java.lang.String getProgramFiles86Path()
private static java.lang.String getEnvVarPath(java.lang.String envVar, java.lang.String defaultValue)
public static com.google.common.collect.ImmutableList<java.lang.String> getPathsInProgramFiles(java.lang.String childPath)
private static java.lang.String getFullPath(java.lang.String parent, java.lang.String child)
public static java.lang.String getLocalAppDataPath()
public static java.lang.String getEnvVarIgnoreCase(java.lang.String var)
public static java.io.File findSystemRoot()
public static java.lang.String findWMIC()
public static java.io.File findWBEM()
null
if it couldn't be foundpublic static java.lang.String findTaskKill()
public static java.lang.String findReg()
public static boolean isRegExeVersion1()
public static java.lang.Class<?> discoverRegistryKeyType(java.lang.String key)
public static java.lang.String readStringRegistryValue(java.lang.String key)
public static int readIntRegistryValue(java.lang.String key)
public static boolean readBooleanRegistryValue(java.lang.String key)
public static boolean doesRegistryValueExist(java.lang.String key)
public static void writeStringRegistryValue(java.lang.String key, java.lang.String data) throws WindowsRegistryException
WindowsRegistryException
private static java.lang.String executeCommand(java.lang.String commandName, java.lang.String... args)
public static void writeIntRegistryValue(java.lang.String key, int data)
public static void writeBooleanRegistryValue(java.lang.String key, boolean data)
public static void deleteRegistryValue(java.lang.String key)
private static java.lang.String runRegQuery(java.lang.String key)
public static boolean thisIsWindows()