{"id":218,"date":"2017-05-18T15:08:38","date_gmt":"2017-05-18T15:08:38","guid":{"rendered":"http:\/\/techref.passionwind.org\/?p=218"},"modified":"2017-05-19T09:09:38","modified_gmt":"2017-05-19T13:09:38","slug":"replacing-a-string-each-users-profile","status":"publish","type":"post","link":"http:\/\/techref.camellarry.com\/?p=218","title":{"rendered":"Replacing a string in each user&#8217;s profile"},"content":{"rendered":"<p>This routine replaces a string in the text file <em>user.js<\/em>. \u00a0The file is located in each user&#8217;s profile which also contains a random string as part of the path name.<\/p>\n<pre><span style=\"color: #0000ff;\">Imports System.Net<\/span>\r\n<span style=\"color: #0000ff;\">Imports System.IO<\/span>\r\n\r\n<span style=\"color: #ff0000;\">Public Class Form1<\/span>\r\n\r\n<span style=\"color: #0000ff;\">Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load<\/span>\r\n<span style=\"color: #0000ff;\"> Dim strPath As String = \"c:\\users\"<\/span>\r\n<span style=\"color: #0000ff;\"> Dim arrFolders() As String = System.IO.Directory.GetDirectories(strPath)<\/span>\r\n<span style=\"color: #0000ff;\"> Dim MozPath As String<\/span>\r\n\r\n<span style=\"color: #0000ff;\">'----------------------------------------------------------------<\/span>\r\n<span style=\"color: #0000ff;\"> ' get list of profiles<\/span>\r\n<span style=\"color: #0000ff;\"> '----------------------------------------------------------------<\/span>\r\n<span style=\"color: #0000ff;\"> For Each arrFolder As String In arrFolders<\/span>\r\n<span style=\"color: #0000ff;\"> MozPath = arrFolder &amp; \"\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\\"<\/span>\r\n\r\n<span style=\"color: #0000ff;\">If My.Computer.FileSystem.DirectoryExists(MozPath) = True Then<\/span>\r\n<span style=\"color: #0000ff;\"> Dim arrGUIDpath() As String = System.IO.Directory.GetDirectories(MozPath)<\/span>\r\n\r\n<span style=\"color: #0000ff;\">For Each arrGUIDfolder As String In arrGUIDpath<\/span>\r\n<span style=\"color: #0000ff;\"> If My.Computer.FileSystem.FileExists(arrGUIDfolder &amp; \"\\user.js\") = True Then<\/span>\r\n<span style=\"color: #0000ff;\"> Console.WriteLine(\"notepad \" &amp; arrGUIDfolder &amp; \"\\user.js\")<\/span>\r\n\r\n<span style=\"color: #0000ff;\">'----------------------------------------------------------------<\/span>\r\n<span style=\"color: #0000ff;\"> ' 1. rename the user.js file<\/span>\r\n<span style=\"color: #0000ff;\"> ' 2. replace the proxy defintion string tinto user.js<\/span>\r\n<span style=\"color: #0000ff;\"> '----------------------------------------------------------------<\/span>\r\n<span style=\"color: #0000ff;\"> Try<\/span>\r\n<span style=\"color: #0000ff;\"> My.Computer.FileSystem.DeleteFile(arrGUIDfolder &amp; \"\\user2.js\")<\/span>\r\n<span style=\"color: #0000ff;\"> Catch ex As Exception<\/span>\r\n<span style=\"color: #0000ff;\"> Application.DoEvents()<\/span>\r\n<span style=\"color: #0000ff;\"> End Try<\/span>\r\n\r\n<span style=\"color: #0000ff;\">My.Computer.FileSystem.CopyFile(arrGUIDfolder &amp; \"\\user.js\", arrGUIDfolder &amp; \"\\user2.js\")<\/span>\r\n\r\n<span style=\"color: #0000ff;\">My.Computer.FileSystem.WriteAllText(arrGUIDfolder &amp; \"\\user.js\", _<\/span>\r\n<span style=\"color: #0000ff;\"> My.Computer.FileSystem.ReadAllText(arrGUIDfolder &amp; \"\\user2.js\").Replace(\"user_pref(\"\"network.proxy.type\"\", 4);\", _<\/span>\r\n<span style=\"color: #0000ff;\"> \"user_pref(\"\"network.proxy.type\"\", 0);\"), False)<\/span>\r\n<span style=\"color: #0000ff;\"> End If<\/span>\r\n\r\n<span style=\"color: #0000ff;\">'----------------------------------------------------------------<\/span>\r\n<span style=\"color: #0000ff;\"> ' clean up to avoid confusion in the future<\/span>\r\n<span style=\"color: #0000ff;\"> '----------------------------------------------------------------<\/span>\r\n<span style=\"color: #0000ff;\"> Application.DoEvents()<\/span>\r\n\r\n<span style=\"color: #0000ff;\">Try<\/span>\r\n<span style=\"color: #0000ff;\"> My.Computer.FileSystem.DeleteFile(arrGUIDfolder &amp; \"\\user2.js\")<\/span>\r\n<span style=\"color: #0000ff;\"> Catch ex As Exception<\/span>\r\n<span style=\"color: #0000ff;\"> Application.DoEvents()<\/span>\r\n<span style=\"color: #0000ff;\"> End Try<\/span>\r\n<span style=\"color: #0000ff;\"> Next<\/span>\r\n<span style=\"color: #0000ff;\"> End If<\/span>\r\n\r\n<span style=\"color: #0000ff;\">Next<\/span>\r\n<span style=\"color: #0000ff;\"> End<\/span>\r\n<span style=\"color: #0000ff;\"> End Sub<\/span>\r\n\r\n<span style=\"color: #ff0000;\">End Class<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This routine replaces a string in the text file user.js. \u00a0The file is located in each user&#8217;s profile which also contains a random string as part of the path name. Imports System.Net Imports System.IO Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim strPath As String = &#8220;c:\\users&#8221; Dim arrFolders() [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"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":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[9],"tags":[12,24,29,87,58,74,76,77,78,80],"class_list":["post-218","post","type-post","status-publish","format-standard","hentry","category-vb-net","tag-net","tag-configure","tag-example","tag-firefox","tag-programming","tag-tutorial","tag-vb","tag-vb-net","tag-visualbasic","tag-windows"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9t3oE-3w","_links":{"self":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts\/218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=218"}],"version-history":[{"count":3,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts\/218\/revisions"}],"predecessor-version":[{"id":275,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts\/218\/revisions\/275"}],"wp:attachment":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}