vbs文件中声明错误的预期结束 [英] Expected End of Statement error in vbs file

查看:211
本文介绍了vbs文件中声明错误的预期结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我自动完成在Mozilla Firefox上禁用代理服务器的任务(目前它默认为'Automatic proxy config url',手动设置为'无代理服务器')。

经过一番研究之后,我意识到可以通过创建一个user.js文件(覆盖pref.js中存储的firefox设置)来改变设置:

  user_pref(network.proxy.type,0); 

下面是我遇到的vbs语法问题:

  Set objFSO = CreateObject(Scripting.FileSystemObject)

outFile =%APPDATA%\Mozilla\Firefox\Profiles\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\'\\\\\\\' &安培; vbCrLf
objFile.Close

执行vbs文件时,出现这个错误



第5行
字符27
预期结束语
800A0401

任何帮助
谢谢。

解决方案

VBScript字符串由双引号分隔。如果要在VBScript中使用双引号,则必须使用双引号将其转义:

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

或通过连接插入文字双引号(ASCII字符34):

  objFile.Writeuser_pref(& Chr(34)&network.proxy.type& Chr(34)_ 
&,0); &安培; vbCrLf


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.

解决方案

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

这篇关于vbs文件中声明错误的预期结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆