官方bing壁纸软件-Bing Wallpaper

更新内容:官方Bing壁纸软件-Bing Wallpaper

官方发布了一款bing壁纸软件:Bing Wallpaper

下载安装中会有两个选项:将bing设为首页和将bing设为默认搜索。根据个人打勾或取消。软件是英文版的,不能设置中文。

功能很简单:壁纸的故事,变更壁纸和开启每日壁纸


原文初始标题:

bing image desktop 获取bing首页图片设置为桌面,脚本转exe

内容:

新建txt文本文档,填写如下代码(代码来源网络)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
Param(
# Get the Bing image of this country
[ValidateSet('en-US', 'de-DE', 'en-AU', 'en-CA', 'en-NZ', 'en-UK', 'ja-JP', 'zh-CN')][string]$locale = 'zh-CN',

# Download the latest $files Wallpapers
[int]$files = 0,

# Resolution of the image to download
[ValidateSet('auto', '1024x768', '1280x720', '1366x768', '1920x1080')][string]$resolution = 'auto',

# Destination folder to download the Wallpapers to
[string]$downloadFolder = "$([Environment]::GetFolderPath("MyPictures"))\Bing-Wallpapers"
)
# Max item count: the number of images we'll query for
[int]$maxItemCount = [System.Math]::max(1, [System.Math]::max($files, 8))
# URI to fetch the image locations from
[string]$hostname = "https://www.bing.com"
[string]$uri = "$hostname/HPImageArchive.aspx?format=xml&idx=0&n=$maxItemCount&mkt=$locale"

# Get the appropiate screen resolution
if ($resolution -eq 'auto') {
Add-Type -AssemblyName System.Windows.Forms
$primaryScreen = [System.Windows.Forms.Screen]::AllScreens Where-Object {$_.Primary -eq 'True'}
if ($primaryScreen.Bounds.Width -le 1024) {
$resolution = '1024x768'
}
elseif ($primaryScreen.Bounds.Width -le 1280) {
$resolution = '1280x720'
}
elseif ($primaryScreen.Bounds.Width -le 1366) {
$resolution = '1366x768'
}
else {
$resolution = '1920x1080'
}
}

# Check if download folder exists and otherwise create it
if (!(Test-Path $downloadFolder)) {
New-Item -ItemType Directory $downloadFolder
}

$request = Invoke-WebRequest -Uri $uri
[xml]$content = $request.Content

$items = New-Object System.Collections.ArrayList
foreach ($xmlImage in $content.images.image) {
[datetime]$imageDate = [datetime]::ParseExact($xmlImage.startdate, 'yyyyMMdd', $null)
[string]$imageUrl = "$hostname$($xmlImage.urlBase)_$resolution.webp"

# Add item to our array list
$item = New-Object System.Object
$item Add-Member -Type NoteProperty -Name date -Value $imageDate
$item Add-Member -Type NoteProperty -Name url -Value $imageUrl
$null = $items.Add($item)
}

# Keep only the most recent $files items to download
if (!($files -eq 0) -and ($items.Count -gt $files)) {
# We have too many matches, keep only the most recent
$items = $itemsSort-Object date
while ($items.Count -gt $files) {
# Pop the oldest item of the array
$null, $items = $items
}
}

Write-Host "Downloading images..."
$client = New-Object System.Net.WebClient
$imgsArr = @()
foreach ($item in $items) {
$baseName = $item.date.ToString("yyyy-MM-dd")
$destination = "$downloadFolder\$baseName.webp"
$url = $item.url

$imgsArr = $imgsArr + $destination
# Download the enclosure if we haven't done so already
if (!(Test-Path $destination)) {
Write-Debug "Downloading image to $destination"
$client.DownloadFile($url, "$destination")
}
}

if ($files -gt 0) {
# We do not want to keep every file; remove the old ones
Write-Host "Cleaning the directory..."
$i = 1
Get-ChildItem -Filter "????-??-??.webp" $downloadFolder Sort-Object -Descending FullName ForEach-Object {
if ($i -gt $files) {
# We have more files than we want, delete the extra files
$fileName = $_.FullName
Write-Debug "Removing file $fileName"
Remove-Item "$fileName"
}
$i++
}
}

#The code is from https://stackoverflow.com/questions/9440135/powershell-script-from-shortcut-to-change-desktop
Add-Type @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Wallpaper
{
public enum Style : int
{
Tile, Center, Stretch, NoChange
}
public class Setter {
public const int SetDesktopWallpaper = 20;
public const int UpdateIniFile = 0x01;
public const int SendWinIniChange = 0x02;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaper ( string path, Wallpaper.Style style ) {
SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile SendWinIniChange );
RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
switch( style )
{
case Style.Stretch :
key.SetValue(@"WallpaperStyle", "2") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
case Style.Center :
key.SetValue(@"WallpaperStyle", "1") ;
key.SetValue(@"TileWallpaper", "0") ;
break;
case Style.Tile :
key.SetValue(@"WallpaperStyle", "1") ;
key.SetValue(@"TileWallpaper", "1") ;
break;
case Style.NoChange :
break;
}
key.Close();
}
}
}
"@

$today = Get-Date (Get-Date).AddDays(-1) -UFormat "%Y-%m-%d"
$lastPicDate = Get-Date $items[0].date -UFormat "%Y-%m-%d"

switch ($lastPicDate) {
$today {
$Wallpaper = "$downloadFolder\" + $today + '.webp'
break
}
Default {
$imgsArr = $imgsArr Sort-Object {Get-Random}
$Wallpaper = $imgsArr[0]
break
}
}

[Wallpaper.Setter]::SetWallpaper( $Wallpaper, 1 )

将.txt格式改为shell脚本.ps1格式.用powershell运行一下是否成功.

将脚本文件转成可执行的.exe文件需要脚本编辑器.我使用的是PowerGUI.3.8.0.129

bing image desktop

File->Open打开ps1脚本文件

bing image desktop

Tools->Compile Script

bing image desktop

图标格式为.ico格式.其它根据你自己情况选择

bing-Wallpapers.ico文件

编译完成的.exe文件

https://1drv.ms/u/s!Ajlt0jS9cFmqkOdFfbtCvRzBzZ40fg?e=WxYZel

bing image desktop

选择完后会生成.exe和.config两个文件

计划任务 设置运行时间或开机启动

bing image desktop

控制面板->系统安全->管理工具->计划任务

bing image desktop

创建任务:取个名字,勾选使用最高权限运行

bing image desktop

触发器->选择开始任务,配置你想启动的方式和时间
开始任务更改为登陆时,勾选所有用户,勾选延迟任务时间为30秒.还有启用.

获取bing首页图片

操作->浏览选择生成的.exe文件.
注 : 这里以前我是使用脚本运行的,可是每次启动的打开方式却是txt文本编辑器,才编译为.exe文件运行的

获取bing首页图片

刚刚停电 , 重启后没有网络连接 . 程序没有连接到网络 , 桌面会是黑色 .添加一个条件

获取bing首页图片

设置->勾选如图所示

创建任务里按需更改选项 , 然后保存测试就可以了.