Hello,
Using VS 2005 Beta (VB) I would like to read a network share in the form of:
\\192.168.1.10\c$\ - Using the DirectoryInfo object. However when I try that I get the error:
Logon failure: unknown user name or bad password
How can I either popup a box for the user to type in the username or password or embed it into the program

Logon failu unknown user name or bad password
dollmaker
PS - you would think it would be in the .net framework...
Osmar
please help !!!
axedeveloper
Hi Vikram,
I am trying to save file from one system to another system (connected in lan).
Actually I am taking database backup through my application (.net).The database backup file will be stored in the system (in specified folder) where the SQL server is. Now I have to store the database backup file in another system connectend in LAN . While I am trying to do the same using File.copy("","") it is saying that "Login Failure: Unknown user name or bad password". Can U please help me in this regard. thanks in Advance
Regards,
Kiran
gariche
Converted it: Not tested though...
----------------------------------------------------------------------
Imports System.Security.Principal
Imports System.Runtime.InteropServices
Public Class UserManager
Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal lpszUsername As String, _
ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As Integer, _
ByVal dwLogonProvider As Integer, ByRef phToken As IntPtr) As Integer
Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal handle As IntPtr) As Boolean
Public Shared Sub CreateIdentity(ByVal User As String, ByVal Domain As String, ByVal Password As String)
Dim tokenHandle As New IntPtr(0)
Dim ret As Integer
Dim LOGON32_PROVIDER_DEFAULT As Integer = 0
Dim LOGON32_LOGON_NETWORK_CLEARTEXT As Integer = 3
tokenHandle = IntPtr.Zero
Dim returnValue As Boolean = LogonUser(User, Domain, Password, LOGON32_LOGON_NETWORK_CLEARTEXT, LOGON32_PROVIDER_DEFAULT, tokenHandle)
If False = returnValue Then
ret = Marshal.GetLastWin32Error()
Throw New Exception("LogonUser failed with error code: " + ret)
End If
Dim id As New WindowsIdentity(tokenHandle)
CloseHandle(tokenHandle)
id.Impersonate()
End Sub
End Class
----------------------------------------------------------------------
Regards,
Vikram
-bc-
I hope this helps others who received this error message.
When I debugged my .net application on my local computer everything worked, however, when copying the same application to the server I received the error message Logon failure: Unknown user name or bad password All the proper permissions were set, still same error message.
Then instead of copying the files to the web server, I published them using VS 2005...the error message went away. To publish: Build>>Publish Website
Simon St.Denis
There should be no password for a default configuration.
Jeejangs
Hi,
You would need to store the logon credentials in some store and retrieve it and logon using the LogonUser Win32API call and then impersonate using the Identity.
Code for creating identity and impersonating is provided below.
[DllImport("advapi32.dll", SetLastError=true)]
private static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword,
int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
private extern static bool CloseHandle(IntPtr handle);
public static void CreateIdentity(string User, string Domain, string Password)
{
// The Windows NT user token.
IntPtr tokenHandle = new IntPtr(0);
const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_NETWORK_CLEARTEXT = 3;
tokenHandle = IntPtr.Zero;
bool returnValue = LogonUser(User, Domain, Password,
LOGON32_LOGON_NETWORK_CLEARTEXT, LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);
if (false == returnValue)
{
int ret = Marshal.GetLastWin32Error();
throw new Exception("LogonUser failed with error code: " + ret);
}
WindowsIdentity id = new WindowsIdentity(tokenHandle);
CloseHandle(tokenHandle);
id.Impersonate(); }
Regards,
Vikram
j.oneill
try enable Guest account in the remote computer u want to access..
http://www.chicagotech.net/systemerrors.htm#System%20error%201326%20has%20occurred%20-%20Logon%20failure:%20unknown%20user%20name%20or%20bad%20password.
_dog