c# Button execute value fro profile

Jan Meeling 0 Reputation points
2023-01-24T15:54:30.0766667+00:00
I want under the button a cmd.exe executen
 
I have unde the properties the following configured:
 <setting name="CMD" serializeAs="String">
                <value>C:\Windows\System32\cmd.exe</value>
            </setting>
			
 string cmd = Properties.Settings.Default.CMD;
 
 private void button1_Click(object sender, EventArgs e)
        {
            string cmd = Properties.Settings.Default.CMD;

        }
		
	I get a error the file can not been found please help
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,275 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Kran2022 386 Reputation points
    2023-01-31T08:24:03.1166667+00:00

    Hi There, you can also try the below approach. using netsh

     
     private static string SetNetwork(
            string nic,
            string ip,
            string subnetMask,
            string gateway,
            string primaryDNS)
            {
                string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "netsh");
                Process.Start(new ProcessStartInfo(fileName)
                {
                    Arguments = string.Format("interface ip set address \"{0}\" static {1} {2} {3}", (object)nic, (object)ip, (object)subnetMask, (object)gateway),
                    CreateNoWindow = true,
                    WindowStyle = ProcessWindowStyle.Hidden
                }).WaitForExit();
                Process.Start(new ProcessStartInfo(fileName)
                {
                    Arguments = string.Format("interface ip set dns \"{0}\" static {1} Primary", (object)nic, (object)primaryDNS),
                    CreateNoWindow = true,
                    WindowStyle = ProcessWindowStyle.Hidden
                }).WaitForExit();
                return string.Empty;
            }
    
    0 comments No comments

  2. Kran2022 386 Reputation points
    2023-01-31T08:35:03.6133333+00:00

    Hi tehre:

    You can try the below approach , you dont need cmd you can use netsh

    
    
    
     private static string SetNetwork(
            string nic,
            string ip,
            string subnetMask,
            string gateway,
            string primaryDNS)
            {
                string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "netsh");
                Process.Start(new ProcessStartInfo(fileName)
                {
                    Arguments = string.Format("interface ip set address \"{0}\" static {1} {2} {3}", (object)nic, (object)ip, (object)subnetMask, (object)gateway),
                    CreateNoWindow = true,
                    WindowStyle = ProcessWindowStyle.Hidden
                }).WaitForExit();
                Process.Start(new ProcessStartInfo(fileName)
                {
                    Arguments = string.Format("interface ip set dns \"{0}\" static {1} Primary", (object)nic, (object)primaryDNS),
                    CreateNoWindow = true,
                    WindowStyle = ProcessWindowStyle.Hidden
                }).WaitForExit();
                return string.Empty;
            }
     Process.Start(new ProcessStartInfo(fileName)
     
                    Arguments = string.Format("interface ip set dns \"{0}\" static {1} Primary", (object)nic, (object)primaryDNS),
                    CreateNoWindow = true,
                    WindowStyle = ProcessWindowStyle.Hidden
                }).WaitForExit();
                return string.Empty;
    
    0 comments No comments