物語

目的
実装にできるだけ「リソース」を費やさずにアイデアを実装し、スクリーンショットの作成から壁紙の置き換えまでのプロセスを気付かないようにします。
使用済みツール
- PhantomJS -Webリソースからスクリーンショットを取得するため
- NConvert-画像をさまざまな形式に変換するため
- 壁紙 -Windows Vistaおよび7で壁紙を更新するため
- VBScript-必要なすべてのコマンドを実行します
- Windowsタスクスケジューラ-定期的に壁紙を更新するため
実装
まず、 PhantomJS 、 NConvert 、 Wallpaperの最新バージョンをダウンロードします。
残念ながら、ファイル「wallpaper.exe」を含むアーカイブは利用できないため、記事のソースを含むアーカイブからダウンロードできます。リンクは最後に公開されます。
執筆時点では、PhantomJS 1.3.0 Windows(静的ビルド)およびNConvert v5.91が使用されていました。 次に、「meteo_wall」フォルダーを作成し、その中に「tools」サブフォルダーを作成します。 このサブフォルダーに移動し、「PhantomJS」アーカイブの内容を同じ名前のフォルダーに解凍します。 また、「ツール」フォルダーにNConvertとwallpaper.exeを配置します。 次に、「rasterize.js」ファイルをexamplesフォルダーからコピーして、「tools」フォルダーに配置する必要があります。 スクリーンショットの必要な拡張子を指定できるように、「rasterize.js」ファイルを少し修正します。
var page = new WebPage(), address, output, size; if (phantom.args.length < 2 || phantom.args.length > 3) { console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]'); console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"'); phantom.exit(); } else { address = phantom.args[0]; output = phantom.args[1]; page.viewportSize = { width: 600, height: 600 }; if (phantom.args.length === 3 && phantom.args[1].substr(-4) === ".pdf") { size = phantom.args[2].split('*'); page.paperSize = size.length === 2 ? { width: size[0], height: size[1], border: '0px' } : { format: phantom.args[2], orientation: 'portrait', border: '1cm' }; }/* xrays add */ else if(phantom.args.length === 3){ size = phantom.args[2].split('*'); page.viewportSize = { width: size[0], height: size[1] }; };/* end */ page.open(address, function (status) { if (status !== 'success') { console.log('Unable to load the address!'); } else { window.setTimeout(function () { page.render(output); phantom.exit(); }, 200); } }); }
その後、VBScriptの作成を開始できます。 「tools」フォルダーに「wallpaper.vbs」ファイルを作成します。まず、必要なファイルを説明し、重要な変数を入力します。
Dim WshShell Set WshShell = WScript.CreateObject("Wscript.Shell") Dim url, history, logon ' url = "http://www.artmeteo.ru/4335/" ' history = 1 ' logon = 1 ' Windows
率直に言って、その前はVBScriptでコードを書いていませんでした。 スクリーンショットを自動的に取得するには、画面の解像度を知る必要があります。
' Dim obj, monSize Set obj = CreateObject("htmlfile") monSize = obj.parentWindow.screen.width & "*" & obj.parentWindow.screen.height
次:
' ' Dim toolsPath, path Set obj = CreateObject("Scripting.FileSystemObject") ' obj toolsPath = obj.GetParentFolderName(WScript.ScriptFullName) & "\" ' path = obj.GetParentFolderName(toolsPath) & "\" ' ' Dim phantom, bmpname phantom = toolsPath&"phantomjs\" ' phantomjs bmpname = path&"url.bmp " ' bmp WshShell.Run phantom & "phantomjs.exe " & toolsPath & "rasterize.js " & url & " " & bmpname & monSize, 0, True '
注:最後の行の最後で、パラメーター
0, True
を使用して、コードがバックグラウンドで実行され、スクリプトで説明されている追加のコマンドがこのコードの実行を待機していることを確認します。
ご覧のとおり、スクリーンショットはbmp形式で保存されています。これは、VistaのWindowsのバージョンが異なる形式の壁紙を受け入れないためです。 次に、OSバージョンを確認します。
Dim OSType OSType = Left(Trim(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")),1) ' windows Dim convert, n, time, jpgname, wallpaper
スクリプトは可能な限りユニバーサルにする必要がありますが、OSの異なるバージョンを考慮する必要があるため、最初にWindows Vistaおよび7のコードについて説明します。
If OSType>5 Then ' Windows Vista Windows 7 ' bmp jpg Dim quality quality = 95 ' jpg convert = toolsPath & "nconvert.exe -out jpeg -q " & quality & " -i -overwrite -o " n = Now ' time = Right("00" & Day(n), 2) & "-" & Right("00" & Month(n), 2) & "-" & Right("00" & Year(n), 2) & "_" & Right("00" & Hour(n), 2) & "_" & Right("00" & Minute(n), 2) & "_" & Right("00" & Second(n), 2) ' jpgname = path & time & ".jpg " ' jpg WshShell.Run convert & jpgname & bmpname, 0, True ' bmp jpeg ' wallpaper = WshShell.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\Windows\Themes\TranscodedWallpaper.jpg" ' obj.CopyFile jpgname, wallpaper ' jpg . WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", wallpaper ' ' logon Dim logonname logonname = WshShell.ExpandEnvironmentStrings("%windir%") & "\System32\oobe\info\backgrounds\backgroundDefault.jpg " ' logon If logon = 1 Then ' logon Dim logonconvert, goodlogon Set file = obj.GetFile(jpgname) ' logon If Round(file.size/1024) < 256 Then ' < 256, goodlogon = 1 obj.CopyFile jpgname, logonname Else goodlogon = 0 quality = quality - 3 End If ' logon While goodlogon = 0 logonconvert = toolsPath & "nconvert.exe -out jpeg -q " & quality & " -i -overwrite -o " ' -canvas 1280 800 top-left WshShell.Run logonconvert & logonname & bmpname, 0, True Set file = obj.GetFile(logonname) ' logon If Round(file.size/1024) < 256 Then ' < 256 Kb, goodlogon = 1 Else quality = quality - 3 ' End If Wend WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background\OEMBackground", 1, "REG_DWORD" Else If obj.FileExists(logonname) Then obj.DeleteFile logonname, True ' logon , End If End If If history = 0 Then ' , jpg obj.DeleteFile jpgname, True End If WshShell.Run toolsPath & "wallpaper.exe", 0, True ' Windows
このコードでは、Windowsの要件が適用される画像(ようこそ画面の画像)のログオンに変更があることに気付くかもしれません。 これらの要件の本質は、ファイルを256 Kbより大きくすることはできないため、許容されるしきい値の制限に達するまで画像の品質を低下させるサイクルが開始されることです。
次は、Windowsの下位バージョンのコードについて説明します。
Else ' Windows ' wallpaper = WshShell.ExpandEnvironmentStrings("%appdata%") & "\Wallpaper.bmp" ' obj.CopyFile bmpname, wallpaper ' bmp . WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", wallpaper ' ' logon Dim Background, Winlogon If logon = 1 Then ' logon Background = 1 Winlogon = 0 WshShell.RegWrite "HKEY_USERS\.DEFAULT\Control Panel\Desktop\TileWallpaper", 1, "REG_SZ" ' : (0 = ; 1 = ()) Else Background = 0 wallpaper = "" Winlogon = 1 End If WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background\OEMBackground", Background, "REG_DWORD" ' logon WshShell.RegWrite "HKEY_USERS\.DEFAULT\Control Panel\Desktop\Wallpaper", wallpaper, "REG_SZ"' logon ' WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LogonType", Winlogon, "REG_DWORD" ' 1 - , 0 - If history = 1 Then ' , bmp jpg (95% ) convert = toolsPath & "nconvert.exe -out jpeg -q 95 -overwrite -o " n = Now time = Right("00" & Day(n), 2) & "-" & Right("00" & Month(n), 2) & "-" & Right("00" & Year(n), 2) & "_" & Right("00" & Hour(n), 2) & "_" & Right("00" & Minute(n), 2) & "_" & Right("00" & Second(n), 2) ' jpgname = path & time & ".jpg " WshShell.Run convert & jpgname & bmpname, 0, True ' bmp jpg End If WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 0, True ' End If
スクリプトの最後の「添えもの」:
obj.DeleteFile bmpname, True ' bmp Set WshShell = Nothing
これは、スクリプトが書き込まれる場所です。 たとえば、5分ごとの自動スクリプト実行は、組み込みのWindowsタスクスケジューラを使用して実行されます。 これを行うには、新しいタスクを作成し、起動するプログラムとして「wallpaper.vbs」スクリプトへのパスを指定します。また、毎日選択し、トリガーが機能するようにプロパティで5分ごとに繰り返すことを忘れないでください。
まとめ
スクリプトは、Windows 7を搭載した2台のコンピューター、Windows 2003 Serverを搭載したコンピューターとWindows XPを搭載したコンピューターでテストされました。 Windows XPのウェルカム画面で変更を確認するには、「コントロールパネル->ユーザーアカウント->ユーザーログインの変更」で「ウェルカムページを使用」ボックスのチェックを外すか、スクリプトソースの100行のコメントを外します。 すべての追加ソフトウェアを含むスクリプトのソースコードは、 ここから取得できます 。
更新情報
Windows 7を搭載した別のコンピューターでスクリプトをテストする機会がありましたが、正常に起動できませんでした。 問題は、ウェルカム画面の画像が保存されているファイルへのパスがないというエラーがあったことです。 経験的に、次のパス
"%windir%\System32\oobe\info\backgrounds\"
を手動で作成するか、ユーザーアカウント制御(UAC)設定を最低に変更し、その後コンピューターを再起動してスクリプトを更新するソリューションが見つかりましたこちらからダウンロードできます 。