PC > 指定フォルダ内の画像からランダムで壁紙を自動設定

電気技術とプログラムの世界

« LinuxにHamachi導入時のエラー | メイン | Windows2GBの壁 »

指定フォルダ内の画像からランダムで壁紙を自動設定

Windowsのpowershellを利用して壁紙をランダムで自動設定してくれるようにしてみた.

コードは以下の通り

function set-wallpaper{ Param ( [string]$newpaper="",[string]$format) switch ($format) { "tiled" {$tile=1;$style=0} "centered" {$tile=0;$style=0} "fit" {$tile=0;$style=2} default {$tile=0;$style=0} } #verify file exists if (Get-ChildItem $newpaper -ea "SilentlyContinue") { $regkeys="HKCU:Control Panel\Desktop","HKCU:Software\Microsoft\Internet Explorer\Desktop\General" foreach ($regkey in $regkeys) { Set-ItemProperty -path $regkey -name WallPaper -value $newpaper Set-ItemProperty -path $regkey -name TileWallpaper -value $tile Set-ItemProperty -path $regkey -name WallpaperStyle -value $style } $rundll32="{0}\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters" -f $env:windir Invoke-Expression -Command $rundll32 } else { Write-Warning "Failed to find $newpaper" } }

$folder="F:\img\material\wallpaper"

$file=get-Childitem $folder -name | get-Random

set-wallpaper $folder/$file "centered"

上記コードをwallpaper.ps1などと名前を付けて保存

下から三行目
$folder="F:\img\material\wallpaper"
で画像が入っているフォルダを指定

最終行
set-wallpaper $folder/$file "centered"
にて
"tiled" 並べて表示
"centered" 中央に表示
"fit" 拡大して表示
を設定

後はwallpaper.ps1をスタートアップ時などに読み込ませてあげれば完了.
今回はWindowsXPで行ったがデスクトップの再描画が上手くできないのかデスクトップのアイコンを表示しない設定にしないと上手く動かなかった.
そのため,実行時に壁紙が変更されるわけだが実際に目で見れるのは再ログインした後といった動作になってしまっているのでデスクトップの再描画する等の改善が必要そう.

スクリプト参考
ScriptingAnswers.com Forums: How do I get a Powershell script to set Wallpaper?:
powershell関連付け参考
PowerShell Scripting - インストールから実行まで

トラックバック

このエントリーのトラックバックURL:

コメントする


画像の中に見える文字を入力してください。

About

2010年3月15日 14:06に投稿されたエントリーのページです。

ひとつ前の投稿は「LinuxにHamachi導入時のエラー」です。

次の投稿は「Windows2GBの壁」です。

他にも多くのエントリーがあります。メインページアーカイブページも見てください。

ページのトップへ
tasyu.com  - ブログ  - 電気  - リンクについて
Copyright © TASYU All rights reserved.