Click here to Skip to main content
       

C#

 
Questionmodify C# 2008 desktop application Pinmemberclassy_dog1-May-13 17:47 
AnswerRe: modify C# 2008 desktop application PinprotectorPete O'Hanlon1-May-13 19:54 
Questionunexpected end of file Pinmembermiket2144123451-May-13 14:54 
AnswerRe: unexpected end of file PinmemberFreak301-May-13 23:26 
AnswerRe: unexpected end of file PinmvpEddy Vluggen2-May-13 1:30 
QuestionProblem while exporting a aspx page to pdf PinmemberMember 100216341-May-13 0:20 
AnswerRe: Problem while exporting a aspx page to pdf PinmemberJasmine25011-May-13 9:40 
QuestionBest practice to select and copy a file to a remote location? Pinmembermatleeds1-May-13 0:07 
I have a requirement where when a button is clicked the app connects to a remote pc and the user can browse to a folder on the c drive then copy a file to their pc (not on a LAN but a remote location)
 
When using Remote desktop connection the details are (for example)
Computer: abcd.dyndns.org:1234
Username: bob2\apple
Password: password
 
After doing a bit of research using WMI or Impersonation seems the best options. Here's where I'm at with the Impersonation approach..
 
[DllImport("advapi32.DLL", SetLastError=true)]
        public static extern int LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType,
            int dwLogonProvider, ref IntPtr phToken);
 
private void button4_Click(object sender, EventArgs e)
        {
            WindowsIdentity wid_current = WindowsIdentity.GetCurrent();
            WindowsImpersonationContext wic = null;
            try
            {
                IntPtr admin_token = new IntPtr();
               
                if (LogonUser("bob2\apple", "abcd.dyndns.org:1234","password",9, 0, ref admin_token) != 0)
                {   
                    wic = new WindowsIdentity(admin_token).Impersonate();
 
                    // NOT SURE ABOUT THIS BIT.....
                    File.Copy(@"", @"",
                        true);
                    MessageBox.Show("Copy Succeeded");
                }
                else
                {
                    MessageBox.Show("Copy Failed");
                }
             }
            catch(Exception se)
            {
                int ret = Marshal.GetLastWin32Error();
                MessageBox.Show(ret.ToString(), "Error code: " + ret.ToString());
                MessageBox.Show(se.Message);
            }
            finally
            {
                if (wic != null)
                    wic.Undo();
            }
           
        }
 
thanks
Mat

AnswerRe: Best practice to select and copy a file to a remote location? PinmemberJasmine25011-May-13 9:37 
AnswerRe: Best practice to select and copy a file to a remote location? Pinmemberjschell1-May-13 9:41 
Questionpassword creation in c# winform PinmemberMember 1002123530-Apr-13 19:39 
AnswerRe: password creation in c# winform PinmvpRichard MacCutchan30-Apr-13 22:42 
AnswerRe: password creation in c# winform PinmemberGuyThiebaut1-May-13 3:14 
Questionhow to get the value of a control in a process which start with Process.start PinprofessionalMember 1001614230-Apr-13 19:11 
AnswerRe: how to get the value of a control in a process which start with Process.start PinmvpRichard MacCutchan30-Apr-13 22:37 
GeneralRe: how to get the value of a control in a process which start with Process.start PinprofessionalMember 100161421-May-13 15:33 
GeneralRe: how to get the value of a control in a process which start with Process.start PinmvpRichard MacCutchan1-May-13 22:02 
QuestionSaving DrawLine to Image: SOLVED PinmemberMember 792126830-Apr-13 4:34 
AnswerRe: Saving DrawLine to Image PinmvpEddy Vluggen30-Apr-13 5:05 
GeneralRe: Saving DrawLine to Image PinmemberMember 792126830-Apr-13 6:11 
AnswerRe: Saving DrawLine to Image PinprofessionalKenneth Haugland30-Apr-13 5:42 
GeneralRe: Saving DrawLine to Image PinmemberMember 79212681-May-13 1:46 
AnswerRe: Saving DrawLine to Image: SOLVED PinmemberMember 79212681-May-13 5:39 
QuestionThe performance of LINQ vs. traditional iteration PinprofessionalRob Philpott30-Apr-13 4:30 
AnswerRe: The performance of LINQ vs. traditional iteration PinmvpEddy Vluggen30-Apr-13 5:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 20 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid