示例#1
0
        private bool ExecuteFile(GCInterface gcInterface, DeviceFileType type, bool wait)
        {
            switch (type)
            {
            case DeviceFileType.StartScript:
                return(ServiceControl.SetServiceStatus(gcInterface.InterfaceName, AdapterStatus.Running));

            case DeviceFileType.StopScript:
                return(ServiceControl.SetServiceStatus(gcInterface.InterfaceName, AdapterStatus.Stopped));
            }

            // map type
            DeviceFileType t = type;

            if (type == DeviceFileType.InstallScript ||
                type == DeviceFileType.UninstallScript)
            {
                t = DeviceFileType.ServiceAssembly;
            }

            // find script
            DeviceFile file = gcInterface.Directory.Files.FindFirstFile(t);

            if (file == null)
            {
                GCError.SetLastError("Cannot find file : " + t.ToString() + " in " + gcInterface.ToString());
                return(false);
            }

            // find installer
            DeviceFile installer = gcInterface.Directory.Files.FindFirstFile(DeviceFileType.Installer);

            if (installer == null)
            {
                GCError.SetLastError("Cannot find installer in " + gcInterface.ToString());
                return(false);
            }

            ProcessControl pc              = new ProcessControl();
            string         exefilename     = ConfigHelper.GetFullPath(gcInterface.FolderPath + "\\" + file.Location);
            string         installfilename = ConfigHelper.GetFullPath(gcInterface.FolderPath + "\\" + installer.Location);

            switch (type)
            {
            case DeviceFileType.ConfigAssembly:
                return(ProcessControl.ExecuteAssemblyDirectly(exefilename, AdapterConfigArgument.InIMWizard));

            case DeviceFileType.MonitorAssembly:
                return(ProcessControl.ExecuteAssemblyDirectly(exefilename, ""));

            case DeviceFileType.InstallScript:
                return(pc.ExecuteAssembly(installfilename, "\"" + exefilename + "\"", true));

            case DeviceFileType.UninstallScript:
                return(pc.ExecuteAssembly(installfilename, "-u \"" + exefilename + "\"", true));
            }

            return(false);
        }
示例#2
0
        // execute scripts
        // Notics: Cisco Security Agent will block this function
        //[Obsolete("Execute scripts. Notics: Cisco Security Agent may block this function.", false)]
        private bool ExecuteCommand(GCInterface gcInterface, CommandType type, bool wait)
        {
            // find script
            Command[] cmdList = gcInterface.Directory.Commands.FindCommands(type);
            if (cmdList != null && cmdList.Length > 0)
            {
                // run script
                foreach (Command cmd in cmdList)
                {
                    string exefilename = ConfigHelper.GetFullPath(gcInterface.FolderPath + "\\" + cmd.Path);
                    if (wait)
                    {
                        ProcessControl pc = new ProcessControl();
                        if (!pc.ExecuteAssembly(exefilename, cmd.Argument))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (!ProcessControl.ExecuteAssemblyDirectly(exefilename, cmd.Argument))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }