您好,我正在尝试编写一个需要 3 个用户输入的程序:文件路径、用户名和计算机名称,然后为列表中的每个计算机名称创建一个批处理文件。我还没有编写创建批处理文件部分,但是我无法从计算机文本框中取出多台计算机并从中创建单独的代码行。
因此,如果计算机文本框中有 3 个计算机名称,我希望当用户点击按钮时,将每个计算机名称输出到不同的行。
如果计算机名称文本框包含以下计算机名称:M22-LIBRL74258S、M22-LIBRL74257S 和 M22-LIBRL74256S
输出将是:
XCOPY "C:\Documents and Settings\Administrator\Desktop\file.exe" "\M22-LIBRL74258S\c$\Users\username\desktop"
XCOPY "C:\Documents and Settings\Administrator\Desktop\file.exe" "\M22-LIBRL74257S\c$\Users\username\desktop"
XCOPY "C:\Documents and Settings\Administrator\Desktop\file.exe" "\M22-LIBRL74256S\c$\Users\username\desktop"
谢谢!
WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void browsebtn_Click(object sender, EventArgs e)
{
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "Select a File to Send";
// Show the Dialog.
// If the user clicked OK in the dialog and
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
string strfilename = openFileDialog1.InitialDirectory + openFileDialog1.FileName;
pathtxt.Text = strfilename.ToString();
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void createbtn_Click(object sender, EventArgs e)
{
string filepath = pathtxt.Text.ToString();
string username = usertxtbox.Text.ToString();
string computer = computerstxtbox.Text;
string[] split = computer.Split(new char[] { '\n' });
foreach (string l in split)
{
var strIP = "XCOPY \"" + pathtxt.Text + '"' + ' ' + '"' + "\\" + "\\" + l + "\\" + "c$" + "\\" + "Users" + "\\" + username + "\\" + "desktop" + '"';
//This is to see it
MessageBox.Show(strIP);
}