/// <exception cref="UnauthorizedAccessException"></exception> private PowershellScriptConfig TryCastToPowershellScriptConfig(IScriptStorageModel script, RegistryName registryName, MenuLocation location) { PowershellScriptConfig newConfig = null; try { IIconReference iconReference = null; if (!string.IsNullOrWhiteSpace(script.Icon)) { iconReference = new IconReference(script.Icon); } newConfig = new PowershellScriptConfig(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 <= 12 || script.Command.Substring(0, 12) != powershell) { return(null); } newConfig.KeepWindowOpen = script.Command.Contains(PowershellScriptConfig.noExit); 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); }