Jump to content

Copying a portion of one .ini file and inputing that selection into vbscript


Recommended Posts

Posted
Not sure if this is even possible, but we're trying to add a site to trusted sites in Firefox, but in order to do so, we need to modify the prefs.js file in the profile folder under "profiles." Problem is, we want to make this change to all the machines on our network, but because Firefox gave random profile names to each user, we need to either use a wild card, or make a scrip that can pull the user id from the profiles.ini file and input it into the script with an append function. Anyone know how I can accomplish this? Seems to be quite difficult.
Posted
I was actually able to figure it out, but now for the last piece of the puzzle. I need the script to check for the lines I want to write before they're written and quit the script if it detects the string or continue if it doesn't. How would I do that?
Posted

Here's where I'm at. It keeps telling me "expected end." Where am I going wrong?

 

dim filesys, filetxt, strSearchFor

strSearchFor = "pref(""network.negotiate-auth.trusted-uris"", ""dl-okoar-01.chikentime.local"");"

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Set filesys = CreateObject("Scripting.FileSystemObject")

Set objFile = filesys.OpenTextFile("C:\Program Files (x86)\Mozilla Firefox\defaults\pref\channel-prefs.js", ForReading)

    IfInStr(strLine, strSearchFor) = TrueThen

Set filetxt = Nothing

    IfNot foundthen

Set filetxt = filesys.OpenTextFile("C:\Program Files (x86)\Mozilla Firefox\defaults\pref\channel-prefs.js", ForAppending, True)

filetxt.WriteLine("pref(""network.negotiate-auth.trusted-uris"", ""dl-okoar-01.chikentime.local"");")

filetxt.WriteLine("pref(""network.automatic-ntlm-auth.allow-non-fqdn"", true);")

filetxt.WriteLine("pref(""network.negotiate-auth.allow-non-fqdn"", true);")

filetxt.Close

EndIf

 

Posted (edited)

I'm not overly familiar with vbscript, versus other languages, but try this approach:

 

dim filesys, filetxt, strSearchFor 
strSearchFor = "pref(""network.negotiate-auth.trusted-uris"", ""dl-okoar-01.chikentime.local"");"
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set objFile = filesys.OpenTextFile("C:\Program Files (x86)\Mozilla Firefox\defaults\pref\channel-prefs.js", ForReading)
If Not InStr(strLine, strSearchFor) = True Then
	Set filetxt = filesys.OpenTextFile("C:\Program Files (x86)\Mozilla Firefox\defaults\pref\channel-prefs.js", ForAppending, True)
	filetxt.WriteLine("pref(""network.negotiate-auth.trusted-uris"", ""dl-okoar-01.chikentime.local"");")
	filetxt.WriteLine("pref(""network.automatic-ntlm-auth.allow-non-fqdn"", true);")
	filetxt.WriteLine("pref(""network.negotiate-auth.allow-non-fqdn"", true);")
	filetxt.Close
End If

 

I would also expect that "If Not InStr(strLine, strSearchFor) = True Then" can be shortened to "If Not InStr(strLine, strSearchFor) Then" but again that might be how VBscript needs it.

 

Also, have you intentionally misspelt "chickentime" as "chikentime"?

 

Peter

 

(Edit: Corrected the tabbing that didn't apply when I hit post)

Edited by howartp

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...