Here is the wallpaper changing code you asked for.
There is a problem with the VB translation I did, it has to do
with the api call (I haven't used them in VB.Net till today with this). Maybe you can figure it out. If you do get it working,
repost the working code here so all others can use it.

If all else fails, you can use the C# code, it works fine
on my computer.


VB Code:
  1. Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByRef lpvParam As String, ByVal fuWinIni As Integer) As Integer
  2.  
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Dim myPic As String = "YourPicture.jpg" 'This can be a gif, bmp, or jpg and probably others.
  5.         Dim image As Bitmap = New Bitmap(myPic)
  6.  
  7.         'Might need to change the hard coded path to find the actual windows directory.
  8.         Dim path As String = "C:\Windows\" + System.IO.Path.GetFileNameWithoutExtension(myPic)
  9.  
  10.         'This only works with bitmaps, so if it isn't a bmp file, it needs to be
  11.         'converted to one before we can change the wallpaper.
  12.         Dim ext As System.IO.FileInfo = New System.IO.FileInfo(myPic)
  13.         If ext.Extension.ToUpper <> "BMP" Then
  14.             image.Save(path, System.Drawing.Imaging.ImageFormat.Bmp)
  15.         End If
  16.  
  17.         'Now make the call to change the wallpaper.
  18.         Dim returncode As Integer
  19.         returncode = SystemParametersInfo(20, 0, path, 0)
  20.  
  21.         'Need to set the registry so that you can see the image when you right-click
  22.         'the desktop and choose properties and go to the background tab.
  23.         Dim key As Microsoft.Win32.RegistryKey
  24.         key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Control Panel", True)
  25.         Try
  26.             key = key.OpenSubKey("Desktop", True)
  27.             key.SetValue("Wallpaper", path)
  28.         Catch
  29.             'An error happened when setting the registry setting.
  30.             'Do what you want here.
  31.         End Try
  32.  
  33.  
  34.  
  35.         'C# CODE FOR CHANGING THE WALLPAPER:
  36.         'AUTHOR Brian Russell AKA hellswraith on VBForums.com
  37.         '
  38.         '// This is the API declaration for the call to set the wallpaper.
  39.         '[System.Runtime.InteropServices.DllImportAttribute("user32")]
  40.         'private static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam,
  41.         '   int fuWinIni);
  42.  
  43.         'private void ImageToWallpaper()
  44.         '{
  45.         '   // This only works with bitmaps, so we need to convert the image to
  46.         '   // a bmp file before it will work.  I am saving it in the C:\Windows folder
  47.         '   string myPicPath = "YourPicture.jpg"
  48.         '   Bitmap image = new Bitmap(myPicPath);
  49.         '   string path = @"C:\Windows\" + System.IO.Path.GetFileNameWithoutExtension(myPicPath);
  50.  
  51.         '   image.Save(path, System.Drawing.Imaging.ImageFormat.Bmp);
  52.  
  53.         '   // Now make the call to change the wallpaper.
  54.         '   int returncode;
  55.         '   returncode = SystemParametersInfo(20,0,path,0);
  56.  
  57.         '   // We still need this.  If we don't set the registry key
  58.         '   // you won't see your image you just set in the properties window
  59.         '   // when you right-click the desktop.
  60.         '   RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel", true);
  61.  
  62.         '      Try
  63.         '   {
  64.         '       key = key.OpenSubKey("Desktop", true);
  65.  
  66.         '       key.SetValue("Wallpaper", path);
  67.         '   }
  68.         '      Catch
  69.         '   {
  70.         '       // Something went wrong.
  71.         '       MessageBox.Show("Something went wrong");
  72.         '   }
  73.         '}
  74.     End Sub