Book a Demo

Author Topic: How to make schedule to run the script with Windows Server  (Read 4339 times)

demian824

  • EA User
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
How to make schedule to run the script with Windows Server
« on: July 18, 2024, 02:18:46 am »
Hello I try to make the window service for run the script follow by the Community Site ( Link : https://community.sparxsystems.com/tutorials/603-75ea-as-an-unattended-windows-service-on-windows-server-2008r2-and-higher ).

However, I keep failing to start the service. it occurred the run-time error 1064. I need help to solve this issue!!!

Code on my side
------------------------------
cmdLaunchService.cs:

    public partial class cmdLaunchService : ServiceBase
    {
        static string ProjectGuid;
        public cmdLaunchService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            Process cmdTool = new Process();
            cmdTool.StartInfo.FileName = "cmd.exe";
            cmdTool.Start();
            Console.Write("Start Connecting Sparx Server...");

            EA.App a = new EA.App();
            //EA.Repository repo = new EA.Repository();
            EA.Repository repo = a.Repository;


            if (repo.OpenFile("dev-sparx --- ;Connect=Cloud=protocol:http,address:dev-sparx01.fsrao.ca,port:804;Data Source=DEV-SPARX-EA2;DSN=DEV-SPARX-EA2;"))
            {
                ProjectGuid = "Opened the Repository GUID : " + repo.ProjectGUID + ", Name : Sparx Dev";
            }

            // clean up
            GC.Collect();
            GC.WaitForPendingFinalizers();
            TextWriter tw = new StreamWriter("C:\\temp\\guids.txt");
            // write a line of text to the file, just to have a easy to access info
            tw.WriteLine("Date : " + DateTime.Now + ", Project GUID : " + ProjectGuid);

            // close the stream tw.Close();
            tw.Close();
        }

        protected override void OnStop(){}
    }
ProjectInstaller.cs
partial class ProjectInstaller
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
            this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
            //
            // serviceProcessInstaller1
            //
            this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
            //this.serviceProcessInstaller1.Password = null;
            //this.serviceProcessInstaller1.Username = null;
            //
            // serviceInstaller1
            //
            this.serviceInstaller1.ServiceName = "cmdLauncherService";
            //
            // ProjectInstaller
            //
            this.Installers.AddRange(new System.Configuration.Install.Installer[] {
            this.serviceProcessInstaller1,
            this.serviceInstaller1});

        }

        #endregion

        private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
        private System.ServiceProcess.ServiceInstaller serviceInstaller1;
    }