473,941 Members | 9,429 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 10594
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
2169
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
14019
by: kaushik | last post by:
I had install oracle 9i. but i don't know the username & password for login into oracle, :)
4
2369
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
1652
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
2641
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
3819
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
19660
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
2619
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
3851
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
10134
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
11525
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11110
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11293
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10659
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...
1
8218
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
7389
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
6078
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...
1
4908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.