|
|
|
|
@ -8,9 +8,11 @@
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
|
|
import net.java.sip.communicator.util.*;
|
|
|
|
|
|
|
|
|
|
import com.sun.jna.*;
|
|
|
|
|
import com.sun.jna.platform.win32.*;
|
|
|
|
|
import com.sun.jna.win32.*;
|
|
|
|
|
|
|
|
|
|
import net.java.sip.communicator.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Take care of application auto startup. Reading and writing the registry.
|
|
|
|
|
@ -31,6 +33,19 @@ public class WindowsStartup
|
|
|
|
|
private static String REGISTRY_STARTUP_KEY =
|
|
|
|
|
"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process Status API. Used to obtain current running executable name.
|
|
|
|
|
*/
|
|
|
|
|
public interface PSAPI extends StdCallLibrary
|
|
|
|
|
{
|
|
|
|
|
PSAPI INSTANCE = (PSAPI)Native.loadLibrary("psapi", PSAPI.class);
|
|
|
|
|
int GetModuleFileNameExA (
|
|
|
|
|
WinNT.HANDLE process,
|
|
|
|
|
Pointer hModule,
|
|
|
|
|
byte[] lpString,
|
|
|
|
|
int nMaxCount);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks whether startup is enabled.
|
|
|
|
|
* @param appName the application name.
|
|
|
|
|
@ -44,6 +59,21 @@ public static boolean isStartupEnabled(String appName)
|
|
|
|
|
appName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the currently running process executable name with path.
|
|
|
|
|
* @return the currently running process executable name with path.
|
|
|
|
|
*/
|
|
|
|
|
public static String getModuleFilename()
|
|
|
|
|
{
|
|
|
|
|
byte[] exePathName = new byte[512];
|
|
|
|
|
|
|
|
|
|
WinNT.HANDLE process = Kernel32.INSTANCE.GetCurrentProcess();
|
|
|
|
|
|
|
|
|
|
int result = PSAPI.INSTANCE.GetModuleFileNameExA(
|
|
|
|
|
process, new Pointer(0), exePathName, exePathName.length);
|
|
|
|
|
return Native.toString(exePathName).substring(0, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates or deletes registry key for application autostart.
|
|
|
|
|
*
|
|
|
|
|
@ -59,11 +89,32 @@ public static void setAutostart(String appName,
|
|
|
|
|
{
|
|
|
|
|
if(isAutoStart)
|
|
|
|
|
{
|
|
|
|
|
String executableFileName = null;
|
|
|
|
|
String filePath = getModuleFilename();
|
|
|
|
|
|
|
|
|
|
if(filePath != null && filePath.length() > 0)
|
|
|
|
|
{
|
|
|
|
|
int ix = filePath.lastIndexOf(File.separatorChar);
|
|
|
|
|
|
|
|
|
|
if(ix > 0)
|
|
|
|
|
executableFileName = filePath.substring(ix + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(executableFileName == null)
|
|
|
|
|
{
|
|
|
|
|
logger.warn("Missing information for process, " +
|
|
|
|
|
"shortcut will be created any way using defaults.");
|
|
|
|
|
// if missing we will use application name
|
|
|
|
|
// removing spaces,_,-
|
|
|
|
|
executableFileName = appName.replaceAll(" ", "")
|
|
|
|
|
.replaceAll("_", "").replaceAll("-","") + ".exe";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Advapi32Util.registrySetStringValue(
|
|
|
|
|
WinReg.HKEY_CURRENT_USER,
|
|
|
|
|
REGISTRY_STARTUP_KEY,
|
|
|
|
|
appName,
|
|
|
|
|
workingDirectory + File.separator + "run.exe");
|
|
|
|
|
workingDirectory + File.separator + executableFileName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|