Quartz.NET:运行 PHP 命令行会导致 php_mssql.dll 访问被拒绝?

发布于 2024-10-05 09:59:22 字数 2538 浏览 3 评论 0原文

我有一个实现 Quartz.NET 调度的 Windows 服务,它从 XML 文件读取计划作业信息,解析它以供运行的 cmd 行,并使用解析的参数创建计划作业。

我目前正在使用 PHP 命令行脚本来测试调度程序的命令行执行,它似乎很好地启动了作业,它们甚至成功完成,在 eventLog 中显示脚本输出...

问题是每个运行时,会显示一个警告弹出窗口,并显示错误:

“PHP 启动:无法加载动态库 'C:\php5\php_mssql.dll' - 访问被拒绝”

如果我对此警告响应正常,则脚本似乎运行良好,但如果它保留在屏幕上,则进一步计划的 PHP 脚本将运行完成,但输出为空(我假设被之前运行的暂停作业所阻止。)...

如何以编程方式防止访问被拒绝消息?

运行解析的 CMD 行的 Quartz.NET 作业执行脚本如下:

public void Execute(JobExecutionContext context)
    {
        EventLog eventLog = new EventLog();
        eventLog.Source = "SchedulerServiceSource";
        eventLog.Log = "SchedulerService";


        JobDataMap dataMap = context.MergedJobDataMap;  // contanis information for this job parsed from the XML file.
        String jobName = dataMap.GetString("name");
        String execute = dataMap.GetString("execute");
        String args = dataMap.GetString("arguments");

        //String LogMsg = "JobRunner Executing=============\n"; // Written to event log after job execution
        //LogMsg += "JobName: " + jobName + "\n";
        //LogMsg += "Executing: " + execute + "\n";
        // eventLog.WriteEntry(LogMsg); // Write the job's details to the log

        try
        {
            Process p = new Process(); // Start the child process.
            // Redirect the output stream of the child process.
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = execute;
            p.StartInfo.Arguments = args;
            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 output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            eventLog.WriteEntry(jobName + "\nexecuted:\n---------------\n" + execute + " " + args + "\n---------------\nRESULTS:\n===============\n" + output + "\n===============");
        }
        catch (Exception ex)
        {
            eventLog.WriteEntry(jobName + "\nattempted to execute:\n---------------\n" + execute + " " + args + "\n---------------\n...FAILED:\n===============\n" + ex.Message + "\n===============", EventLogEntryType.Error);
        }
    }

提前感谢大家!

编辑:我正在运行的php脚本是一个简单的HELLO WORLD,它不与数据库交互,但我有一种感觉,如果我运行一个使用数据库功能的脚本,它会由于访问被拒绝消息而失败...这也是不能接受的,这个项目我必须能够全力使用PHP!

EDIT2:我使用 Windows LocalService 帐户安装了该服务。

I have a Windows Service implementing Quartz.NET scheduling which reads scheduled job information from an XML file, parses it for a cmd line to run, and creates a scheduled job with the parsed parameters.

I'm currently using PHP command line scripts to test the command line execution of the scheduler, and it seems to be kicking off jobs just fine, and they even complete successfully, showing the script output in the eventLog...

The problem is every time it runs, a Warning popup displays with the error:

"PHP Startup: Unable to load dynamic library 'C:\php5\php_mssql.dll' - Access is denied"

If I respond OK to this warning, the script seems to run fine, but if it remains on screen, further scheduled PHP scripts will run to completion, but the output is empty (I assume held up by the paused job running prior to it.)...

How can I prevent that access denied message programmatically?

The Quartz.NET Job Execution script that runs the parsed CMD line is as follows:

public void Execute(JobExecutionContext context)
    {
        EventLog eventLog = new EventLog();
        eventLog.Source = "SchedulerServiceSource";
        eventLog.Log = "SchedulerService";


        JobDataMap dataMap = context.MergedJobDataMap;  // contanis information for this job parsed from the XML file.
        String jobName = dataMap.GetString("name");
        String execute = dataMap.GetString("execute");
        String args = dataMap.GetString("arguments");

        //String LogMsg = "JobRunner Executing=============\n"; // Written to event log after job execution
        //LogMsg += "JobName: " + jobName + "\n";
        //LogMsg += "Executing: " + execute + "\n";
        // eventLog.WriteEntry(LogMsg); // Write the job's details to the log

        try
        {
            Process p = new Process(); // Start the child process.
            // Redirect the output stream of the child process.
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = execute;
            p.StartInfo.Arguments = args;
            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 output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            eventLog.WriteEntry(jobName + "\nexecuted:\n---------------\n" + execute + " " + args + "\n---------------\nRESULTS:\n===============\n" + output + "\n===============");
        }
        catch (Exception ex)
        {
            eventLog.WriteEntry(jobName + "\nattempted to execute:\n---------------\n" + execute + " " + args + "\n---------------\n...FAILED:\n===============\n" + ex.Message + "\n===============", EventLogEntryType.Error);
        }
    }

Thanks everyone in advance!

EDIT: The php script I'm running is a simple HELLO WORLD which does NOT interact with the Database, but I have a feeling if I DID run one that used DB functionality, it would fail due to the Access Denied msg... This is also unacceptable, and I must be able to use PHP in full capacity for this project!

EDIT2: I have the service installed using a Windows LocalService account.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倒数 2024-10-12 09:59:22

试试这个(从另一个站点的论坛复制)

将以下文件复制到 System32 目录中
1.libmysql.dll
2. msql.dll

将以下文件复制到 php\ext 目录中
1.msql.dll。当您解压 PHP 5 zip 文件时,应该复制此文件,但显然它不会

重新启动网络服务器

Try this (copied from forum on another site)

Copy the following files in System32 directory
1. libmysql.dll
2. msql.dll

Copy the following files in php\ext directory
1. msql.dll . This file should be copied when you extract the PHP 5 zip file, but obviously its not

Restart webserver

昔梦 2024-10-12 09:59:22

事实证明,以 LOCALSYSTEM 身份运行服务可以解决这个问题......

Turns out that running the service as LOCALSYSTEM fixes this problem...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文