/// <exception cref="UnauthorizedAccessException"></exception>
        private BatScriptConfig TryCastToBatScriptConfig(IScriptStorageModel script, RegistryName registryName, MenuLocation location)
        {
            BatScriptConfig newConfig = null;

            try
            {
                IIconReference iconReference = null;
                if (!string.IsNullOrWhiteSpace(script.Icon))
                {
                    iconReference = new IconReference(script.Icon);
                }

                newConfig = new BatScriptConfig(registryName.Name, registryName.ID, settings, messagePrompt, iconPicker)
                {
                    Label = script.Label,
                    Icon  = iconReference
                };

                newConfig.LoadScript();
                newConfig.ModifyLocation(location, true);
            }
            catch (System.Security.SecurityException)
            {
                return(null);
            }
            catch (ObjectDisposedException)
            {
                return(null);
            }
            catch (IOException)
            {
                return(null);
            }
            catch (ScriptAccessException)
            {
                return(null);
            }

            if (script.Command.Length <= 8 || script.Command.Substring(0, 5) != cmd)
            {
                return(null);
            }

            if (script.Command.Substring(7, 2) == BatScriptConfig.keepCMDOpen)
            {
                newConfig.KeepWindowOpen = true;
            }
            else if (script.Command.Substring(7, 2) == BatScriptConfig.closeCMD)
            {
                newConfig.KeepWindowOpen = false;
            }
            else
            {
                return(null);
            }

            return(newConfig);
        }
        private IScriptConfig Generate(ScriptType scriptType, string id)
        {
            IScriptConfig result;

            switch (scriptType)
            {
            case ScriptType.Batch:
                result = new BatScriptConfig(DateTime.UtcNow.Ticks.ToString(), id, settings, messagePrompt, iconPicker);
                break;

            case ScriptType.Powershell:
                result = new PowershellScriptConfig(DateTime.UtcNow.Ticks.ToString(), id, settings, messagePrompt, iconPicker);
                break;

            default:
                throw new ArgumentException($"The scriptType of [{scriptType}] is not valid for the [RegistryWorker]");
            }

            result.Label        = NewScript;
            result.OnBackground = true;
            result.OnDirectory  = true;

            return(result);
        }