Question

I am trying copy a file via xcopy under startup. But it doesn't work.

Here is code:

System.Diagnostics.ProcessStartInfo psi2 = new System.Diagnostics.ProcessStartInfo(@"xcopy.exe", @"E:\Debug\VipBat\* C:\\Users\\VCCS\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\" /s /i /y");
System.Diagnostics.Process.Start(psi2);
Était-ce utile?

La solution

Problem : You are misusing double quotes here => Startup\"

Soultion : you need to properly pass arguments to Process.StartInfo() .

Your first parameter should be file name and second parameter should be arguments.

Try This:

System.Diagnostics.ProcessStartInfo psi2 = new   
System.Diagnostics.ProcessStartInfo(@"xcopy.exe", "E:\\Debug\\VipBat\\* \"C:\\Users\\VCCS\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\\" /s /i /y");

Autres conseils

Try this ;

Using System.IO;

public void Copy(string filePath,string DestPath)
{
    if(File.Exists(filePath))
    {
       File.Copy(filePath,DestPath);
    }
    else
    {
       MessageBox.Show("The file doesn't exists.","Error") 
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top