{"id":71133,"date":"2004-10-27T18:36:00","date_gmt":"2004-10-27T18:36:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/10\/27\/how-can-i-change-the-screensaver-timeout-value\/"},"modified":"2004-10-27T18:36:00","modified_gmt":"2004-10-27T18:36:00","slug":"how-can-i-change-the-screensaver-timeout-value","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-change-the-screensaver-timeout-value\/","title":{"rendered":"How Can I Change the Screensaver Timeout Value?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! Can I use a script to change the timeout value for the screensaver on a computer?<BR><BR>&#8212; JN<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/A> \n<P>Hey, JN. For some reason, Microsoft\u2019s scripting technologies come up a little short any time you\u2019re talking about Windows settings and components, things like screensavers, wallpaper, the Taskbar, the Start menu, etc. You can use WMI (in particular, the Win32_Desktop class) to <I>read<\/I> many of these values, but you can\u2019t use the Win32_Desktop class (or any equivalent class or object) to <I>modify<\/I> these values. Why? To be honest, we don\u2019t really know; that\u2019s just the way it is.<\/P>\n<P>Fortunately, though, many of these settings are stored in the Windows registry, and if it\u2019s stored in the registry, there\u2019s a good chance you can write a script to manage those settings. The screensaver is no exception. Open up Regedit, and take a look in HKEY_CURRENT_USER; in the Control Panel\\Desktop key, you\u2019ll see several registry values related to the screensaver, including ScreenSaveTimeout. As you might have guessed, this is the registry value that determines how long the system must be idle before the screensaver kicks in. By default, this is set to 600 seconds, or 10 minutes.<\/P>\n<P>So how do you change that value? By using a script just like this one, which changes the timeout value to 5 minutes (300 seconds):<\/P><PRE class=\"codeSample\">HKEY_CURRENT_USER = &amp;H80000001\nstrComputer = &#8220;.&#8221;\nSet objReg = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\default:StdRegProv&#8221;)\nstrKeyPath = &#8220;Control Panel\\Desktop&#8221;\nobjReg.CreateKey HKEY_CURRENT_USER, strKeyPath\nValueName = &#8220;ScreenSaveTimeout&#8221;\nstrValue = &#8220;300&#8221;\nobjReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue\n<\/PRE>\n<P>To do this, we start by creating a constant named HKEY_CURRENT_USER and set the value to &amp;H80000001; this tells WMI\u2019s Registry provider that we\u2019re working with the HKEY_CURRENT_USER portion of the registry. If we wanted to work with HKEY_LOCAL_MACHINE, we\u2019d set a constant equal to &amp;H80000001; &amp;H80000003 would let us work with HKEY_USERS.<\/P>\n<P>For this script we\u2019re working on the local computer, so we set the variable strComputer to a dot (a WMI shortcut meaning the local computer). But the great thing about the Registry provider is that it works just as well on remote computers as it does the local computer. If you want to change the screensaver timeout value on a remote computer, just set the value of strComputer to the name of that computer.<\/P>\n<P>From there we connect to the WMI service, and specify the registry path (Control Panel\\Desktop). Next we call the CreateKey method. This is just to be on the safe side. If the registry key we\u2019re looking for doesn\u2019t exist, CreateKey will create it. If the registry key already exists, then CreateKey will just leave well enough alone.<\/P>\n<P>After specifying the name of the registry value we want to change (ScreenSaveTimeout) and the new value (300), we then use the SetStringValue method to change the timeout value to 300 seconds. <\/P>\n<P>Not too bad, huh? For more information about the Registry provider &#8211; probably one of the most under-appreciated on all WMI providers &#8211; take a look at the <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/guide\/sas_reg_overview.mspx\" target=\"_blank\"><B>Registry chapter<\/B><\/A> in the Microsoft Windows 2000 Scripting Guide. And check out the infamous <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/tools\/twkmatic.mspx\"><B>Tweakomatic<\/B><\/A>, the amazing utility that will actually write scripts that can read from and write to the registry. And to steal from an old commercial, with a name like Tweakomatic, it <I>has<\/I> to be good.<\/P>\n<P>Incidentally, here\u2019s another useful screensaver script for you; this one ensures that the screensaver is password-protected:<\/P><PRE class=\"codeSample\">HKEY_CURRENT_USER = &amp;H80000001\nstrComputer = &#8220;.&#8221;\nSet objReg = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\default:StdRegProv&#8221;)\nstrKeyPath = &#8220;Control Panel\\Desktop&#8221;\nobjReg.CreateKey HKEY_CURRENT_USER, strKeyPath\nValueName = &#8220;ScreenSaverIsSecure&#8221;\nstrValue = &#8220;1&#8221;\nobjReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue\n<\/PRE>\n<P>See how much fun registry scripting can be?!? The Tweakomatic has additional scripts for managing the screensaver, as well as scripts for managing the Start menu, the Task bar, Windows Explorer folder settings, and a whole lot more. If you\u2019re looking for ways to manage common desktop settings, that\u2019s as good a place to start as any.<\/P><BR>\n<DIV>\n<TABLE class=\"\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">\n<TBODY>\n<TR>\n<TD class=\"\"><A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/oct04\/hey1027.mspx#top\"><IMG height=\"9\" alt=\"Top of page\" src=\"http:\/\/www.microsoft.com\/technet\/mnplibrary\/templates\/MNP2.Common\/images\/arrow_px_up.gif\" width=\"7\" border=\"0\"><\/A><A class=\"topOfPage\" href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/oct04\/hey1027.mspx#top\">Top of page<\/A><\/TD><\/TR><\/TBODY><\/TABLE><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Can I use a script to change the timeout value for the screensaver on a computer?&#8212; JN Hey, JN. For some reason, Microsoft\u2019s scripting technologies come up a little short any time you\u2019re talking about Windows settings and components, things like screensavers, wallpaper, the Taskbar, the Start menu, etc. You can use [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[237,16,3,5],"class_list":["post-71133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-basic-computer-information","tag-desktop-management","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Can I use a script to change the timeout value for the screensaver on a computer?&#8212; JN Hey, JN. For some reason, Microsoft\u2019s scripting technologies come up a little short any time you\u2019re talking about Windows settings and components, things like screensavers, wallpaper, the Taskbar, the Start menu, etc. You can use [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=71133"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71133\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=71133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}