FolderWidget/frmMain.cs
/// <summary>
/// start item as a different user
/// </summary>
start item as a different user
start item as a different user
private void StartProcessAsDifferentUser(object sender, EventArgs e)
        {
            string line = ((sender as MenuItem).GetContextMenu()).SourceControl.Tag.ToString();
            var rowFromTable = (m_iconsData.AsEnumerable().Where(dr => dr.Field<string>("Path") == line).FirstOrDefault()) as DataRow;
            if (string.IsNullOrEmpty(rowFromTable["User"].ToString()) || string.IsNullOrEmpty(rowFromTable["Pass"].ToString()))
            {
                frmRunAsDifferentUser frmRunAs = new frmRunAsDifferentUser(rowFromTable["Path"].ToString());
                frmRunAs.ShowDialog();
                if (frmRunAs.DialogResult == DialogResult.OK)
                {
                    rowFromTable["User"] = frmRunAs.user;
                    rowFromTable["Pass"] = frmRunAs.pass;
                }
                else
                {
                    return;
                }
                bool stopAndRefresh = false;
                string[] parsedPaths = line.Split(',');
                foreach (var path in parsedPaths)
                {
                    if (!File.Exists(path) && !Directory.Exists(path))
                    {
                        this.Visible = false;
                        MessageBox.Show("This file doesn't exists anymore");
                        this.Visible = true;
                        if (!string.IsNullOrEmpty(rowFromTable["Icon"].ToString()))
                        {
                            clsFileManager.DeleteIcon(rowFromTable["Icon"].ToString());
                        }
                        m_iconsData.Rows.Remove(rowFromTable);
                        clsFileManager.ReplaceXMLFile(m_iconsData);
                        stopAndRefresh = true;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(rowFromTable["User"].ToString()) && !string.IsNullOrEmpty(rowFromTable["Pass"].ToString()))
                        {
                            SecureString passSecure = new NetworkCredential("", rowFromTable["Pass"].ToString()).SecurePassword;
                            try
                            {
                                Process.Start(path, rowFromTable["User"].ToString(), passSecure, "localhost");
                            }
                            catch (Exception ex)
                            {
                                this.Visible = false;
                                MessageBox.Show("Wrong Credentials");
                                clsFileManager.WriteError(ex.Message, ex.StackTrace);
                                this.Visible = true;
                            }
                        }
                        else
                        {
                            Process.Start(path);
                        }
                    }
                    if (stopAndRefresh)
                    {
                        break;
                    }
                }
                if (stopAndRefresh)
                {
                    InitFormFilesAndButtons();
                }
            }
        }
private void StartProcessAsDifferentUser ( object sender , EventArgs e ) { string line = ( ( sender as MenuItem ) . GetContextMenu ( ) ) . SourceControl . Tag . ToString ( ) ; var rowFromTable = ( m_iconsData . AsEnumerable ( ) . Where ( dr => dr . Field < string > ( " " ) == line ) . FirstOrDefault ( ) ) as DataRow ; if ( string . IsNullOrEmpty ( rowFromTable [ " " ] . ToString ( ) ) || string . IsNullOrEmpty ( rowFromTable [ " " ] . ToString ( ) ) ) { frmRunAsDifferentUser frmRunAs = new frmRunAsDifferentUser ( rowFromTable [ " " ] . ToString ( ) ) ; frmRunAs . ShowDialog ( ) ; if ( frmRunAs . DialogResult == DialogResult . OK ) { rowFromTable [ " " ] = frmRunAs . user ; rowFromTable [ " " ] = frmRunAs . pass ; } else { return ; } bool stopAndRefresh = false ; string [ ] parsedPaths = line . Split ( ' ' ) ; foreach ( var path in parsedPaths ) { if ( ! File . Exists ( path ) && ! Directory . Exists ( path ) ) { this . Visible = false ; MessageBox . Show ( " " ) ; this . Visible = true ; if ( ! string . IsNullOrEmpty ( rowFromTable [ " " ] . ToString ( ) ) ) { clsFileManager . DeleteIcon ( rowFromTable [ " " ] . ToString ( ) ) ; } m_iconsData . Rows . Remove ( rowFromTable ) ; clsFileManager . ReplaceXMLFile ( m_iconsData ) ; stopAndRefresh = true ; } else { if ( ! string . IsNullOrEmpty ( rowFromTable [ " " ] . ToString ( ) ) && ! string . IsNullOrEmpty ( rowFromTable [ " " ] . ToString ( ) ) ) { SecureString passSecure = new NetworkCredential ( " " , rowFromTable [ " " ] . ToString ( ) ) . SecurePassword ; try { Process . Start ( path , rowFromTable [ " " ] . ToString ( ) , passSecure , " " ) ; } catch ( Exception ex ) { this . Visible = false ; MessageBox . Show ( " " ) ; clsFileManager . WriteError ( ex . Message , ex . StackTrace ) ; this . Visible = true ; } } else { Process . Start ( path ) ; } } if ( stopAndRefresh ) { break ; } } if ( stopAndRefresh ) { InitFormFilesAndButtons ( ) ; } } }
start item as a different user
start item as a different user
sender
object
e
EventArgs