Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 不使用regedit更改桌面背景_Windows_Batch File_Vbscript - Fatal编程技术网

Windows 不使用regedit更改桌面背景

Windows 不使用regedit更改桌面背景,windows,batch-file,vbscript,Windows,Batch File,Vbscript,有没有办法在不编辑注册表的情况下更改Windows计算机的桌面背景?由于该程序将在不同的计算机上运行,这可能会影响Usb驱动器号。因此,是否有一个vbs,它将检查驱动器号,并将照片(我需要文件源的驱动器号来复制照片)复制到本地驱动器。有人知道怎么做吗?TIA否,您需要编辑注册表,这是根据图像引用方式的定义进行的 正如上面的评论者所提到的,有一些方法可以绕过这个问题。首先,你可以尝试相对路径而不是绝对路径。在下面的代码中,当然要删除messagebox Set WshShell = CreateO

有没有办法在不编辑注册表的情况下更改Windows计算机的桌面背景?由于该程序将在不同的计算机上运行,这可能会影响Usb驱动器号。因此,是否有一个vbs,它将检查驱动器号,并将照片(我需要文件源的驱动器号来复制照片)复制到本地驱动器。有人知道怎么做吗?TIA

否,您需要编辑注册表,这是根据图像引用方式的定义进行的

正如上面的评论者所提到的,有一些方法可以绕过这个问题。首先,你可以尝试相对路径而不是绝对路径。在下面的代码中,当然要删除messagebox

Set WshShell = CreateObject("WScript.Shell")
msgbox WshShell.CurrentDirectory 'This returns the path of your script
要获得脚本的完整路径,只需使用

msgbox WScript.ScriptFullName
对于奖励积分,我们可以使用

msgbox CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
这将消除对驱动器号或文件夹所在位置的任何担忧。如果您愿意,您可以使用下面的命令来提取驱动器号

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

strPath = objShell.CurrentDirectory
strDrive = objFSO.GetDriveName(strPath)

msgbox strDrive
让脚本复杂化的是,您希望确保在卸下闪存驱动器后桌面图片仍然可用。你有两个选择。第一,你可以把你的照片复制到C:上的一个安全位置。或者,我要做的是在VBS中添加一个侦听器,检查X:drive是否仍然可读。一旦拔掉闪存驱动器的插头,vbs将继续运行,因此它会注意到该驱动器已消失,然后将桌面映像更改回原来的状态

一些psudocode:

Read the reg desktop location
Back it up
write new location
refresh desktop
Call Secondary Script (OR LOOP NOW to watch the drive)

根据脚本的功能,让它调用另一个脚本来检查闪存驱动器,或者只是在主脚本中有一个循环。我会简单地调用另一个脚本,以便您可以自由地执行主脚本中的任何其他操作。如果您还有任何问题,请告诉我

您可以创建powershell脚本文件集\u desktop\u background.ps1

Push-Location
cd HKCU:\
Set-Itemproperty -path 'HKEY_CURRENT_USER\Control Panel\Desktop' -Name 'WallPaper' -value ''
add-type -typedefinition "using System;`n using System.Runtime.InteropServices;`n public class PInvoke { [DllImport(`"user32.dll`")] public static extern bool SetSysColors(int cElements, int[] lpaElements, int[] lpaRgbValues); }"
[PInvoke]::SetSysColors(1, @(1), @(0x663309))
Start-Process "taskkill.exe" -ArgumentList "/F /IM explorer.exe" -Wait -WindowStyle Hidden
Start-Process "explorer.exe" -WindowStyle Hidden
Pop-Location
然后通过

powershell -File C:\desktop_background\set_desktop_background.ps1 -WindowStyle Hidden

Wscript.ScriptFullName
包含vbs文件的全名,因此只需从中获取驱动器号即可。不,不修改注册表,您无法更改墙纸,因为它是存储墙纸位置的位置。