I've just started studying Java and wanted to test something. I have Window 10 and using PowerShell I found a script for changing the wallpaper:
$setwallpapersource = @"
using System.Runtime.InteropServices;
public class wallpaper
{
public const int SetDesktopWallpaper = 20;
public const int UpdateIniFile = 0x01;
public const int SendWinIniChange = 0x02;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaper ( string path )
{
SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
}
}
"@
Add-Type -TypeDefinition $setwallpapersource
[wallpaper]::SetWallpaper("C:\Users\Saab\Desktop\Image.jpg")
I saved this .ps1 script and converted it to .exe ("change_wp.exe").
If I double click on the exe file, it will change wallpaper as required.
Then I wanted to see if I could execute the exe file on Java:
import java.io.IOException;
class Change {
public static void main(String args[])
throws IOException
{
Runtime.getRuntime().exec("C:\\Users\\Saab\\Desktop\\change_wp.exe");
}
}
Saved the file as Change.java and put it on my desktop.
Opened cmd, reached the path were the file java is (C:\Users\Saab\Desktop) and executed the 2 below commands:
- javac Change.java (no error displayed)
- java -cp . Change (no error displayed)
It seems all good no? Then I had a look at the wallpaper, which didn't change. :(
Where am I wrong?