Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从C#dotnet核心API触发VBScript_C#_Vbscript_Permissions_Asp.net Core Webapi - Fatal编程技术网

从C#dotnet核心API触发VBScript

从C#dotnet核心API触发VBScript,c#,vbscript,permissions,asp.net-core-webapi,C#,Vbscript,Permissions,Asp.net Core Webapi,我有一个ASP.NET核心API在应用服务器的IIS中运行,它需要能够触发一系列VBScript来打开、填充和打印大量文档。API使用的应用程序池将其标识设置为具有成功运行脚本所需权限的域用户,Fooser。如果我以该用户身份登录并运行脚本Bar.vbs,它将成功执行 但是,当我尝试使用过程从API运行Bar.vbs时,它在尝试打开模板文档时失败。我在WScript.NetworkUsername属性的Bar.vbs中添加了一些日志记录,果然是Fooser(或我设置的任何用户) C:\Compa

我有一个ASP.NET核心API在应用服务器的IIS中运行,它需要能够触发一系列VBScript来打开、填充和打印大量文档。API使用的应用程序池将其标识设置为具有成功运行脚本所需权限的域用户,
Fooser
。如果我以该用户身份登录并运行脚本
Bar.vbs
,它将成功执行

但是,当我尝试使用
过程从API运行
Bar.vbs
时,它在尝试打开模板文档时失败。我在
WScript.Network
Username
属性的
Bar.vbs
中添加了一些日志记录,果然是
Fooser
(或我设置的任何用户)

C:\Company\CompanyDocuments\Scripts\Bar.vbs
如下所示:

' -- Script Start

Set logShell = CreateObject("WScript.Shell")
Set objWord = OpenWord("C:\Company\CompanyDocuments\test.doc")
Set EVENT_INFORMATION = 4

' -- Script End

Function OpenWord(wrdDoc2Open)
Dim Word
Const wdDialogFilePrintSetup = 97
Set Word = CreateObject("Word.Application")
logShell.LogEvent EVENT_INFORMATION, "Test 1: opened word"
Word.Visible= True
' Set Options in Word to try to speed up document processing.
With Word.Options
        .CheckSpellingAsYouType = False
        .CheckGrammarAsYouType = False
        .SuggestSpellingCorrections = False
        .SuggestFromMainDictionaryOnly = False
        .CheckGrammarWithSpelling = False
        .ShowReadabilityStatistics = False
End With
logShell.LogEvent EVENT_INFORMATION, "Test 2: opening document " & wrdDoc2Open
logShell.LogEvent EVENT_INFORMATION, "Test 2.1: User" & CreateObject("WScript.Network").UserName

Set g_objDoc = Word.documents.Open(wrdDoc2Open,,True)

If Err Then 
    logShell.LogEvent EVENT_INFORMATION, "Test Error."
End If

logShell.LogEvent EVENT_INFORMATION, "Test 3: opened document"
Set OpenWord = Word
End Function
API正在运行的流程是:

var scriptProcess = new Process
{
    StartInfo =
    {
        FileName = @"cscript",
        WorkingDirectory = scriptsPath.ToString(),
        WindowStyle = ProcessWindowStyle.Normal,
        Arguments = $"//B //Nologo {fileName} {(arguments.Count != 0 ? string.Join(' ', arguments) : string.Empty)}"
    }
};
scriptProcess.Start();
scriptProcess.WaitForExit();
scriptProcess.Close();
进程正在成功启动脚本,但脚本在未到达
“测试错误”
“测试3:打开的文档”
语句的情况下失败

这是与遗留系统集成,因此更换vbs的工作量太大