Expected End of Statement error in vbs file

这一生的挚爱 提交于 2019-12-13 05:47:19

问题


I'm automating the task of disabling the Proxy on Mozilla firefox (it currently defaults to 'Automatic proxy config url' and I manually set it to 'No Proxy').

After some research, I realised the settings can be changed by creating a user.js file (which overrides the firefox settings stored in pref.js) that contains this:

user_pref("network.proxy.type", 0);

Below is the vbs syntax i'm having issues with:

Set objFSO=CreateObject("Scripting.FileSystemObject")

outFile="%APPDATA%\Mozilla\Firefox\Profiles\3b59qrw5.default\user.js"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "user_pref("network.proxy.type", 0);" & vbCrLf
objFile.Close

When executing the vbs file, I get this error

Line 5 Char 27 Expected end of statement 800A0401

Any help would be great, Thank you.


回答1:


VBScript strings are delimited by double quotes. If you want to use double quotes inside strings in VBScript, you must either escape them by using double double quotes:

objFile.Write "user_pref(""network.proxy.type"", 0);" & vbCrLf

or insert literal double quotes (ASCII character 34) by concatenation:

objFile.Write "user_pref(" & Chr(34) & "network.proxy.type" & Chr(34) _
  & ", 0);" & vbCrLf


来源:https://stackoverflow.com/questions/16022316/expected-end-of-statement-error-in-vbs-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!