Winforms 从c中的vbscript函数返回值#
我正在用c#中的代码执行一个.vbs文件,以检查用户的真实性。我正在传递用户名和密码值,并在登录时单击。vbs将运行并验证用户。如果vbs中not authentic then函数中的用户返回一个值,我如何在c#中的代码中获取该值,并使用它在应用程序的UI中显示正确的错误消息。Winforms 从c中的vbscript函数返回值#,winforms,c#-4.0,vbscript,Winforms,C# 4.0,Vbscript,我正在用c#中的代码执行一个.vbs文件,以检查用户的真实性。我正在传递用户名和密码值,并在登录时单击。vbs将运行并验证用户。如果vbs中not authentic then函数中的用户返回一个值,我如何在c#中的代码中获取该值,并使用它在应用程序的UI中显示正确的错误消息。 请帮助..不要显示生产代码,而是显示 这/它“原则上是如何工作的” 您必须在文档中查找哪些关键字/组件 demo.cs: using System; using System.Diagnostics; namespac
请帮助..不要显示生产代码,而是显示
using System;
using System.Diagnostics;
namespace Demo
{
public class Demo
{
public static void Main(string [] args) {
string user = "nix";
if (1 <= args.Length) {user = args[0];};
string passw = "nix";
if (2 <= args.Length) {passw = args[1];};
string cscript = "cscript";
string cmd = string.Format("\"..\\vbs\\auth.vbs\" {0} {1}", user, passw);
System.Console.WriteLine("{0} {1}", cscript, cmd);
Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = "cscript.exe";
process.StartInfo.Arguments = cmd;
try {
process.Start();
System.Console.WriteLine(process.StandardOutput.ReadToEnd());
System.Console.WriteLine(process.ExitCode);
} catch (Exception ex) {
System.Console.WriteLine(ex.ToString());
}
}
}
}
输出:
demo.exe
cscript "..\vbs\auth.vbs" nix nix
fail
1
demo.exe user passw
cscript "..\vbs\auth.vbs" user passw
ok
0
也许您可以通过忘记返回文本而只使用.Exitcode来简化操作。如何运行VBS?你能解释一些代码来澄清吗?Process.Start(“Execute.vbs”);我正在执行vbs文件。我现在需要的是将uname和pwd的值从WinFormUI传递到Execute中的函数,该函数将返回一个字符串值,我必须再次在UI中显示它。
demo.exe
cscript "..\vbs\auth.vbs" nix nix
fail
1
demo.exe user passw
cscript "..\vbs\auth.vbs" user passw
ok
0