碰到一个需要修改桌面背景的需求,将解决方案分享,下面是通过vb写的(可以将如下代码放入一个html页面执行即可)
<script language=vbscript> document.write("11111") Sub changeWallPaper set ws = createobject("wscript.shell") document.write("2222") ws.regwrite "HKCU\Control Panel\Desktop\wallpaper","d:\deskTest\4.jpg","REG_SZ" ws.run "RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters" ws.run "D:\deskTest\refresh.bat" document.write("3333") End Sub changeWallPaper document.write("4444") </script>
<img id=bgimg border="0" src="d:\deskTest\4.jpg"> <button id="btn" value="改变桌面背景" onclick="changeWallPaper">
D:\deskTest\refresh.bat这个文件是用来刷新桌面的批处理文件,由于修改注册表后不刷新桌面没法及时显示更新桌面图片,代码如下:
@echo off if exist D:\deskTest\bak.jpg (del/q D:\deskTest\bak.jpg) if exist D:\deskTest\7.bmp (rename D:\deskTest\7.bmp bak.jpg) RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ASSOC .AV=AVFILE>NUL 2>NUL