编程语言
首页 > 编程语言> > 从C#.ashx运行cscript.exe不会在vbscript文件中执行代码

从C#.ashx运行cscript.exe不会在vbscript文件中执行代码

作者:互联网

编辑

我在.vbs文件中添加了一些错误处理,这确实是权限问题(我现在收到“权限被拒绝错误”).但是,在web.config< impersonate>中提供我的凭据标签似乎没有任何作用.

另外,当尝试通过通过流程向流程提供我的凭据时

p.StartInfo.Password = Misc.CreateSecurityString("password");
p.StartInfo.UserName = "admin";

我收到一个新错误:

cscript.exe – Application error

The application failed to initialize
properly (0xc0000142). Click on OK to
terminate the application.

如果您知道是什么原因,请大声喊出来. (或直接输入…)

感谢您一直以来的帮助!

背景

我正在尝试从自定义处理程序(.ashx)执行.vbs文件. VBScript正在iis 5.1中设置Web应用程序.

到目前为止,以下代码可以正确执行

string sToRun = "C:\CreateIISApplication.vbs" 
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cscript";
p.StartInfo.Arguments = sToRun;
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string sOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();

问题

我的问题是vbscript似乎根本没有运行.当我检查IIS时,未创建我的应用程序.

当我直接从命令提示符运行脚本文件时,一切正常,并且我的应用程序显示在IIS中.

故障排除

我决定在.vbs文件中添加一些echo语句,以确保它正在运行.在命令行上,所有语句均正确输出.当检查字符串sOutput时,我收到标头消息,但随后的消息都没有.

从C#-sOutput的内容

Microsoft (R) Windows Script Host
Version 5.7 Copyright (C) Microsoft
Corporation. All rights reserved

从命令行

Microsoft (R) Windows Script Host
Version 5.7 Copyright (C) Microsoft
Corporation. All rights reserved

Hello

因此,我可以证明(我认为).vbs文件未被评估,并且cscript被调用.如果我在不引用.vbs文件的情况下调用cscript,那么我将获得帮助文档.所以出了点问题.

有任何想法吗?谢谢!

解决方法:

我想象一个问题(也许不是整个问题)是IIS在其下运行的用户没有特权在目标计算机上运行脚本.

标签:ashx,wsh,vbscript,asp-net,c
来源: https://codeday.me/bug/20191209/2096344.html