I wrote a service that monitors directories all over my network. As the company grows, my service is becoming more and more utilized. I now have to monitor drives and devices through VPN tunnels on different domains. Up to this point all my clients have been willing to add in my service account user into there domain to allow me access. I have just acquired a new client that will not add in this user to their domain (I can not blame them). This client has provided me a username and password to access their provided network share.
I tried adding in a WMI connection using this user, not being an admin, the connection fails.
My next idea was to use the LogonUser API to impersonate users. This also fails because I have no access to the DC on the remote network. When my code tries to get the SecurityToken by authenticating with the machine it is running on. The user can not authenticate because the user is not on my domain (user is from the clients domain).
Leading into my question:
Is there a way to have the Windows Authentication Prompt* auto fill itself with a provided username/password < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
* The dialog box that prompts for username and password when you try to access a network share that your user does not have access to.
Thanks for any help!
Code used for Logon API:
Private 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 Integer) As Boolean Const LOGON32_LOGON_INTERACTIVE As Long = 2 Const LOGON32_LOGON_NETWORK As Long = 3 Const LOGON32_PROVIDER_DEFAULT As Long = 0 Const LOGON32_PROVIDER_WINNT50 As Long = 3 Const LOGON32_PROVIDER_WINNT40 As Long = 2 Const LOGON32_PROVIDER_WINNT35 As Long = 1 Private Function GetWindowsIdentity(ByVal UserName As String, _ ByVal Domain As String, ByVal Password As String) As WindowsIdentity Dim SecurityToken As Integer Dim Success As BooleanSuccess = LogonUser(UserName, Domain, Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, SecurityToken)
GetWindowsIdentity =
New WindowsIdentity(New IntPtr(SecurityToken)) End Function Sub subConnect() Dim strUser, strPass, strDomain As String Dim intType, intProvider As Integer Dim intToken As IntegerstrUser = strXMLUser
strPass = strXMLPass
strDomain = strXMLDom
intType = LOGON32_LOGON_NETWORK
intProvider = LOGON32_PROVIDER_DEFAULT
Dim NewIdentity As WindowsIdentity Dim CurIdentity As WindowsIdentity TryNewIdentity = GetWindowsIdentity(strUser, strDomain, strPass)
NewContext = NewIdentity.Impersonate()
Dim tmpindent As WindowsIdentitytmpindent = WindowsIdentity.GetCurrent()
strDa01 =
String.Format("[" & DateTime.Now & "]" & " Login as: " & tmpindent.Name)strData = strData.Concat(strData, strDa01)
strDa01 = Environment.NewLine
strData = strData.Concat(strData, strDa01)
Catch ex As ExceptionstrDa01 =
String.Format("[" & DateTime.Now & "]" & " Error - " & ex.Message)strData = strData.Concat(strData, strDa01)
strDa01 = Environment.NewLine
strData = strData.Concat(strData, strDa01)
End Try End Sub
Need Help - Auto Fill the Windows Authentication Prompt??
Bill Tubbs
Again, Thanks for any help!
S. Khawar
Here's the code I used to access an XML file that was protected. It's C# and you need to add Credentials.
XmlTextReader rdr =
new XmlTextReader("URLTO DOWNLOAD");XmlUrlResolver resolver =
new XmlUrlResolver();CredentialCache myCache =
new CredentialCache();myCache.Add(
new Uri("THe URI"),"Basic",new NetworkCredential("username", "password"));rdr.XmlResolver = resolver;
resolver.Credentials = myCache;
XmlDocument doc =
new XmlDocument();doc.Load(rdr);
Andria1974
SetWindowText and FindWindow
Does anyone know the .net equivalent