Click here to Skip to main content
15,908,931 members
Home / Discussions / C#
   

C#

 
GeneralRe: component Pin
PIEBALDconsult4-Dec-10 8:31
mvePIEBALDconsult4-Dec-10 8:31 
AnswerRe: component Pin
RaviRanjanKr15-Dec-10 17:48
professionalRaviRanjanKr15-Dec-10 17:48 
Questionindex of items in CheckedListBox Pin
navidsoft4-Dec-10 1:50
professionalnavidsoft4-Dec-10 1:50 
AnswerRe: index of items in CheckedListBox Pin
Abhinav S4-Dec-10 2:05
Abhinav S4-Dec-10 2:05 
AnswerRe: index of items in CheckedListBox Pin
Luc Pattyn4-Dec-10 2:07
sitebuilderLuc Pattyn4-Dec-10 2:07 
QuestionDatagrid view's Event Control Pin
toetoeag3-Dec-10 21:04
toetoeag3-Dec-10 21:04 
AnswerRe: Datagrid view's Event Control Pin
Eddy Vluggen4-Dec-10 2:25
professionalEddy Vluggen4-Dec-10 2:25 
QuestionHow to return an environment variable? [modified] Pin
turbosupramk33-Dec-10 7:16
turbosupramk33-Dec-10 7:16 
I cannot get my environment variables to return a value in the message box in this example, but it works fine with things like "ipconfig" ... any idea as to why?


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;


namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string testSession = ExecuteCommandSync("sessionname");
            MessageBox.Show(testSession);
        }
        public string ExecuteCommandSync(object command)
        {
            try
            {
                // create the ProcessStartInfo using "cmd" as the program to be run,
                // and "/c " as the parameters.
                // Incidentally, /c tells cmd that we want it to execute the command that follows,
                // and then exit.
                System.Diagnostics.ProcessStartInfo procStartInfo =
                    new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
                
                // The following commands are needed to redirect the standard output.
                // This means that it will be redirected to the Process.StandardOutput StreamReader.
                procStartInfo.RedirectStandardOutput = true;
                procStartInfo.UseShellExecute = false;
                // Do not create the black window.
                procStartInfo.CreateNoWindow = false;
                // Now we create a process, assign its ProcessStartInfo and start it
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo = procStartInfo;
                proc.Start();
                // Get the output into a string
                string result = proc.StandardOutput.ReadToEnd();
                //string result2 = System.Diagnostics.ProcessStartInfo( //procStartInfo("cmd", "/c " + command);
                return (result);
                // Display the command output.
                
            }
            catch (Exception objException)
            {
                // Log the exception
                return("failure");
            }
        }

    }
}


modified on Friday, December 3, 2010 4:50 PM

AnswerRe: How to return an environment variable? Pin
turbosupramk33-Dec-10 9:48
turbosupramk33-Dec-10 9:48 
AnswerRe: How to return an environment variable? Pin
T M Gray3-Dec-10 10:40
T M Gray3-Dec-10 10:40 
GeneralRe: How to return an environment variable? Pin
turbosupramk33-Dec-10 11:27
turbosupramk33-Dec-10 11:27 
AnswerRe: How to return an environment variable? Pin
Ian Shlasko3-Dec-10 10:52
Ian Shlasko3-Dec-10 10:52 
GeneralRe: How to return an environment variable? Pin
turbosupramk33-Dec-10 11:28
turbosupramk33-Dec-10 11:28 
AnswerRe: How to return an environment variable? Pin
PIEBALDconsult3-Dec-10 11:13
mvePIEBALDconsult3-Dec-10 11:13 
GeneralRe: How to return an environment variable? Pin
turbosupramk33-Dec-10 11:29
turbosupramk33-Dec-10 11:29 
AnswerRe: How to return an environment variable? Pin
Dr.Walt Fair, PE3-Dec-10 13:25
professionalDr.Walt Fair, PE3-Dec-10 13:25 
GeneralRe: How to return an environment variable? Pin
turbosupramk33-Dec-10 14:03
turbosupramk33-Dec-10 14:03 
GeneralRe: How to return an environment variable? Pin
Dr.Walt Fair, PE3-Dec-10 14:24
professionalDr.Walt Fair, PE3-Dec-10 14:24 
GeneralRe: How to return an environment variable? Pin
turbosupramk33-Dec-10 18:33
turbosupramk33-Dec-10 18:33 
GeneralRe: How to return an environment variable? Pin
Dr.Walt Fair, PE3-Dec-10 19:52
professionalDr.Walt Fair, PE3-Dec-10 19:52 
QuestionPrevent class member circular initialization? Pin
frattaro3-Dec-10 5:01
frattaro3-Dec-10 5:01 
AnswerRe: Prevent class member circular initialization? Pin
_Erik_3-Dec-10 5:22
_Erik_3-Dec-10 5:22 
AnswerRe: Prevent class member circular initialization? PinPopular
Luc Pattyn3-Dec-10 5:22
sitebuilderLuc Pattyn3-Dec-10 5:22 
GeneralRe: Prevent class member circular initialization? Pin
Dalek Dave3-Dec-10 5:33
professionalDalek Dave3-Dec-10 5:33 
GeneralRe: Prevent class member circular initialization? Pin
frattaro3-Dec-10 5:58
frattaro3-Dec-10 5:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.