Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add Windows Application Recovery and Restart API #1293

Open
ebourg opened this issue Dec 26, 2020 · 5 comments
Open

Please add Windows Application Recovery and Restart API #1293

ebourg opened this issue Dec 26, 2020 · 5 comments

Comments

@ebourg
Copy link
Contributor

ebourg commented Dec 26, 2020

Would it be possible to add the Windows Application Recovery and Restart API functions to WinBase.java please? Especially the RegisterApplicationRestart function which can be used to ensure an application is automatically restarted when the system restarts after an update.

@dbwiddis
Copy link
Contributor

Hi @ebourg. JNA is a user-supported project, so it's unlikely this will be done unless you do it, or wait for another user who needs these mappings.

These are straightforward mappings you could easily add. See the example in the FAQ here. Feel free to ask for help on the jna-users mailing list.

@matthiasblaesing
Copy link
Member

matthiasblaesing commented Dec 28, 2020

@ebourg I had a look at this and the first functions can be found here: #1294

While the unittest demonstrates, that the functions are correctly run, I failed to use it really - this was not restartet:

public class Main {
    public static void main(String[] args) {
        HRESULT hres = Kernel32.INSTANCE.RegisterApplicationRestart(Native.toCharArray("-jar c:\\temp\\restarttest.jar restart"), 0);
        COMUtils.checkRC(hres);
        System.out.println(Kernel32Util.QueryFullProcessImageName(Kernel32.INSTANCE.GetCurrentProcess(), 0));
        Native.setProtected(false);
        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame("Dummy Window");
            frame.setSize(800, 600);
            JLabel label = new JLabel(Arrays.toString(args));
            JButton button = new JButton("Kill");
            button.addActionListener((ae) -> {
                new Pointer(0).getByteArray(0, 1024);
            });
            frame.add(label);
            frame.add(button);
            frame.setVisible(true);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        });
    }
}

So it would be nice to get a pointer into the right direction.

@ebourg
Copy link
Contributor Author

ebourg commented Dec 28, 2020

Thank you, I've started implementing the 3 restart functions too, and I'm trying to validate this, either by crashing the JVM (not that easy!) or by updating the system.

@matthiasblaesing
Copy link
Member

Indeed the JVM prevents windows crash handling to kick in. Here is a sample that worked for me:

https://github.com/matthiasblaesing/JNA-Demos/tree/master/ApplicationRestart

@matthiasblaesing
Copy link
Member

For anyone looking into this - the first bindings were merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants