问题:小组政策不允许我将锁定屏幕更改为幻灯片放映或聚光灯,但我是个人电脑上的本地管理员,通过替换C:\Windows\Web\Screen\Screen.jpg
我可以更改锁定屏幕图片。
解决方案:创建每xx分钟运行一次的batch
/ CMD
/ PS script
并从源文件夹中复制随机图片以替换C:\Windows\Web\Screen\Screen.jpg
我在这个article中发现了一个可行的脚本,但我如何根据自己的目的修改它?如果我在任务调度器中安排它每30分钟运行一次,批处理文件会在后台运行而不会产生干扰或者CMD脚本或Powershell脚本是否是更好的解决方案?
请参阅以下代码:
@echo off & setlocal
set "workDir=C:\source\folder"
::Read the %random%, two times is'nt a mistake! Why? Ask Bill.
::In fact at the first time %random% is nearly the same.
@set /a "rdm=%random%"
set /a "rdm=%random%"
::Push to your path.
pushd "%workDir%"
::Count all files in your path. (dir with /b shows only the filenames)
set /a "counter=0"
for /f "delims=" %%i in ('dir /b ^|find "."') do call :sub1
::This function gives a value from 1 to upper bound of files
set /a "rdNum=(%rdm%*%counter%/32767)+1"
::Start a random file
set /a "counter=0"
for /f "delims=" %%i in ('dir /b ^|find "."') do set "fileName=%%i" &call :sub2
::Pop back from your path.
popd "%workDir%"
goto :eof
:: end of main
:: start of sub1
:sub1
::For each found file set counter + 1.
set /a "counter+=1"
goto :eof
:: end of sub1
:: start of sub2
:sub2
::1st: count again,
::2nd: if counted number equals random number then start the file.
set /a "counter+=1"
if %counter%==%rdNum% (
:: OUTPUT ALERT BOX with FILENAME
MSG * "%fileName%"
)
goto :eof
:: end of sub2
答案 0 :(得分:1)
在这种情况下,IMO PowerShell远远优于批处理
dir C:\source\folder\*.jpg |Get-Random|Copy -Dest C:\Windows\Web\Screen\Screen.jpg -Force
您可以将其包装在批/ cmd行
中powershell -Nop -C "dir C:\source\folder\*.jpg |Get-Random|Copy -Dest C:\Windows\Web\Screen\Screen.jpg -Force"