473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

File Copy

Hello!

I'm trying to copy a file from another computer on the network that I do not
have permission with my current logon details to access.

If I open the folder using the Windows file manager with the path "\\
192.168.2.2\temp" (where temp is a shared directory on server \\192.168.2.2),
windows prompts for a User Name and password of a user who has permission on
that computer to access that directory. If I enter valid details, the folder
is opened and I can copy files from this machine.

How do I do this programmatically in c++ or c#? Standard file open and/or
directory commands do not have the option to enter a valid Username/password
and they just fails with permission denied (understandably).

Regards....Adrian

Jul 31 '08 #1
2 2170
On Jul 31, 11:40*pm, AdrianMorris
<AdrianMor...@discussions.microsoft.comwrote:
Hello!

I'm trying to copy a file from another computer on the network that I do not
have permission with my current logon details to access.

If I open the folder using the Windows file manager with the path "\\
192.168.2.2\temp" (where temp is a shared directory on server \\192.168.2..2),
windows prompts for a User Name and password of a user who has permissionon
that computer to access that directory. If I enter valid details, the folder
is opened and I can copy files from this machine.

How do I do this programmatically in c++ or c#? Standard file open and/or
directory commands do not have the option to enter a valid Username/password
and they just fails with permission denied (understandably).
Try using WindowsIdentity.Impersonate() to impersonate the user
account you want to use to access files, and invoke File.Copy when
impersonated.
Aug 1 '08 #2
Hello Pavel,

Many thanks for your suggestions.

I used the "LogonUser" followed by the "ImpersonateLoggedOnUser" functions
and all is working well.

Regards....Adrian

"Pavel Minaev" wrote:
On Jul 31, 11:40 pm, AdrianMorris
<AdrianMor...@discussions.microsoft.comwrote:
Hello!

I'm trying to copy a file from another computer on the network that I do not
have permission with my current logon details to access.

If I open the folder using the Windows file manager with the path "\\
192.168.2.2\temp" (where temp is a shared directory on server \\192.168.2..2),
windows prompts for a User Name and password of a user who has permission on
that computer to access that directory. If I enter valid details, the folder
is opened and I can copy files from this machine.

How do I do this programmatically in c++ or c#? Standard file open and/or
directory commands do not have the option to enter a valid Username/password
and they just fails with permission denied (understandably).

Try using WindowsIdentity.Impersonate() to impersonate the user
account you want to use to access files, and invoke File.Copy when
impersonated.
Aug 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
0
by: SeanR | last post by:
I have a function to copare two files. It will first copy the original file form a different server to a local temp path and then compare that version to a version that has been restored form tape....
2
by: RitaG | last post by:
Hi. In a VB.Net program I use File.Copy to copy some zipped (and text) files from one server to another. I'm required by management to do a file compare after the copy has completed. Is the...
5
by: DraguVaso | last post by:
Hi, I need a SECURE way to copy parts of a file. I'm having files which contains a whole bunch of records. In one 'fysical' file I'm having one or more logical files. What I need to do is to...
8
by: luis molina Micasoft | last post by:
it seems that when i do file.copy the svchost.exe is hanged, i mean if i make 40 threads of file.copy , 40 copys of files at same time the system is going down and stop responding, this is when i'm...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
1
by: Rachel McConnell | last post by:
Hi, I am trying to import data using COPY, from a file containing thirty or so COPY commands each with 0 or more rows of data. Reason, I have a small data set I want to include into a database...
3
by: maheshkadam | last post by:
Hi friends I am new to perl so please guide me. I have one application which created backup log file every day.But it appends that file so you can see logs for different day in one file only. ...
1
by: =?Utf-8?B?UmFkZW5rb19aZWM=?= | last post by:
I am using standard File.Copy(source,dest,true) method in C# and I have problem with copying large number of files. Here is my code: foreach (FileInfo file in files) {...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.