{"id":51,"date":"2007-07-10T18:46:25","date_gmt":"2007-07-10T18:46:25","guid":{"rendered":"http:\/\/www.nukeitmike.com\/blog\/2007\/07\/10\/ListAllFoldersInTheUserProfileDirectory.aspx"},"modified":"2007-07-10T18:46:25","modified_gmt":"2007-07-10T18:46:25","slug":"list-all-folders-in-the-user-profile-directory","status":"publish","type":"post","link":"https:\/\/blog.nukeitmike.com\/index.php\/2007\/07\/10\/list-all-folders-in-the-user-profile-directory\/","title":{"rendered":"List All Folders in the User Profile Directory"},"content":{"rendered":"<p>I wanted to be able to remotely connect to a server and see if it had a profile directory for a particular user.&nbsp; I wrote a VBScript that will connect to a machine through WMI, find out what the ProfilesDirectory path is and then list all the folders in that directory.&nbsp; It wouldn&#8217;t take much to be able to output to a text file or some other format.<\/p>\n<p>The next thing I will work on is to have it pull a list of machines from somewhere, go check those machines and then when it finds a particular profile on that machine to go and remove it.&nbsp;&nbsp; You can see what I have so far:<\/p>\n<blockquote>\n<p><em>Const HKLM = &amp;H80000002 <\/em> <\/p>\n<p><em>Dim strComputer <\/em> <\/p>\n<p><em>strComputer = &#8220;.&#8221; &#8216;This computer is the &#8220;.&#8221;.&nbsp; If you want another computer, replace the .<br \/>Set oReg=GetObject(&#8220;winmgmts:{impersonationLevel=impersonate}!\\\\&#8221; &amp; _ <br \/>&nbsp;&nbsp;&nbsp; strComputer &amp; &#8220;\\root\\default:StdRegProv&#8221;)<br \/>strKeyPath = &#8220;SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\&#8221;<br \/>strValueName = &#8220;ProfilesDirectory&#8221; <\/em> <\/p>\n<p><em>oReg.GetExpandedStringValue HKLM,strKeyPath,strValueName,strValue <\/em> <\/p>\n<p><em>If strValue = &#8220;%SystemDrive%\\Documents and Settings&#8221; Then<br \/>&nbsp;&nbsp;&nbsp; WScript.Echo &#8220;Default Path&#8221;<br \/>&nbsp;&nbsp;&nbsp; strProfilePath = &#8220;C:\\Documents and Settings&#8221;<br \/>Else<br \/>&nbsp;&nbsp;&nbsp; WScript.Echo strValue<br \/>&nbsp;&nbsp;&nbsp; strProfilePath = strValue<br \/>End If <\/em> <\/p>\n<p><em>Set objWMIService = GetObject(&#8220;winmgmts:&#8221; _<br \/>&nbsp;&amp; &#8220;{impersonationLevel=impersonate}!\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<br \/>Set colSubfolders = objWMIService.ExecQuery _<br \/>&nbsp;(&#8220;ASSOCIATORS OF {Win32_Directory.Name='&#8221; &amp; strProfilePath &amp; &#8220;&#8216;} &#8221; _<br \/>&nbsp;&amp; &#8220;WHERE AssocClass = Win32_Subdirectory &#8221; _<br \/>&nbsp;&amp; &#8220;ResultRole = PartComponent&#8221;)<br \/>For Each objFolder in colSubfolders<br \/>&nbsp;Wscript.Echo objFolder.Name<br \/>Next<\/em><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to be able to remotely connect to a server and see if it had a profile directory for a particular user.&nbsp; I wrote a VBScript that will connect to a machine through WMI, find out what the ProfilesDirectory path is and then list all the folders in that directory.&nbsp; It wouldn&#8217;t take much&hellip; <a class=\"more-link\" href=\"https:\/\/blog.nukeitmike.com\/index.php\/2007\/07\/10\/list-all-folders-in-the-user-profile-directory\/\">Continue reading <span class=\"screen-reader-text\">List All Folders in the User Profile Directory<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-scripting","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pcW544-P","_links":{"self":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":0,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nukeitmike.com\/index.php\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}