Hello i’m trying to write a program that takes 3 user inputs: file path, username, and computer name and then create a batch file for each computer name in the list. I have not written the create batch file part yet but I am having trouble taking the multiple computers from the computer text box and creating separate lines of code out of them.
So if there are 3 computer names inside the computer textbox, id like to when the user hits the button, output each computer name on a different line.
if the computer name textbox contained the following computer names: M22-LIBRL74258S, M22-LIBRL74257S, and M22-LIBRL74256S
the output would be :
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”
Thanks!
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);
}
Try and replace the line
with this instead
Also if your computer names are seperated by commas, you must also specify them in the split. e.g. new String[] {“\r\n”, “,”}