14,865,273 members
See more:

I need to route the information about a file copy in such a way that the default copier that is installed is triggered. I did it with the SHFileOperation function from the windows shell api and it worked for me but only with the windows copier, not with the supercopier or any other copier installed.

What I have tried:

The following code performs the task but invokes the progress bar of windows explorer:

C#
[DllImport("shell32.dll", CharSet = CharSet.Unicode, EntryPoint = "SHFileOperation")]
public static extern Int32 SHFileOperation32(
ref SHFILEOPSTRUCT32 lpFileOp);

[DllImport("shell32.dll", CharSet = CharSet.Unicode, EntryPoint = "SHFileOperation")]
public static extern Int32 SHFileOperation64(
ref SHFILEOPSTRUCT64 lpFileOp);         // Address of an SHFILEOPSTRUCT structure that contains information
// this function needs to carry out the specified operation. This
// parameter must contain a valid value that is not NULL. You are
// responsibile for validating the value. If you do not validate it,
// you will experience unexpected results.

public static Int32 SHFileOperation(ref SHFILEOPSTRUCT lpFileOp)
{
MachineType mt = GetMachineType();
Int32 result;

switch (mt)
{
case MachineType.win32:
SHFILEOPSTRUCT32 fos32 = new SHFILEOPSTRUCT32(lpFileOp);
result = SHFileOperation32(ref fos32);
lpFileOp.CopyFrom(fos32);
break;

case MachineType.win64:
SHFILEOPSTRUCT64 fos64 = new SHFILEOPSTRUCT64(lpFileOp);
result = SHFileOperation64(ref fos64);
lpFileOp.CopyFrom(fos64);
break;

default:
throw new ArgumentException("What kind of computer are you using? It's not 32 and not 64 bit");
}

return result;
}

The effect of showing the windows progress bar can also be achieved by the following code:

C#
Microsoft.VisualBasic.FileIO.FileSystem.CopyFile(
@"D:\file1.txt",
@"D:\file2.txt",UIOption.AllDialogs);

But this is not the desired functionality. What is desired is to invoke the installed windows copier such as Supercopier, Teracopy, Ultracopier or another. It is evident that these tools implement an extension of the Windows Shell and make a customization of the copy process. I've been looking at the code on GitHub for some of these tools to see the copy hook handler they implement and I can't find a way to achieve my goald.

I need to invoke the windows shell in such a way that these copiers detect the event and handle it in their own way. If anyone has a suggestion it would be welcome.

Posted
Updated 27-Oct-20 21:21pm
Gerry Schmitz 28-Oct-20 0:39am

So, it works, but you don't like the "progress bar". In the grand scheme of things ...
yoandryLumpuy 29-Oct-20 11:18am

Gerry It works perfectly that way, but the client is the boss and he wants the default copier to be activated because sometimes they provide better handling and behavior of the copies.

## Solution 1

If you want to use Supercopier, Teracopy, Ultracopier or another application, you have to:
1) call its exe via Process.Start[^].
or
2) install NuGet package and use it within your application. See: GitHub - alphaonex86/Supercopier: Deprecated, replaced by Ultracopier[^]
yoandryLumpuy 29-Oct-20 12:09pm

This way?:

var fileName1 = @"D:\text1.txt";
var fileName2 = @"D:\text2.txt";
var processStartInfo = new ProcessStartInfo
{
UseShellExecute = true,
Arguments = \$"copy /B \"{fileName1}\" \"{fileName2}\"",
FileName = "cmd.exe",
WindowStyle = ProcessWindowStyle.Hidden
};

Process.Start(processStartInfo);

But this way doesn't even show the Windows progress bar when triggering the copy.
Even if Teracopy or one of those copiers could be activated by command line, that's not what I want, I want the copy to be activated by invoking windows and that it delegates it as desired to one of those copiers, without even knowing if there is one installed, otherwise use the default one. I don't know if so much demand in this functionality can be implemented, i can't find the way of doing it.