vbs syntax error: 800A03EE ')' expected

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I try to execute this in a file called 'addcurrentkey.vbs' But it says ')' is expected in row 1. Character 38.

I tried this tutorial: http://www.codeproject.com/Articles/16569/Autorun-Applications

Why can't I execute a .vbs file?

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  

回答1:

The code you posted is probably written in VB.net (or perhaps VBA). You are tying to run the code as VBScript, which does not support typed parameters and variables. 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.



回答2:

VBScript still uses the "old" Visual Basic syntax. 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. 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. Not what it actually does nor what you intended.



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