随机壁纸脚本

我创建了这个VBScript来随机化我的墙纸。 它还将子文件夹用于顺序图像。 它从指定的父文件夹中的文件或文件夹之一中随机选择。 如果选择文件,则等待10分钟以进行更改。 如果选择文件夹,它将每5秒按顺序浏览图片。

要使用它,请将代码复制并保存到.vbs文件,如果希望其自动启动,请将其放在启动文件夹中。


Option Explicit
Dim WshShell, oFolder, intNumber, strValue, i, oFile, strFolder, intFolders, intFiles, serialIndex, sleepTime, serialFolder 
strFolder = "C:\Documents and Settings\username\My Documents\My Pictures\Wallpapers\"
Set WshShell = WScript.CreateObject("Wscript.Shell")
Set oFolder = WScript.CreateObject("Scripting.FileSystemObject").GetFolder(strFolder)
serialIndex = 0 
Do While True
    Do While True
        If serialIndex > 0 Then
            serialIndex = serialIndex + 1
            If serialIndex > serialFolder.Files.Count Then serialIndex = 0
        End If 
        If serialIndex > 0 Then
            i = 0
            For Each oFile In serialFolder.Files    
                i = i + 1
                If i = serialIndex Then Exit For                                                            
            Next
        Else
            intFiles = oFolder.Files.Count
            intFolders = oFolder.Subfolders.Count
            Randomize
            intNumber = Int((intFiles + intFolders) * Rnd) + 1 
            If intNumber > intFiles Then
                sleepTime = 5000
                serialIndex = 1
                i = intFiles
                For Each serialFolder In oFolder.Subfolders     
                    i = i + 1
                    If i = intNumber Then Exit For                                                            
                Next 
                i = 0
                For Each oFile In serialFolder.Files     
                    i = i + 1
                    If i = serialIndex Then Exit For                                                         
                Next
            Else
                sleepTime = 600000
                i = 0
                For Each oFile In oFolder.Files     
                    i = i + 1
                    If i = intNumber Then Exit For                                                          
                Next
            End If
        End If 
        If oFile.Path <> strValue Then
            strValue = oFile.Path
            Exit Do
        End If
    Loop
    Set oFile = Nothing 
    WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", strValue
    WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters", 1, False
    WScript.Sleep sleepTime
Loop 
Set WshShell = Nothing
Set oFolder = Nothing 

From: https://bytes.com/topic/windows/insights/905645-random-wallpaper-script

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值