473,830 Members | 2,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting Username&passwo rd 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.GetDirec tories();

foreach (FileInfo fri in fiArr)
Console.WriteLi ne(fri.Name);
foreach (DirectoryInfo di in diArr)
Console.WriteLi ne(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.IOExc eption: Logon failure: unknown user
name or bad password.

at System.IO.__Err or.WinIOError(I nt32 errorCode, String str)
at System.IO.Direc tory.InternalGe tFileDirectoryN ames(..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 10534
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\so meuser

Willy.
<si************ **@rediffmail.c om> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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.GetDirec tories();

foreach (FileInfo fri in fiArr)
Console.WriteLi ne(fri.Name);
foreach (DirectoryInfo di in diArr)
Console.WriteLi ne(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.IOExc eption: Logon failure: unknown user
name or bad password.

at System.IO.__Err or.WinIOError(I nt32 errorCode, String str)
at System.IO.Direc tory.InternalGe tFileDirectoryN ames(..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
2162
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 it asks for username and passord when the user tries to send a page and does it successfully. But before I view the status of the page it asks me for username and password. It asks thrice and then give me an error web page. Any help would be...
3
14001
by: kaushik | last post by:
I had install oracle 9i. but i don't know the username & password for login into oracle, :)
4
2360
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 in the Windows scheduled task. But I also want to send the username and password as Parameters (that is identified through windows authentication). and automatically assigned these parameters to loging into the application and conduct my...
1
1647
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 code I m able to download files from that url using "DefaultCredentials" but i want to use password and username to access resources if tht url contains. & if for tht specific url if user enters wrong username & password so tht he must not...
1
2637
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 the username and use it on various forms as they are updated by the various users. Any ideas??
8
3806
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 for a username and password. I've tried entering the conditions as follows: 'Open the External Database in Access Window appAccess.OpenCurrentDatabase strDBPath, False, bstrPassword providing it with the database path (as String), that I...
3
19641
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 password at the terminal. Is there any way to do this non-interactively? To hardcode the user/ pass into the script so I can get the page automatically? (This is not a cracking attempt, I am trying to retrieve a page I have
5
2611
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? $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "LoginOK.php" session_start(); session_register("myusername");...
1
3846
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 the username and password in the code so I can automate the url? If I can automate it, then I can take out the .visible. Thanks so much. Option Explicit Dim objIEA Set objIEA = CreateObject("InternetExplorer.Application") objIEA.Navigate...
0
9791
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10202
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9313
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7745
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6950
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3958
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.