/// <summary>Elevates the process with administrative rights.</summary> /// <param name="processName">Name of the process.</param> /// <exception cref="ArgumentNullException"></exception> public void ElevateProcessWithAdministrativeRights(string processName) { WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); bool hasAdministrativeRights = principal.IsInRole(WindowsBuiltInRole.Administrator); if (string.IsNullOrEmpty(processName)) { throw new ArgumentNullException(); } if (!hasAdministrativeRights) { ProcessStartInfo process = new ProcessStartInfo(); process.Verb = "runas"; process.FileName = processName; try { Process.Start(process); } catch (Win32Exception e) { KryptonMessageBoxExtended.Show($"Error: { e.Message }", "An Error has Occurred", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } }
private void kbtnDisconnect_Click(object sender, EventArgs e) { UpdateStatus("Disconnecting drive..."); try { //unmap the drive _networkDrives.Force = kcbForceDisConnection.Checked; _networkDrives.LocalDrive = kcmbDriveLetter.Text; _networkDrives.UnMapDrive(); //update status UpdateStatus("Drive disconnection successful"); } catch (Exception err) { //report error UpdateStatus("Cannot disconnect drive! - " + err.Message); KryptonMessageBoxExtended.Show(this, "Cannot disconnect drive!\nError: " + err.Message); } _networkDrives = null; }
private void KbtnLoadColourPalette_Click(object sender, EventArgs e) { using (FileDialog fd = new OpenFileDialog { Filter = PaletteSerializer.DefaultOpenFilter, DefaultExt = "pal", Title = "Open a custom palette file:" }) { if (fd.ShowDialog(this) == DialogResult.OK) { try { Cyotek.Windows.Forms.IPaletteSerializer serializer; serializer = Cyotek.Windows.Forms.PaletteSerializer.GetSerializer(fd.FileName); if (serializer != null) { ColorCollection colours; if (!serializer.CanRead) { throw new InvalidOperationException("Serializer does not support reading palettes."); } using (FileStream fs = File.OpenRead(fd.FileName)) { colours = serializer.Deserialize(fs); } if (colours != null) { while (colours.Count > 96) { colours.RemoveAt(colours.Count - 1); } while (colours.Count < 96) { colours.Add(Color.White); } cgColourPalette.Colors = colours; } } else { KryptonMessageBoxExtended.Show("Sorry, unable to open palette, the file format is not supported or is not recognized.", "Load Palette", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception exc) { KryptonMessageBoxExtended.Show($@"Sorry, unable to open palette. { exc.GetBaseException().Message }", "Load Palette", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public virtual void FindNext(string pattern) { try { RegexOptions opt = kcbMatchCase.Checked ? RegexOptions.None : RegexOptions.IgnoreCase; if (!kcbRegex.Checked) { pattern = Regex.Escape(pattern); } if (kcbMatchWholeWord.Checked) { pattern = "\\b" + pattern + "\\b"; } // Range range = _textBox.Selection.Clone(); range.Normalize(); // if (_firstSearch) { _startPlace = range.Start; _firstSearch = false; } // range.Start = range.End; if (range.Start >= _startPlace) { range.End = new Place(_textBox.GetLineLength(_textBox.LinesCount - 1), _textBox.LinesCount - 1); } else { range.End = _startPlace; } // foreach (var r in range.GetRangesByLines(pattern, opt)) { _textBox.Selection = r; _textBox.DoSelectionVisible(); _textBox.Invalidate(); return; } // if (range.Start >= _startPlace && _startPlace > Place.Empty) { _textBox.Selection.Start = new Place(0, 0); FindNext(pattern); return; } KryptonMessageBoxExtended.Show("Not found"); } catch (Exception ex) { } }
}//getMACAddress() private IPAddress GetIPByName(string strMachineName) { try { IPHostEntry hostInfo = Dns.GetHostEntry(strMachineName); return(hostInfo.AddressList[0]); } catch (Exception ex) { KryptonMessageBoxExtended.Show("Unable to connect with the system: " + strMachineName); throw ex; } }//getIPByName()
private void HotkeysEditorWindow_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult == DialogResult.OK) { var actions = GetUnAssignedActions(); if (!string.IsNullOrEmpty(actions)) { if (KryptonMessageBoxExtended.Show("Some actions are not assigned!\r\nActions: " + actions + "\r\nPress Yes to save and exit, press No to continue editing", "Some actions is not assigned", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No) { e.Cancel = true; } } } }
private void RandomPasswordGenerator_FormClosing(object sender, FormClosingEventArgs e) { if (ktxtOutput.Text != null) { DialogResult result = KryptonMessageBoxExtended.Show($"There is a password of: '{ ktxtOutput.Text }' still in the field. Do you want to exit?", "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Information, messageboxTypeface: new Font("Segoe UI", 12)); if (result == DialogResult.Yes) { Close(); } else { return; } } }
private void kbtnMapDrive_Click(object sender, EventArgs e) { UpdateStatus($"Mapping '{ ktxtShareAddress.Text }' to drive '{ kcmbDriveLetter.Text }'"); try { _networkDrives.Force = kcbForceDisConnection.Checked; _networkDrives.Persistent = kcbPersistantConnection.Checked; _networkDrives.LocalDrive = kcmbDriveLetter.Text; _networkDrives.PromptForCredentials = kcbPromptForCredentials.Checked; _networkDrives.ShareName = ktxtShareAddress.Text; _networkDrives.SaveCredentials = kcbSaveCredentials.Checked; if (ktxtUsername.Text == "" && ktxtPassword.Text == "") { _networkDrives.MapDrive(); } else if (ktxtUsername.Text == "") { _networkDrives.MapDrive(ktxtPassword.Text); } else { _networkDrives.MapDrive(ktxtUsername.Text, ktxtPassword.Text); } UpdateStatus("Drive mapping was successful!"); } catch (Exception exc) { UpdateStatus($"Cannot map drive! - { exc.Message }"); KryptonMessageBoxExtended.Show(this, "Cannot map drive!\nError: " + exc.Message); } _networkDrives = null; }
private void NodeViewer_Load(object sender, EventArgs e) { //create a new NetworkNodeBrowser object, and get the //list of network computers it found, and add each //entry to the combo box on this form try { NetworkNodeBrowser nb = new NetworkNodeBrowser(); foreach (string pc in nb.GetNetworkComputers()) { kcmbNodeList.Items.Add(pc); } } catch (Exception ex) { KryptonMessageBoxExtended.Show($"An error occurred trying to access the network computers.\n\n\n{ ex.Message }", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Initialises a new instance of the <see cref="ToolStripMenuItemUACSheld"/> class. /// </summary> public ToolStripMenuItemUACSheld() : base() { _globalMethods.CheckIfTargetPlatformIsSupported(true); if (_globalMethods.GetIsTargetPlatformSupported()) { if (!_isSystemAbleToLoadShield.HasValue || _isSystemAbleToLoadShield.Value) { try { var _icon = IconExtractor.LoadIcon(IconExtractor.IconType.SHIELD, SystemInformation.SmallIconSize); if (_icon != null) { Image = _icon.ToBitmap(); TextImageRelation = TextImageRelation.ImageBeforeText; ImageAlign = ContentAlignment.MiddleCenter; _isSystemAbleToLoadShield = true; return; } else { _isSystemAbleToLoadShield = false; } } catch (Exception exc) { KryptonMessageBoxExtended.Show($"Your platform is unsupported. Please contact the software vendor for details.\nFor reference, your system is running: { _globalMethods.GetOSFriendlyName() }.\nException message: { exc.Message }.", "Unsupported Software", MessageBoxButtons.OK, MessageBoxIcon.Error); _isSystemAbleToLoadShield = false; } } //NativeMethods.SendMessage(Handle, BCM_SETSHIELD, IntPtr.Zero, new IntPtr(1)); } }
private void KbtnSaveColourPalette_Click(object sender, EventArgs e) { using (FileDialog fd = new SaveFileDialog { Filter = PaletteSerializer.DefaultSaveFilter, DefaultExt = "pal", Title = "Save custom palette as:" }) { if (fd.ShowDialog(this) == DialogResult.OK) { Cyotek.Windows.Forms.IPaletteSerializer serializer; serializer = Cyotek.Windows.Forms.PaletteSerializer.AllSerializers.Where(s => s.CanWrite).ElementAt(fd.FilterIndex - 1); if (serializer != null) { if (!serializer.CanWrite) { throw new InvalidOperationException("Serializer does not support writing palettes."); } } try { using (FileStream fs = File.OpenWrite(fd.FileName)) { serializer.Serialize(fs, cgColourPalette.Colors); } } catch (Exception exc) { KryptonMessageBoxExtended.Show($@"Sorry, unable to save palette. { exc.GetBaseException().Message }", "Save Palette", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { KryptonMessageBoxExtended.Show("Sorry, unable to save palette, the file format is not supported or is not recognised.", "Save Palette", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
/// <summary> /// Uses the DllImport : NetServerEnum with all its required parameters /// (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/netserverenum.asp /// for full details or method signature) to retrieve a list of domain SV_TYPE_WORKSTATION /// and SV_TYPE_SERVER PC's /// </summary> /// <returns>Arraylist that represents all the SV_TYPE_WORKSTATION and SV_TYPE_SERVER /// PC's in the Domain</returns> public ArrayList GetNetworkComputers() { //local fields ArrayList networkComputers = new ArrayList(); const int MAX_PREFERRED_LENGTH = -1; int SV_TYPE_WORKSTATION = 1; int SV_TYPE_SERVER = 2; IntPtr buffer = IntPtr.Zero; IntPtr tmpBuffer = IntPtr.Zero; int entriesRead = 0; int totalEntries = 0; int resHandle = 0; int sizeofINFO = Marshal.SizeOf(typeof(_SERVER_INFO_100)); try { //call the DllImport : NetServerEnum with all its required parameters //see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/netserverenum.asp //for full details of method signature int ret = NetServerEnum(null, 100, ref buffer, MAX_PREFERRED_LENGTH, out entriesRead, out totalEntries, SV_TYPE_WORKSTATION | SV_TYPE_SERVER, null, out resHandle); //if the returned with a NERR_Success (C++ term), =0 for C# if (ret == 0) { //loop through all SV_TYPE_WORKSTATION and SV_TYPE_SERVER PC's for (int i = 0; i < totalEntries; i++) { //get pointer to, Pointer to the buffer that received the data from //the call to NetServerEnum. Must ensure to use correct size of //STRUCTURE to ensure correct location in memory is pointed to tmpBuffer = new IntPtr((int)buffer + (i * sizeofINFO)); //Have now got a pointer to the list of SV_TYPE_WORKSTATION and //SV_TYPE_SERVER PC's, which is unmanaged memory //Needs to Marshal data from an unmanaged block of memory to a //managed object, again using STRUCTURE to ensure the correct data //is marshalled _SERVER_INFO_100 svrInfo = (_SERVER_INFO_100) Marshal.PtrToStructure(tmpBuffer, typeof(_SERVER_INFO_100)); //add the PC names to the ArrayList networkComputers.Add(svrInfo.sv100_name); } } } catch (Exception ex) { KryptonMessageBoxExtended.Show($"Problem with accessing network computers in NetworkBrowser\r\n\r\n\r\n{ ex.Message }", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } finally { //The NetApiBufferFree function frees //the memory that the NetApiBufferAllocate function allocates NetApiBufferFree(buffer); } //return entries found return(networkComputers); }
private static void FailLaunch(string value) => KryptonMessageBoxExtended.Show($"'{ value }' failed to launch.\nPlease check if this file exists before proceeding.");
public void ShowError(string message, string description) { KryptonMessageBoxExtended.Show(message, description, MessageBoxButtons.OK, MessageBoxIcon.Error); }
private void kbtnGetDetails_Click(object sender, EventArgs e) { KryptonMessageBoxExtended.Show(AssemblyManager.GetFileVersionInformation(ktxtFilePath.Text).ToString()); }