{"id":2288,"date":"2014-06-26T20:55:28","date_gmt":"2014-06-26T17:55:28","guid":{"rendered":"http:\/\/9v.lt\/blog\/?p=2288"},"modified":"2022-01-19T08:34:39","modified_gmt":"2022-01-19T06:34:39","slug":"change-windows-wallpaper-programatically","status":"publish","type":"post","link":"http:\/\/9v.lt\/blog\/change-windows-wallpaper-programatically\/","title":{"rendered":"Change windows wallpaper programatically"},"content":{"rendered":"<p>Another VBScript I produced, this time it&#8217;s to change the wallpaper. Well, we have a lot of computers used in classes and we decided it&#8217;s enough already to show off that shitty Windows background and replace it with our own wallpaper. Group Policy wasn&#8217;t much help &#8211; it allowed to change the wallpaper, however it would change for everyone, all the time and wouldn&#8217;t let people to change it back &#8211; what the hell Microsoft? Because of this I made a workaround &#8211; a VBScript to change the wallpaper but only once and let people change it back. Put this into the domain&#8217;s logoff script and done. In the morning they&#8217;ll have a fresh desktop :D<br \/>\nIt works very simply &#8211; reads a custom registry key which contains 1 if the script has ran already and if it exists and data is valid (1 for true) the script exits. Otherwise it proceeds to download a wallpaper (has to be in BMP format, otherwise WinXP will not understand wtf you are giving it), sets it as a background, makes it stretch and if everything went fine, writes that control registry key so it knows that it has done shit before on this computer.<br \/>\nThat&#8217;s basically it, very simple. Can be downloaded from <a href=\"http:\/\/9v.lt\/projects\/other\/change_wallpaper.vbs\" target=\"_blank\" rel=\"noopener\">here<\/a> and of course the code for quick review is below.<br \/>\n<!--more--><\/p>\n<pre lang=\"vb\" line=\"1\">\r\n'======================================================\r\n'   Author: Kulverstukas\r\n'   Date: 2014.06.24\r\n'   Description:\r\n'       Downloads and changes the wallpaper for current user,\r\n'       but it only takes effect after the user has logged on\r\n'       the second time. The script changes the wallpaper only\r\n'       once and users can change it back.\r\n'======================================================\r\nFunction DownloadWallpaper(fromWhere, toWhere)\r\nSet xHttp = createobject(\"Microsoft.XMLHTTP\")\r\nSet bStrm = createobject(\"Adodb.Stream\")\r\nxHttp.Open \"GET\", fromWhere, False\r\nxHttp.Send\r\n\r\nWith bStrm\r\n    .type = 1 ' binary\r\n    .open\r\n    .write xHttp.responseBody\r\n    .savetofile toWhere, 2 ' overwrite\r\nEnd With\r\nEnd Function\r\n'======================================================\r\n\r\nSet wshShell = CreateObject(\"WScript.Shell\")\r\n\r\n' check if wallpaper was changed once\r\nOn Error Resume Next\r\nvalue = WSHShell.RegRead(WallpaperChangedOnceKey)\r\n\r\n' do this only if there is no key, or the key contains invalid data\r\nIf ((err.number <> 0) Or (value <> 1)) Then\r\n    fullPath = wshShell.ExpandEnvironmentStrings(\"%USERPROFILE%\\awesomeWallpaper.bmp\")\r\n    DownloadWallpaper \"http:\/\/localhost\/awesomeWallpaper.bmp\", fullPath\r\n    wshShell.RegWrite \"HKCU\\Control Panel\\Desktop\\Wallpaper\", fullPath, \"REG_SZ\"\r\n    wshShell.RegWrite \"HKCU\\Control Panel\\Desktop\\WallpaperStyle\", \"2\", \"REG_SZ\"\r\n    wshShell.RegWrite \"HKCU\\ish\\WallpaperChangedOnce\", 1, \"REG_DWORD\"\r\nEnd If\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Another VBScript I produced, this time it&#8217;s to change the wallpaper. Well, we have a<\/p>\n","protected":false},"author":2,"featured_media":2282,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,750],"tags":[416,915,913,414,914],"class_list":["post-2288","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-projects","category-software-projects","tag-basic","tag-gpo","tag-vbs","tag-vbscript","tag-wallpaper"],"_links":{"self":[{"href":"http:\/\/9v.lt\/blog\/wp-json\/wp\/v2\/posts\/2288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/9v.lt\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/9v.lt\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/9v.lt\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/9v.lt\/blog\/wp-json\/wp\/v2\/comments?post=2288"}],"version-history":[{"count":0,"href":"http:\/\/9v.lt\/blog\/wp-json\/wp\/v2\/posts\/2288\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/9v.lt\/blog\/wp-json\/wp\/v2\/media\/2282"}],"wp:attachment":[{"href":"http:\/\/9v.lt\/blog\/wp-json\/wp\/v2\/media?parent=2288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/9v.lt\/blog\/wp-json\/wp\/v2\/categories?post=2288"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/9v.lt\/blog\/wp-json\/wp\/v2\/tags?post=2288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}