Activate the screensaver in Java

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

squareroot
Posts: 548
Joined: Tue Jan 12, 2010 1:04 am UTC
Contact:

Activate the screensaver in Java

Postby squareroot » Sat Sep 11, 2010 9:12 pm UTC

Just for my own amusement, I thought I would try writing a Java application that would start the default screensaver when the mouse is moved to the top-left corner, like on Macs (but this application is going to run on windows). I thought it would be pretty simple: check every, say, 500ms if the mouse is at 0,0 and if the screensaver isn't running, if bother are true, then start it.

I found a way to check if the screensaver is running, with tasklist.exe, checking if there's any process that ends in .scr. But I can't find any way to actually start the screen saver; just executing C:\Windows\System32\SYSINT~1.scr gives me the configuration window, and running it with \s - which the spec at http://support.microsoft.com/kb/182383 says should run the actual screensaver - doesn't work either. Can someone please explain to me how to launch it?
<signature content="" style="tag:html;" overused meta />
Good fucking job Will Yu, you found me - __ -

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Activate the screensaver in Java

Postby headprogrammingczar » Sun Sep 12, 2010 12:37 pm UTC

Make sure all your '/' and '\' are pointing the right way.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

squareroot
Posts: 548
Joined: Tue Jan 12, 2010 1:04 am UTC
Contact:

Re: Activate the screensaver in Java

Postby squareroot » Sun Sep 12, 2010 6:35 pm UTC

With "\c" it does nothing, with "/c" it gives me the configuration window. :? If I could somehow see the command line arguments of the process, then hopefully I could execute the same command. But I can't find any way to see the command line arguments, as I can only do that through process explorer, which I can only access when the screensaver isn't running. >.>
<signature content="" style="tag:html;" overused meta />
Good fucking job Will Yu, you found me - __ -

Axidos
Posts: 167
Joined: Tue Jan 20, 2009 12:02 pm UTC
Location: trapped in a profile factory please send help

Re: Activate the screensaver in Java

Postby Axidos » Mon Sep 13, 2010 2:04 am UTC

squareroot wrote:With "\c" it does nothing, with "/c" it gives me the configuration window. :? If I could somehow see the command line arguments of the process, then hopefully I could execute the same command. But I can't find any way to see the command line arguments, as I can only do that through process explorer, which I can only access when the screensaver isn't running. >.>

Because "\c" and "/c" are completely different commands, because / and \ are completely different characters. "/c" is the command for opening the configuration window whilst "\c" is not a documented command at all so neither of us should be very surprised it does nothing.

User avatar
Bishop
Posts: 21
Joined: Tue Jul 15, 2008 4:11 am UTC
Location: Michigan, United States
Contact:

Re: Activate the screensaver in Java

Postby Bishop » Mon Sep 13, 2010 4:02 am UTC

Looking at the link you posted it seems that if you put "/s" that would resolve your problems. Like the many people above me have said, using "\s" is not the same as "/s".

squareroot
Posts: 548
Joined: Tue Jan 12, 2010 1:04 am UTC
Contact:

Re: Activate the screensaver in Java

Postby squareroot » Mon Sep 13, 2010 10:28 pm UTC

Oops. When I changed the slash, I'd changed it to a c. Grr. X-(

So, the command now works in the command prompt. But when I use Runtime.getRuntime.exec("C:\\Windows\\System32\\SYSINT~1.scr /s"); it throws an IOException and tells me it cannot find the file. Even when I give it an explicit filename for the screensaver ("SysInternalsBluescreen.scr", in my case), it says the file cannot be found. Is there some special thing I have to do first to give file permissions or something?

Or is there just another horribly simple thing I'm somehow missing?? :(

Thank you for your help!
<signature content="" style="tag:html;" overused meta />
Good fucking job Will Yu, you found me - __ -

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: Activate the screensaver in Java

Postby Sc4Freak » Tue Sep 14, 2010 2:27 am UTC

No, that should just work. Writing to places like the Windows directory requires administrative privileges (and a UAC prompt, which is the Windows equivalent of asking for a root password), but you don't need anything special to read/execute.

What version of Windows are you actually using? The fact that you're trying to use an 8.3 filename suggests something like Windows 95 or older.

User avatar
Dropzone
Posts: 405
Joined: Sun Dec 30, 2007 10:12 pm UTC
Location: North Lincs., UK

Re: Activate the screensaver in Java

Postby Dropzone » Tue Sep 14, 2010 5:35 pm UTC

This code works on my machine:

Code: Select all

import java.io.IOException;

public class Screensaver
{
    public static void main(String[] args) throws IOException
    {
        Runtime.getRuntime().exec("C:\\Windows\\System32\\Bubbles.scr /s");
    }
}

There's only one thing I can think of that could be going wrong: if you're running a 32-bit version of Java on a 64-bit version of Windows, all attempts to access System32 will be redirected to the SysWOW64 directory - and if the screensaver only exists in System32, you'll get a FileNotFoundException. If that is what's happening, copying the screensaver to SysWOW64 should fix it - otherwise, I've got no idea what the problem is.

squareroot
Posts: 548
Joined: Tue Jan 12, 2010 1:04 am UTC
Contact:

Re: Activate the screensaver in Java

Postby squareroot » Tue Sep 14, 2010 7:41 pm UTC

Sc4Freak wrote:No, that should just work. Writing to places like the Windows directory requires administrative privileges (and a UAC prompt, which is the Windows equivalent of asking for a root password), but you don't need anything special to read/execute.

What version of Windows are you actually using? The fact that you're trying to use an 8.3 filename suggests something like Windows 95 or older.

The 8.3 filename was just the filename that was being stored in the registry. I don't know why.

Dropzone wrote:This code works on my machine:

Code: Select all

import java.io.IOException;

public class Screensaver
{
    public static void main(String[] args) throws IOException
    {
        Runtime.getRuntime().exec("C:\\Windows\\System32\\Bubbles.scr /s");
    }
}

There's only one thing I can think of that could be going wrong: if you're running a 32-bit version of Java on a 64-bit version of Windows, all attempts to access System32 will be redirected to the SysWOW64 directory - and if the screensaver only exists in System32, you'll get a FileNotFoundException. If that is what's happening, copying the screensaver to SysWOW64 should fix it - otherwise, I've got no idea what the problem is.

^That's it. The screensaver I'm using hadn't had a real installer, I had to copy it to the System32 folder manually. Up until now, I was never aware of the SysWOW64 folder. After copying it into there as well, it works!

Yay!

Thanks everyone! :-D
<signature content="" style="tag:html;" overused meta />
Good fucking job Will Yu, you found me - __ -


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 9 guests