簡體   English   中英

在 IIS 服務器上運行 bat 文件

[英]Running bat file on IIS server

我正在嘗試在帶有 iis 版本 6.1 SP1 的 Windows Server 2008 R2 64 位上運行 .bat 文件。 在我的本地機器上一切順利,但在服務器上沒有任何反應,除了創建的進程(cms.exe *32)。

從我的搜索來看,主要問題是權限。 我在幾個地方讀到,出於安全原因,默認情況下的 iis 會阻止對批處理文件的訪問。 我確實理解這個問題,但在我的情況下不會有安全問題,所以我想仍然運行我的文件。


我發現的解決方案是通過實現模擬來傳遞的,這意味着:

1- 更改 web.config -> 身份 impersonate="true"

2- 更改 iis 站點身份驗證 -> ASP.NET Impersonation Enabled

3- 授予文件和文件夾的權限

4- 甚至嘗試了不同版本的步驟 1 -> identity impersonate="true" userName= * ** 密碼= ** * *


授予 IIS 用戶權限:

1- 設置允許服務與 IIS 管理服務上的桌面交互


要調用批處理,我在 c# 中使用以下代碼:

private void startPervasive(string npu)
    {
        try
        {
            ProcessStartInfo startInfo = new     ProcessStartInfo(ConfigurationManager.AppSettings.Get("PervasivePath"));
            //startInfo.UseShellExecute = true;
            //startInfo.WorkingDirectory = ConfigurationManager.AppSettings.Get("PervasiveWorkingPath");
            //startInfo.WindowStyle = ProcessWindowStyle.Normal;
            //startInfo.RedirectStandardInput = true;
            //startInfo.RedirectStandardError = true;
            //startInfo.RedirectStandardOutput = true;
            ////startInfo.FileName = ConfigurationManager.AppSettings.Get("PervasivePath");
            startInfo.Arguments = npu;
            Process myProcess = Process.Start(startInfo);
            //StreamReader sr = File.OpenText(ConfigurationManager.AppSettings.Get("PervasivePath"));
            //StreamWriter sw = myProcess.StandardInput;
            //while (sr.Peek() != -1)
            //{
            //    string readed = sr.ReadLine();
            //    readed = readed.Replace("%1", npu);
            //    sw.WriteLine(readed + Environment.NewLine);
            //}

            ////myProcess.WaitForExit();
            //myProcess.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }

還應該注意的是,我嘗試執行其他文件,包括 .exe 文件,但沒有結果。

感謝您對所描述步驟的任何建議、幫助和/或更正。

這可能不是您想要的,但可能會有所幫助。 我建議您在服務器上創建一個計划任務來運行 BAT 文件,您可以設置用戶權限,然后安排您希望何時運行它。

希望這可以幫助。

下面是另一篇 Stackoverflow 文章的鏈接,該文章似乎對同一問題有非常詳細的回應。

IIS7 不啟動我的 Exe 文件...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM