如何在按钮中的C#中使用.bat [英] How can I user .bat in C# in button
问题描述
嗨
我有.bat文件,代码是
Hi
I have file .bat the code is
@ echo off
color 2b
echo Enter computer IP
@ echo off
set userin=
set/p userin= Please Enter Computer IP;
psshutdown -r %userin% -u sstuser3 -p user123
pause "Your computer restarted"
我想通过单击buttom
将这段代码放在Visual Studio C#中
如何使用该代码,如何在此代码中直接添加IP计算机
I want put this code in visual studio C# by click on buttom
how can I use that and can I add IP computer in this code to be direct
psshutdown -r %userin% -u sstuser3 -p user123 \\192.168.1.x
重新启动PC
我尝试过的事情:
使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间WindowsFormsApplication4
{
公共局部类Form1:Form
{
公共Form1()
{
InitializeComponent();
}
private void button1_Click(对象发送者,EventArgs e)
{
@回声关闭
颜色2b
echo输入计算机IP
@回声关闭
设置userin =
set/p userin =请输入计算机IP;
psshutdown-r%userin%-u sstuser3-p user123
暂停您的计算机已重新启动"
}
}
}
to restart PC
What I have tried:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
@ echo off
color 2b
echo Enter computer IP
@ echo off
set userin =
set / p userin = Please Enter Computer IP;
psshutdown - r % userin % -u sstuser3 - p user123
pause "Your computer restarted"
}
}
}
推荐答案
不确定确切的用途,但是您可能需要使用 ^ ].
Not sure exactly what use this would be, but you probably need to use the Process Class (System.Diagnostics)[^].
I认为您正在寻找一种从GUI执行.bat文件的方法.是吗?
您是否尝试过:
I think you are looking for a way to execute a .bat file from GUI. Is it?
Do you tried like:
System.Diagnostics.Process.Start(@"path_of_your_.bat_file");
另请参阅:
.net-如何在其中运行批处理文件C#GUI表单-堆栈溢出 [
Also see:
.net - How to run a batch file within a C# GUI form - Stack Overflow[^]
这篇关于如何在按钮中的C#中使用.bat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!