简体   繁体   English

vbs语法错误:预期为800A03EE')'

[英]vbs syntax error: 800A03EE ')' expected

I try to execute this in a file called 'addcurrentkey.vbs' But it says ')' is expected in row 1. Character 38. 我尝试在名为“ addcurrentkey.vbs”的文件中执行此操作,但在第1行中应显示“)”。字符38。

I tried this tutorial: http://www.codeproject.com/Articles/16569/Autorun-Applications 我尝试了本教程: http : //www.codeproject.com/Articles/16569/Autorun-Applications

Why can't I execute a .vbs file? 为什么我不能执行.vbs文件?

Private Sub AddCurrentKey(ByVal name As String, ByVal path As String)
Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True) 
key.SetValue(name, path) 
End Sub 

The code you posted is probably written in VB.net (or perhaps VBA). 您发布的代码可能是用VB.net(或VBA)编写的。 You are tying to run the code as VBScript, which does not support typed parameters and variables. 您想将代码作为VBScript运行,它不支持键入的参数和变量。 It also doesn't provide the registry object you're trying to use. 它还不提供您要使用的注册表对象。 Change the procedure from this: 从此更改过程:

Private Sub AddCurrentKey(ByVal name As String, ByVal path As String)
  Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True) 
  key.SetValue(name, path) 
End Sub

to this: 对此:

Private Sub AddCurrentKey(ByVal name, ByVal path)
  Dim key : key = "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"
  CreateObject("WScript.Shell").RegWrite key & "\" & name, path
End Sub

and the problem will disappear. 问题就会消失。

VBScript still uses the "old" Visual Basic syntax. VBScript仍然使用“旧的” Visual Basic语法。 Which distinguishes between function calls used in expressions and procedure calls that are statements. 这区分了表达式中使用的函数调用和作为语句的过程调用。 You use (parentheses) in an expression but not in a statement. 您在表达式中使用(括号),而不在语句中使用。 Fix: 固定:

 key.SetValue name, path 

Or if you prefer: 或者,如果您愿意:

 Call key.SetValue(name, path)

The error message is hard to interpret because the script interpreter thinks that you are trying to write this: 该错误消息很难解释,因为脚本解释器认为您正在尝试编写以下代码:

 key.SetValue (name), path

Which means something completely different. 这意味着完全不同的东西。 VBScript passes arguments ByRef. VBScript传递参数ByRef。 The extra parentheses around name turns it into an expression that creates a copy of the variable. 名称周围多余的括号将其转换为创建变量副本的表达式。 It can be modified by the SetValue procedure without it affecting the name variable. 可以通过SetValue过程对其进行修改,而不会影响name变量。 Not what it actually does nor what you intended. 不是它的实际作用,也不是您的意图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM