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
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
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;
}
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;