在 Windows 10 中更改墙纸的脚本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33551934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Script to change wallpaper in windows 10?
提问by user1342164
I am trying to get a script to work that will change the default wallpaper for windows 10 because I will be deploying Win10 to all clients. When I run the batch code below, it is not changing the default wall paper. I see that the img0 file is in the correct directory C:\Windows\Web\Wallpaper\Windows but it is not changing the background. The code below is what I am using. I do get some access denied errors when trying to del C:\Windows\Web\4K\Wallpaper\Windows\img0_1366x768.jpg Access is denied.
我正在尝试使用一个脚本来更改 Windows 10 的默认墙纸,因为我将向所有客户端部署 Win10。当我运行下面的批处理代码时,它不会更改默认墙纸。我看到 img0 文件位于正确的目录 C:\Windows\Web\Wallpaper\Windows 中,但它没有改变背景。下面的代码是我正在使用的。尝试删除 C:\Windows\Web\4K\Wallpaper\Windows\img0_1366x768.jpg 访问被拒绝时,我确实遇到了一些访问被拒绝的错误。
takeown /f c:\windows\WEB\wallpaper\Windows\img0.jpg
takeown /f C:\Windows\WebK\Wallpaper\Windows\*.*
icacls c:\windows\WEB\wallpaper\Windows\img0.jpg /Grant System:(F)
icacls C:\Windows\WebK\Wallpaper\Windows\*.* /Grant System:(F)
del c:\windows\WEB\wallpaper\Windows\img0.jpg
del /q C:\Windows\WebK\Wallpaper\Windows\*.*
copy %~dp0img0.jpg c:\windows\WEB\wallpaper\Windows\img0.jpg
copy %~dp04k\*.* C:\Windows\WebK\Wallpaper\Windows
Any ideas what I am doing wrong? TIA
任何想法我做错了什么?TIA
回答by Michael Palermo
Use Powershell to change the wallpaper. First, create a function like this:
使用 Powershell 更改墙纸。首先,创建一个这样的函数:
Function Set-WallPaper($Value)
{
Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $value
rundll32.exe user32.dll, UpdatePerUserSystemParameters
}
Now call the function:
现在调用函数:
Set-WallPaper -value "path to wallpaper"
回答by Stephen Lee Parker
I know this has already been answered, but if someone wants to do this in a batch file the icacls lines need to use /reset instead of the /grant... something like:
我知道这已经得到了回答,但是如果有人想在批处理文件中执行此操作,则 icacls 行需要使用 /reset 而不是 /grant ... 类似于:
takeown /f c:\windows\WEB\wallpaper\Windows\img0.jpg
icacls c:\windows\WEB\wallpaper\Windows\img0.jpg /reset
copy %~dp0img0.jpg c:\windows\WEB\wallpaper\Windows\img0.jpg
copy %~dp04k\*.* C:\Windows\WebK\Wallpaper\Windows
should work (as long as it is being run by an Administrative account).
应该可以工作(只要它由管理帐户运行)。
回答by Richard Goh
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys("^ ")
WshShell.SendKeys("+{F10}")
WshShell.SendKeys("N")
WshShell.SendKeys("{DOWN}")
WshShell.SendKeys("{DOWN}")
WshShell.SendKeys("{DOWN}")
WshShell.SendKeys("{DOWN}")
WshShell.SendKeys("{DOWN}")
WshShell.SendKeys("{DOWN}")
WshShell.SendKeys("{DOWN}")
WshShell.SendKeys("{DOWN}")
WshShell.SendKeys("{DOWN}")
WshShell.SendKeys("{DOWN}")
WshShell.SendKeys("{ENTER}")