“reg add”似乎在 .BAT 文件中有时不起作用
Posted
技术标签:
【中文标题】“reg add”似乎在 .BAT 文件中有时不起作用【英文标题】:"reg add" Just doesn't seem to work sometime in .BAT files 【发布时间】:2021-11-16 22:07:36 【问题描述】:我正在编写一个 .BAT 脚本,它会不断更新注册表以制作一种动画壁纸。我将 gif 图像拆分为 .bmp 图像,然后运行它。这是我的代码:
:funny
FOR /L %%A IN (1,1,30) DO (
ECHO %%A
reg add "HKCU\control panel\desktop" /v wallpaper /t REG_SZ /d "C:\c" /f
reg add "HKCU\control panel\desktop" /v wallpaper /t REG_SZ /d "C:\Users\User\Desktop\Test\idk\images\frames\troll\frame_%%A_delay-0.05s.bmp" /f
reg delete "HKCU\Software\Microsoft\Internet Explorer\Desktop\General" /v WallpaperStyle /f
reg add "HKCU\control panel\desktop" /v WallpaperStyle /t REG_SZ /d 2 /f
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
)
goto funny
由于某种原因,它有时只能工作,工作一秒钟,停止,当我将鼠标悬停在某物上时开始然后再次停止.. 有什么提示吗?(顺便说一下,我没有管理员权限)
【问题讨论】:
constantly updates
不是真的,一秒钟之内越快越现实,太快了。桌面背景图片显示功能不是为快速更改和更新而设计的,即背景图像显示功能是为显示图像而不是动画、视频等而设计的。为什么不使用多媒体查看器显示动画?
模拟现实世界以便更好地理解。你买了一辆便宜的汽车,然后想着开着它比声音还快是多么有趣。因此,您从某个地方获得带有油箱的喷气发动机,将所有东西都放入汽车的后备箱(或多或少),在汽车方向盘后面进行并点燃涡轮机。你认为会发生什么?我怀疑你的车能达到 1 马赫。但是其他一些观看你尝试的人可能会很有趣。
【参考方案1】:
想通了。我只是没有足够快地更新屏幕。我现在使用 C# 更新屏幕。
write-host "hi, starting"
$imgPath=$desktopImage
$code = @'
using System.Runtime.InteropServices;
namespace Win32
public class Wallpaper
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern int SystemParametersInfo (int uAction , int uParam , string lpvParam , int fuWinIni) ;
public static void SetWallpaper(string thePath)
SystemParametersInfo(20,0,thePath,3);
'@
add-type $code
#Apply the Change on the system
for ($num = 0; $num -lt 60 ; $num++)
[Win32.Wallpaper]::SetWallpaper("C:\Users\user\Downloads\obama\frame_" + $num + "_delay-0.04s.jpg")
if ($num -ge 59)
$num = 0;
# Start-Sleep -Seconds 0.3
感谢@Mofi 的类比,但是当你可以拥有spinning obama sphere? 时谁需要优化
【讨论】:
(开玩笑,我明白了。我在学校电脑上,没有其他选择。)以上是关于“reg add”似乎在 .BAT 文件中有时不起作用的主要内容,如果未能解决你的问题,请参考以下文章
在 .bat 文件中使用 Python 导入 pandas 时不起作用
“npm config set registry https://registry.npmjs.org/”在 Windows bat 文件中不起作用
.bat 文件不起作用 |运行 .bat 文件时显示无效语法 | Python 3.4.0