Skip to main content

Posts

Showing posts with the label Desktop

Java API for Print, Browse, Shutdown from Simple Java Program on Windows OS

I have been working on a app which takes the commands from database and execute on a windows machine (XP,Vista & 7). Commands include browse(given a link), print (given a location) and shutdown the machine. I have utilized the Java Desktop API for solving this problem i have used  this post . All you need is following three snippets: 1. Get Desktop instance: Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); 2. For Browse/Open file:          File file = new File("url");          desktop.open(file); 3. For Print file:            File file = new File("url");          desktop.print(file); 3. For Shutdown file:  Process child = Runtime.getRuntime().exec("shutdown -s");