private void btnHelpWin7Libraries_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (RPMessageBox.ShowQuestion("If this box is checked, Remote Potato ignores this list and uses the folders in your Windows 7 " + CollectionName + " library instead.\r\n\r\nDo you wish to edit these folders now?", "Help on Windows 7 " + CollectionName + " library") == System.Windows.Forms.DialogResult.Yes) { RPMessageBox.ShowAlert("Remote Potato will open a Windows Explorer window. To add/remove " + CollectionName + " folders, you should look for the heading 'Libraries' in the left-hand column, then right-click the word '" + CollectionName + "' and choose 'Properties'."); string target = "explorer.exe"; System.Diagnostics.Process.Start(target); } }
void AddFirewallRules() { // Add firewall rules if (!FirewallHelper.AddFirewallRules()) { RPMessageBox.ShowAlert("The firewall rules could not be added to Windows Firewall.\r\n\r\nYou may need to manually add incoming and outgoing rules for your ports."); } Settings.Default.HaveOfferedWindowsFirewallForPort = Convert.ToInt32(Settings.Default.RPPortWithLiveTV); }
// Generic Methods - for a named service static bool SetServiceLogon(string ServiceName, string AccountName, string Password, bool PredefinedAccount, ref string ErrorText) { string objPath = string.Format("Win32_Service.Name='{0}'", ServiceName); using (ManagementObject service = new ManagementObject(new ManagementPath(objPath))) { object[] wmiParams = new object[11]; if (PredefinedAccount) { wmiParams[6] = "LocalSystem"; wmiParams[7] = ""; } else { // Must be passed local account syntax - adjust if need be if (!AccountName.Contains("\\")) { AccountName = ".\\" + AccountName; } wmiParams[6] = AccountName; // provided by user wmiParams[7] = Password; // provided by user } object invokeResult = null; try { invokeResult = service.InvokeMethod("Change", wmiParams); //http://msdn.microsoft.com/en-us/library/aa384901 } catch (ManagementException mex) { if (mex.ErrorCode.ToString().Equals("NotFound")) { RPMessageBox.ShowAlert("The Remote Potato Service could not be found - please try re-installing Remote Potato"); } return(false); } catch { return(false); } // Return true if result code is 0 int resultCode; if (!int.TryParse(invokeResult.ToString(), out resultCode)) { ErrorText = "Non-numerical result code from Change() method."; return(false); } ErrorText = ChangeServiceErrorMessage(resultCode); return(resultCode == 0); } }
// SHOW ROUTER SETTINGS private void btnShowRouterSettings_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if ((nathelper == null) || (!nathelper.GatewayFound)) { RPMessageBox.ShowAlert("A compatible router (UPnP) could not be found on your network."); return; } string strMappings = nathelper.ListMappings(); RPMessageBox.Show(strMappings, "Router Port Mappings"); }
private void wizardPages1_Deselecting(object sender, TabControlCancelEventArgs e) { bool ShouldCancel = false; string CancelReason = ""; switch (e.TabPageIndex) { case 0: TryMoveFromStep0(ref ShouldCancel, ref CancelReason); break; case 1: TryMoveFromStep1(ref ShouldCancel, ref CancelReason); break; case 2: TryMoveFromStep2(ref ShouldCancel, ref CancelReason); break; case 3: TryMoveFromStep3(ref ShouldCancel, ref CancelReason); break; case 4: TryMoveFromStep4(ref ShouldCancel, ref CancelReason); break; case 5: TryMoveFromStep5(ref ShouldCancel, ref CancelReason); break; } e.Cancel = ShouldCancel; if (e.Cancel) { string strDisplayReason = (string.IsNullOrWhiteSpace(CancelReason)) ? "A value was incorrect, or left blank.\r\n\r\nPlease check all the values you have entered on this page and try again." : CancelReason; RPMessageBox.ShowAlert(strDisplayReason); // Re-adjust page index if (movingForward) { PageIndex--; } else { PageIndex++; } } }
// Add a folder and refresh box void addFolder(string txtPath) { if (string.IsNullOrEmpty(txtPath)) { return; } if (listviewContainsText(txtPath)) { RPMessageBox.ShowAlert("You have already added this folder."); return; } Folders.Add(txtPath); lvRecTVFolders.Items.Add(txtPath); }
public static void AskThenAddFirewallRules() { if (RPMessageBox.ShowQuestion("Do you use Windows Firewall? If so, we can add rules to your firewall to allow Remote Potato to be accessed over the Internet. You will only ever need to do this once, unless you change port numbers.\r\n\r\nDo you want to do this now?", "Add Firewall Rules?") == DialogResult.No) { return; } if (AddFirewallRules()) { RPMessageBox.Show("The rules were successfully added to Windows Firewall.\r\n\r\nRemember, you do not need to do this again unless you change port numbers."); } else { RPMessageBox.ShowAlert("There was an error adding the rules to Windows Firewall - see debug log for more information.\r\n\r\nClick the 'Re-add firewall rules' button to try this again."); } }
void ReserveURLForLiveTVPort() { URLReserver reserver = new URLReserver(); int ResultCode = reserver.ReserveUrl(Convert.ToInt32(Settings.Default.RPPortWithLiveTV), "/", true); if (ResultCode == 0) { Functions.WriteLineToLogFile("URLReserver: 0 OK"); Settings.Default.LastSetSecurityForLiveTVPort = Convert.ToInt32(Settings.Default.RPPortWithLiveTV); } else { Functions.WriteLineToLogFile("URLReserver: NOT OK"); RPMessageBox.ShowAlert("Could not reserve a Url for Remote Potato server - error code " + ResultCode.ToString()); } }
void AddFolder() { if (lvRecTVFolders.Items.Count > (MAX_FOLDERS - 1)) { RPMessageBox.ShowAlert("You may only add up to " + MAX_FOLDERS.ToString() + " folders."); return; } FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.ShowNewFolderButton = true; if (dialog.ShowDialog() == DialogResult.OK) { addFolder(dialog.SelectedPath); } }
void AddPath() { if (lvRecTVFolders.Items.Count > (MAX_FOLDERS - 1)) { RPMessageBox.ShowAlert("You may only add up to " + MAX_FOLDERS.ToString() + " folders."); return; } FormInputBox fInputBox = new FormInputBox("Add path to folder", "Enter the path to a folder - e.g. \\\\SERVER\\SHARENAME", "\\SERVER\\SHARE_NAME"); if (fInputBox.ShowDialog() == DialogResult.OK) { if (!(string.IsNullOrWhiteSpace(fInputBox.Value))) { addFolder(fInputBox.Value); } } }
static bool SetServiceStartupType(string ServiceName, bool startWithWindows, ref string ErrorText) { string objPath = string.Format("Win32_Service.Name='{0}'", ServiceName); using (ManagementObject service = new ManagementObject(new ManagementPath(objPath))) { object[] wmiParams = new object[1]; wmiParams[0] = startWithWindows ? "Automatic" : "Manual"; object invokeResult = null; try { invokeResult = service.InvokeMethod("ChangeStartMode", wmiParams); //http://msdn.microsoft.com/en-us/library/aa384901 } catch (ManagementException mex) { if (mex.ErrorCode.ToString().Equals("NotFound")) { RPMessageBox.ShowAlert("The Remote Potato Service could not be found - please try re-installing Remote Potato"); } return(false); } catch { return(false); } // Return true if result code is 0 int resultCode; if (!int.TryParse(invokeResult.ToString(), out resultCode)) { ErrorText = "Non-numerical result code from Change() method."; return(false); } ErrorText = ChangeServiceErrorMessage(resultCode); return(resultCode == 0); } }
void TryToChangeMediaLibraryAccount() { lblStatus.Text = "Please wait - making changes..."; Application.DoEvents(); string AccountName = txtMediaLibraryUsername.Text.Trim(); string Password = txtMediaLibraryPassword.Text.Trim(); if (string.IsNullOrEmpty(AccountName)) { lblStatus.Text = "You must enter the details of a user of this machine."; return; } if (string.IsNullOrEmpty(Password)) { // Services require a login with a password if limited in registry see http://stackoverflow.com/questions/1047854/cant-run-a-service-under-an-account-which-has-no-password if (Functions.IsBlankPasswordLimitedOnMachine) { if (RPMessageBox.ShowQuestion("Blank passwords for services are currently limited on this machine.\r\n\r\nDo you wish to lift this security restriction so that Remote Potato can run?", "Allow blank passwords on machine?") == DialogResult.Yes) { Functions.SetBlankPasswordLimitOnMachine(false); } else { RPMessageBox.Show("To allow Remote Potato to run, please use an account that has a Username and a Password"); return; } } } else // re-instate blank password limit? { if (!Functions.IsBlankPasswordLimitedOnMachine) { if (RPMessageBox.ShowQuestion("Blank passwords for services are currently allowed on this machine. Unless you require this security relaxation for other services or remotely access user accounts on this machine that have no password, you should re-enable this security restriction.\r\n\r\nDo you wish to forbid blank passwords for services?", "Forbid blank passwords on machine?") == DialogResult.Yes) { Functions.SetBlankPasswordLimitOnMachine(true); } } } if (!ValidateCredentials(AccountName, Password)) { lblStatus.Text = "The log on details that you entered were incorrect."; return; } //if (!SetServiceLogon("Remote Potato Service", AccountName, Password, true)) return; string strErrorText = string.Empty; if (!ServiceManager.SetRPServiceLogon(AccountName, Password, false, ref strErrorText)) { lblStatus.Text = "Could not use this account - please check the details:" + strErrorText; return; } if (!SetLogOnAsServiceRight(AccountName)) { RPMessageBox.ShowAlert("Could not add required security priviliges to this account - please check that you running as an Administrator, and that you have entered the details correctly."); lblStatus.Text = "Error setting priviliges."; return; } lblStatus.Text = string.Empty; CommitAndClose(); }