简体   繁体   English

将变量从C#发送到VBScript

[英]Sending variables from C# to VBScript

is it possible to send variables from C# to a VBScript file? 是否可以将变量从C#发送到VBScript文件? Then send variables back to C# after the script is executed. 然后在脚本执行后将变量发送回C#。

Thank you 谢谢

You can pass command line parameters to a VBScript file, using the windows scripting host (WScript) - see this for details on the VBScript side. 你可以通过命令行参数VBScript文件,使用Windows脚本宿主(WScript的) -看到对VBScript的侧面细节。 On the C# side, you should use Process.Start and pass in the arguments to the script. 在C#端,您应该使用Process.Start并将参数传递给脚本。

There are several options for returning values, though I do not really like any of the ones proposed here . 尽管我真的不喜欢这里提出的任何选择,但有几种返回值的选择。

You can write values out to a file in your VBScript and have the C# read the content of the file. 您可以在VBScript中将值写出到文件中,并让C#读取文件的内容。

If you run the VB script from another process (Process.Start(vbScriptFilePath) etc.) than you can send the variables to the start call, as the command line arguments argument. 如果您从其他进程(Process.Start(vbScriptFilePath)等)运行VB脚本,则可以将变量作为命令行参数参数发送到start调用。 Then, after the process terminates, you can use its ExitCode property. 然后,在进程终止后,可以使用其ExitCode属性。 Note that it enables you to get only one value - so if you want to set more than one C# variables using your VB script, you need to use a file\\ registry keys etc. to do that. 请注意,它使您只能获得一个值-因此,如果要使用VB脚本设置多个C#变量,则需要使用file \\注册表项等来执行此操作。

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

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