5

作成した C# サービス内からシェル コマンドを実行しようとしています。ただし、このコマンドは実行されないようです。ただし、標準のコンソール アプリケーションとしては完全に機能するため、コマンド自体やコード内での実行方法に問題がないことはわかっています。なぜこれがうまくいかないのか、誰か教えてもらえますか?私はC#にかなり慣れていないので、これは私の経験不足の問題かもしれないことに注意してください。以下は、サービス自体のコードです。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;

namespace AdapterDisableTest
{
    class Program : ServiceBase
    {
        //private static Timer workTimer;

        static void Main(string[] args)
        {
            ServiceBase.Run(new Program());
        }

        public Program()
        {
            this.ServiceName = "AdapterDisableTest";
        }

        protected override void OnStart(string[] args)
        {
            base.OnStart(args);

            Process myProcess = new Process();

            myProcess.StartInfo.FileName = @"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe";
            myProcess.StartInfo.Arguments = "controlvm test setlinkstate1 off";
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.CreateNoWindow = true;
            myProcess.Start();

        }

        protected override void OnStop()
        {
            base.OnStop();

            //TODO: clean up any variables and stop any threads
        }

    }
}
4

2 に答える 2