Wildhorn
Wildhorn

Reputation: 932

How to copy file from a local computer to a remote computer?

I tried with WMI but doesn't work.
I also tried this with LogonUser but it doesnt work because LogonUser only works for local computers.

So how can I copy a file or at least get connected to the computer so it accept System.IO.File.Copy?

Upvotes: 0

Views: 5554

Answers (2)

Brian R. Bondy
Brian R. Bondy

Reputation: 347226

You need to p/invoke WNetUseConnection to get access to the computer first, then use a UNC path to access the file and use normal file I/O. Here is some sample C# code.

You would for example access c:\test.txt on a computer named MONKEY on your LAN via a path like this: @"\\MONKEY\c$\test.txt".

Upvotes: 1

HCL
HCL

Reputation: 36775

If you need a share with that you can access on every computer, you can try \\computername\c$.

If your app has admin-rights, you can copy files to every location on the c:. Use \\computername\d$ for d: and so on.

Hope this helps.

Upvotes: 1

Related Questions