I have this batch that makes a scheduled task calling to a powershell script and i cant make it run in windows 8. It works perfectly on windows 7 but when i use it in windows 8 it keep stuck. My problem is that the task doesn´t start, but it´s created and scheduled. When i start the powershell script without scheduling it works perfectly.


@copy /y wall.jpg %APPDATA%
@copy /y cuenta.ps1 %APPDATA%
schtasks /create /sc minute /mo 1 /tn wallpaper /tr "powershell -ExecutionPolicy ByPass -File %appdata%\cuenta.ps1"

Powershell :

Add-Type @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Wallpaper
   public enum Style : int
       Tile, Center, Stretch, NoChange
   public class Setter {
      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, Wallpaper.Style style ) {
         SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
         RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
         switch( style )
            case Style.Stretch :
               key.SetValue(@"WallpaperStyle", "2") ; 
               key.SetValue(@"TileWallpaper", "0") ;
            case Style.Center :
               key.SetValue(@"WallpaperStyle", "1") ; 
               key.SetValue(@"TileWallpaper", "0") ; 
            case Style.Tile :
               key.SetValue(@"WallpaperStyle", "1") ; 
               key.SetValue(@"TileWallpaper", "1") ;
            case Style.NoChange :

[Wallpaper.Setter]::SetWallpaper( '%appdata%\wall.jpg', 0 )

Basically im calling to a ps1 which changes the wallpaper every x minutes. Did anyone solved a problem like this?

  • Does event viewer or task scheduler screen show anything as to why it didn't start? I'm not sure about powershell, but since it's built on .NET what happens if you wrap it in a Try Catch block so you can publish the exception (if there is one)? – Dave Sep 5 '14 at 14:34
  • ok, im goint to try – Pablo Nodar Campos Sep 5 '14 at 14:37
  • You'll need to do something in the catch to log it in some manner. – Dave Sep 5 '14 at 14:45
  • @Dave Well i dont know if im doing good the try catch but it doesn´t report anthing, it works perfectly when i do it directly without scheduling. Im doing like this: try { [Wallpaper.Setter]::SetWallpaper( '%appdata%\wall.jpg', 0 ) } catch [System.Net.WebException],[System.IO.IOException]{} i dont know how to do it properly – Pablo Nodar Campos Sep 5 '14 at 14:48
  • Of course in win8 this really isn't needed, there is a property to change the wallpaper ever X minutes built in to win8. – Tyson Sep 5 '14 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.