I am trying to use the SystemParametersInfo API to change the
wallpaper from a VBScript run by Windows Script Host locally on the
computer.

This is what I have:

Dim bmpFile
bmpFile = "C:\WINDOWS\WALLPAPR.BMP"
Call SystemParametersInfo(SPI_SETDESKWALLPAPER,0,bmpFile,SPIF_SENDWININICHANGE)


When I run it, Windows Script Host gives me the following error
information:
Script: C:\changeWallpaper.vbs
Line: 3
Char: 1
Error: Type mismatch: 'SystemParametersInfo'
Code: 800A000D
Source: Microsoft VBScript runtime error


Is there something I need to do prior to using SystemParametersInfo to
make the VBScript recognize it as valid?

Re: SystemParametersInfo not working with VBScript? by Torgeir

Torgeir
Mon Feb 09 19:33:28 CST 2004

Midi wrote:

> I am trying to use the SystemParametersInfo API to change the
> wallpaper from a VBScript run by Windows Script Host locally on the
> computer.
>
> This is what I have:
>
> Dim bmpFile
> bmpFile = "C:\WINDOWS\WALLPAPR.BMP"
> Call SystemParametersInfo(SPI_SETDESKWALLPAPER,0,bmpFile,SPIF_SENDWININICHANGE)

Hi

Sorry, you can't call APIs directly from VBScript. Here is another way
to change the wallpaper that should work for Win2k and WinXP:


Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

sWinDir = oFSO.GetSpecialFolder(0)
sWallPaper = sWinDir & "\WALLPAPR.BMP"

' update in registry
oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper

' let the system know about the change
oShell.Run _
"%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", _
1, True




--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page Scripting
Guide: http://www.microsoft.com/technet/scriptcenter