Board logo

标题: [系统相关] 批处理怎么换将一个文件夹内的壁纸轮流更换? [打印本页]

作者: 魅眸    时间: 2024-1-5 11:36     标题: 批处理怎么换将一个文件夹内的壁纸轮流更换?

请教大神,批处理怎么换将一个文件夹内的壁纸轮流更换
作者: Batcher    时间: 2024-1-6 10:16

回复 1# 魅眸


    Win7? Win10? Win11?
作者: czjt1234    时间: 2024-1-7 16:55

本帖最后由 czjt1234 于 2024-1-7 17:02 编辑

vbs
  1. Option Explicit
  2. Dim oWshShell, oFSO, oShell, WallpaperStyle, TileWallpaper, s, i
  3. Const PATH  = "D:\1"    '图片文件夹
  4. Const STYLE = "适应"    '适应 居中 平铺 拉伸 填充
  5. Set oWshShell = CreateObject("WScript.Shell")
  6. Set oFSO      = CreateObject("Scripting.FileSystemObject")
  7. Set oShell    = CreateObject("Shell.Application")
  8. oWshShell.CurrentDirectory = PATH
  9. Select Case STYLE
  10.     Case "适应"
  11.         WallpaperStyle = "6"
  12.         TileWallpaper  = "0"
  13.     Case "居中"
  14.         WallpaperStyle = "0"
  15.         TileWallpaper  = "0"
  16.     Case "平铺"
  17.         WallpaperStyle = "0"
  18.         TileWallpaper  = "1"
  19.     Case "拉伸"
  20.         WallpaperStyle = "2"
  21.         TileWallpaper  = "0"
  22.     Case "填充"
  23.         WallpaperStyle = "10"
  24.         TileWallpaper  = "0"
  25. End Select
  26. s = ""
  27. For Each i In oFSO.GetFolder(oWshShell.CurrentDirectory).Files
  28.     If LCase(Right(i.Name, 4)) = ".jpg" Or LCase(Right(i.Name, 4)) = ".bmp" Then
  29.     s = s & i.Name & "|"
  30.     End If
  31. Next
  32. If s = "" Then Wsh.Quit()
  33. i = Split(Left(s, Len(s) - 1), "|")
  34. Randomize
  35. s = i(Int((UBound(i) + 1) * Rnd()))
  36. oWshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Desktop\WallpaperStyle", WallpaperStyle, "REG_SZ"
  37. oWshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Desktop\TileWallpaper",  TileWallpaper,  "REG_SZ"
  38. For Each i In oShell.NameSpace(oWshShell.CurrentDirectory).ParseName(s).Verbs
  39.     If i.Name = "设置为桌面背景(&B)" Then i.DoIt() : Wsh.Sleep 2000
  40. Next
复制代码

这是随机图片设为桌面背景的vbs
如果 PATH = "." 则表示当前文件夹




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2