473,396 Members | 1,924 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,396 software developers and data experts.

setting Username&password while using DirectoryInfo()

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

Nov 16 '05 #1
1 10364
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.
<si**************@rediffmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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

Nov 16 '05 #2

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

Similar topics

2
by: Ashutosh | last post by:
Our company has an intranet paging website. It gets all the contact and group addresses from SQL Server database. The paging is done through WCTP. It works properly except for only one group where...
3
by: kaushik | last post by:
I had install oracle 9i. but i don't know the username & password for login into oracle, :)
4
by: kvicky | last post by:
I am trying to set a scheduled task for one of my ASP.net application that I developed on a monthly basis. This application requires a login authentication. I am sending the url of the login page...
1
by: gujarsachin2001 | last post by:
hello friends i m connecting to http or https url programatically through console application using follwoing methods of credentilas but if there is username & password for that url through this...
1
by: Proaccesspro | last post by:
I have an Access database I'd like to add a little security to. Is it possible to have a list of allowable usernames and multiple passwords associated with each username? Also, I'd like to capture...
8
by: BJByrne | last post by:
Hi there, I want to open a database from a macro in another database and I have it working, except that we have usernames and passwords to log on, so when the macro is run is automatically asks...
3
by: rodrigo | last post by:
I am trying to retrieve a password protected page using: get = urllib.urlopen('http://password.protected.url"').read() While doing this interactively, I'm asked for the username, then the...
5
by: webgenius | last post by:
At present I'm using $_SESSION to create and store the login details. But I'm not able to access this session variable. Is there any way for the website to remember these details? ...
1
by: RAldridge | last post by:
Hi, I am a complete newb and experimenting with the VB code below. When I run this, the device on my intranet waits for username and password until it processes the resource. It there a way to pass...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.