{"id":69003,"date":"2005-09-08T19:54:00","date_gmt":"2005-09-08T19:54:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/09\/08\/how-can-i-clear-the-logon-script-path-for-all-my-users\/"},"modified":"2005-09-08T19:54:00","modified_gmt":"2005-09-08T19:54:00","slug":"how-can-i-clear-the-logon-script-path-for-all-my-users","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-clear-the-logon-script-path-for-all-my-users\/","title":{"rendered":"How Can I Clear the Logon Script Path for All My Users?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I clear the logon script path for all my users?<BR><BR>&#8212; TF<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, TF. You know, during in a momentary bout of insanity one of the Scripting Guys once agreed to play his son in an Xbox college football game. \u201cIt\u2019s really easy to play,\u201d noted the Scripting Son, who then proceeded to provide a brief tutorial on how to run, pass, kick, and tackle. A half hour or so later &#8211; and trailing 150,000 to nothing &#8211; the Scripting Guy sighed. \u201cMan, your guys just seem so much faster than mine: I can never outrun them and <I>never<\/I> catch up to them.\u201d <\/P>\n<P>\u201cWell, that\u2019s because you never use the turbo button,\u201d replied the Scripting Son. \u201cDid I forget to tell you about the turbo button?\u201d<\/P>\n<P>Yes, son, you did. Forearmed with the new-found knowledge about the turbo button, the Scripting Guy and his son squared off once more, this time in a fair-and-square battle for family video game supremacy.<\/P>\n<TABLE id=\"E5C\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. No, it doesn\u2019t matter what the score was. After all, this was about quality bonding time between a father and a son; it had nothing to do with winning or losing. Besides, there was a glare on the TV screen and the B button on the Scripting Guy\u2019s controller didn\u2019t seem to work right. And, really, it\u2019s just a silly little video game: what difference does it make if you happen to get crushed 104-7? Not that 104-7 really counts as a <I>crush<\/I>, mind you. Edged 104-7? Nipped 104-7? Lucked out 104-7? Something like that.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>As it turns out, clearing the logon script path is just as easy as playing college football on the Xbox \u2026 <I>provided<\/I> that you know about ADSI\u2019s version of the turbo button. What does that mean? Well, let\u2019s show you the script and then answer the question:<\/P><PRE class=\"codeSample\">On Error Resume Next<\/p>\n<p>Const ADS_SCOPE_SUBTREE = 2\nConst ADS_PROPERTY_CLEAR = 1<\/p>\n<p>Set objConnection = CreateObject(&#8220;ADODB.Connection&#8221;)\nSet objCommand =   CreateObject(&#8220;ADODB.Command&#8221;)\nobjConnection.Provider = &#8220;ADsDSOObject&#8221;\nobjConnection.Open &#8220;Active Directory Provider&#8221;\nSet objCommand.ActiveConnection = objConnection<\/p>\n<p>objCommand.Properties(&#8220;Page Size&#8221;) = 1000\nobjCommand.Properties(&#8220;Searchscope&#8221;) = ADS_SCOPE_SUBTREE <\/p>\n<p>objCommand.CommandText = _\n    &#8220;SELECT AdsPath FROM &#8216;LDAP:\/\/dc=fabrikam,dc=com&#8217; WHERE objectCategory=&#8217;user'&#8221;\nSet objRecordSet = objCommand.Execute<\/p>\n<p>objRecordSet.MoveFirst\nDo Until objRecordSet.EOF\n    Set objUser = GetObject(objRecordSet.Fields(&#8220;AdsPath&#8221;).Value)\n    objUser.PutEx ADS_PROPERTY_CLEAR, &#8220;scriptPath&#8221;, 0\n    objUser.SetInfo\n    objRecordSet.MoveNext\nLoop\n<\/PRE>\n<P>For the most part this is a standard script for searching Active Directory: we simply retrieve the AdsPath attribute for all the user accounts, then bind to each user account and clear the value for the scriptPath attribute. We don\u2019t have room in this column to explain how all that works; if you aren\u2019t familiar with scripts that search Active Directory, you might want to take a look at our two-part <I>Tales from the Script<\/I> series titled <A href=\"http:\/\/null\/technet\/scriptcenter\/resources\/tales\/sg0405.mspx\"><B>Dude, Where\u2019s My Printer?<\/B><\/A><\/P>\n<P>So where\u2019s the turbo button in all this? Well the turbo button shows up here, the part where we actually clear the logon script path for a user:<\/P><PRE class=\"codeSample\">objUser.PutEx ADS_PROPERTY_CLEAR, &#8220;scriptPath&#8221;, 0\nobjUser.SetInfo\n<\/PRE>\n<P>As you can see, this is somewhat odd-looking code. You might expect us to do something a little more straightforward, like set the value of the scriptPath attribute to nothing:<\/P><PRE class=\"codeSample\">objUser.scriptPath = &#8220;&#8221;\nobjUser.SetInfo\n<\/PRE>\n<P>Why don\u2019t we do this? There\u2019s a simple reason for that: it won\u2019t work. Setting the value of scriptPath to an empty string will not actually <I>clear<\/I> the scriptPath; instead, it sets the value to an empty string. You might think, \u201cWell, so what?\u201d, but to Active Directory there\u2019s definitely a difference. Suppose we conduct a search for all the users that have a logon script assigned to them. Believe it or not, any user whose scriptPath has been set to an empty string will show up as having a logon script assigned to them. That\u2019s because Active Directory believes that this user <I>does<\/I> have a logon script assigned; it\u2019s just that the scriptPath happens to equal an empty string.<\/P>\n<P>We know, we know. But that\u2019s just the way it is.<\/P>\n<P>Because of this, we have to specifically clear the scriptPath attribute; we can\u2019t just set the value to an empty string. To clear the attribute we define a constant named ADS_PROPERTY_CLEAR and set the value to 1. We then call the <B>PutEx<\/B> method followed by three parameters:<\/P>\n<TABLE border=\"0\" cellSpacing=\"0\" cellPadding=\"0\">\n<TBODY>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>ADS_PROPERTY_CLEAR, indicating the type of operation we want to perform (clearing the value).<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>\u201cscriptPath\u201d, indicating the attribute we want to clear.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>0, a placeholder for the new value being assigned. We aren\u2019t really assigning a new value, but without adding the 0 we\u2019ll get an error message because PutEx will not have the required number of parameters.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<P>After all that we then call the <B>SetInfo<\/B> method to officially write the changes to the user account object in Active Directory. The logon script path will now be <I>cleared<\/I>.<\/P>\n<P>In case you\u2019re wondering, in relative terms our hero\u2019s performance in Xbox football wasn\u2019t all that bad; after all, you should have seen what happened when he tried to play <I>Halo 2<\/I>. Not a pretty sight at all. <\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I clear the logon script path for all my users?&#8212; TF Hey, TF. You know, during in a momentary bout of insanity one of the Scripting Guys once agreed to play his son in an Xbox college football game. \u201cIt\u2019s really easy to play,\u201d noted the Scripting Son, who then [&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":[7,3,20,5],"class_list":["post-69003","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-scripting-guy","tag-user-accounts","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I clear the logon script path for all my users?&#8212; TF Hey, TF. You know, during in a momentary bout of insanity one of the Scripting Guys once agreed to play his son in an Xbox college football game. \u201cIt\u2019s really easy to play,\u201d noted the Scripting Son, who then [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69003","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=69003"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69003\/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=69003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=69003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=69003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}