Re: setting Username&password while using DirectoryInfo()

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Willy Denoyette [MVP] (willy.denoyette_at_pandora.be)
Date: 12/13/04


Date: Mon, 13 Dec 2004 22:58:34 +0100

You have to:
1. create a new logon session (calling Win32 API LogonUser ) and
2. impersonate using the token obtained by 1.

Another (better) option is to create a network session from the command
line or from a logon script.
check the 'net use ' command

net use \\server\share passwd /user:machine\someuser

Willy.

<siddharth_jain_1@rediffmail.com> wrote in message
news:1102972985.830197.220540@f14g2000cwb.googlegroups.com...
> Hello
>
> I am trying to get a list of shared files and subdirectories in a
> particular folder on a server.
> For this I am using DirectoryInfo in the following way.
>
> DirectoryInfo folder = new
> DirectoryInfo("\\\\server_name\\shared_folder_name");
>
> FileInfo[] fiArr = folder.GetFiles();
> DirectoryInfo[] diArr = folder.GetDirectories();
>
> foreach (FileInfo fri in fiArr)
> Console.WriteLine(fri.Name);
> foreach (DirectoryInfo di in diArr)
> Console.WriteLine(di.Name);
>
> Now, this works fine when the server doesnt have a password set on the
> guest account.
> In other cases, it gives the following runtime exception:
>
> Unhandled Exception: System.IO.IOException: Logon failure: unknown user
> name or bad password.
>
> at System.IO.__Error.WinIOError(Int32 errorCode, String str)
> at System.IO.Directory.InternalGetFileDirectoryNames(..blah blah blah)
>
> If I know the password to access the shares of the server, how do I set
> them in my program?
> I would be grateful to anyone who could guide me towards solving this
> problem.
>
> Thanks
>



Relevant Pages

  • setting Username&password while using DirectoryInfo()
    ... particular folder on a server. ... For this I am using DirectoryInfo in the following way. ... this works fine when the server doesnt have a password set on the ... at System.IO.Directory.InternalGetFileDirectoryNames(..blah blah blah) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: dcdiag - advertising errors on newley promoted domain controller
    ... Can you do the following on uksccmads01 ... The problem may actually have nothing to do with the new server but the ... From a command prompt try and see if you get any additional info ... Skipping site UK-CCM, this site is outside the scope ...
    (microsoft.public.windows.server.active_directory)
  • Re: dcdiag - advertising errors on newley promoted domain controller
    ... Can you do the following on uksccmads01 ... The problem may actually have nothing to do with the new server but the ... Active Directory Forest Replication GUIDs Found: ... From a command prompt try and see if you get any additional info ...
    (microsoft.public.windows.server.active_directory)
  • Re: dcdiag - advertising errors on newley promoted domain controller
    ... Default Server: uksccmads01.jw-uk.jameswalker.co.uk ... Output from dnslint on uksccmads01: No erros found, ... Active Directory Forest Replication GUIDs Found: ... From a command prompt try and see if you get any additional info ...
    (microsoft.public.windows.server.active_directory)
  • Re: dcdiag - advertising errors on newley promoted domain controller
    ... Then change the secondary DNS to the other site DNS server. ... Skipping site UK-CCM, this site is outside the scope provided ... command line arguments provided. ...
    (microsoft.public.windows.server.active_directory)