opening up web browser from winform - vb.net

Done quite a bit of looking but not finding what i need. From a win form i'd like to open up a web browser passing in a url. But i need to provide authentication while doing this. I tried just using a system.diagnostics.process.start("http://userid:pw#site") but that does not work. Was hoping someone could lend a hand.
thanks
shannon
Using the tip.. here is what i have...
Dim m As New System.Security.SecureString
Dim pw As String = "mypassword"
For Each c As Char In pw
m.AppendChar(c)
Next
Dim pis As ProcessStartInfo = New ProcessStartInfo("http://test/pagegoingafter.aspx")
With pis
.UserName = "userid"
.Password = m
.UseShellExecute = False
End With
Process.Start(pis)
I'm getting a logon failure: unknown user name or password.
it's seems strange to me.. but if i do in firefox http://userid:mypassword#test/pagegoingafter.aspx i can get to my page. If i do the same thing in IE 8... no joy.
so is there anything else that can be done to get IE to work.. cause i'm thinking that would allow the above code to work as well.

You can provide credentials to the process.
See this overload to Process.Start - it takes a username, password and domain.
There are other alternatives - see this blog post.

Related

Setting MS Access password at runtime in vb.net designer generated system

I am developing a VB.NET update system for a volunteer organisation’s MS Access database. The database is protected by a password as it contains personal information. I have created the application using the VB designer. I need to be able to code the application so that, if the owner decides to change the MS Access password, they will have no need to come back to me to change the code and rebuild the solution. In other words, I do not want the password to be hard coded in the app.config file or the settings.designer.vb file. My code should not need to know the password as a simple call to one of the Fill functions can test any password entered by the user. My problem is that I have found no way to alter the connection string that is tested in the setttings.designer.vb code whenever the database is accessed. I am using Visual Studio 2017.
I have spent a long time searching the web for answers and have tried various solutions involving the configurationmanager without success. I am new to this area so I would be most grateful if anyone here can help.
Here is my latest attempt which still produces an invalid password error even though the third debug statement suggests that the connection string, including the password, has been correctly set.
Public Sub UpdateConnString(connString As String)
Dim configFileMap As New ExeConfigurationFileMap()
Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(configFileMap.ExeConfigFilename)
Dim connStringName As String = "TestConnectionString"
Debug.Print("0 " + config.ConnectionStrings.ConnectionStrings(connStringName).ConnectionString)
config.ConnectionStrings.ConnectionStrings(connStringName).ConnectionString = connString
Debug.Print("1 " + config.ConnectionStrings.ConnectionStrings(connStringName).ConnectionString)
config.Save(ConfigurationSaveMode.Modified, True)
Debug.Print("2 " + config.ConnectionStrings.ConnectionStrings(connStringName).ConnectionString)
End Sub
Just because a connection string is stored in the config file, you aren't required to use it as it is. You can read in that default value and then edit it before using it, e.g.
Dim builder As New OleDbConnectionStringBuilder(My.Settings.DefaultConnectionString)
builder.DataSource = dataSource
Dim connectionString = builder.ConnectionString
You can add or modify any part of a connection string you want that way at run time.
Thank you for your response. Unfortunately, the code throws a compilation error - "DefaultConnectionString is not a member of My.Settings".
Fortunatley I have now managed to find a working solution:
'My.Settings.Item("TestConnectionString") = connectionString

Auto login windows security window

I try to fill up automatically the name and the password for a windows security window, basically the page is opening after a couple of seconds with the window but the fields for user and password are empty. This is the code I have so far, any help is appreciate. Thank you.
This is where I am now:
Dim oProcess As New Process()
Dim psi As New ProcessStartInfo
psi.FileName = "arp"
psi.Arguments = "-a"
psi.UseShellExecute = False
psi.RedirectStandardOutput = True
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.CreateNoWindow = True
Dim p As Process = Process.Start(psi)
Dim s As String = p.StandardOutput.ReadToEnd()
s = s.Split(" ".ToCharArray)(1)
WebBrowser1.Navigate("http://user:pass#" + (s) + ":34655/")
It works but I get from cmd only the first ip(192.2.2.2), if I don't use the arp command I don't see the ip of the device.
Basically I need to get the ip from this cmd output from third row:
"interface: 192.2.2.2 ----0xb//////
internet address- physical address---type///////
134.45.455.455.4(this ip) mac address dynamic//////
etc etc"/////
Thank you
You need to be more specific.
If this site you are connecting to uses Basic authentication, you are presented with a System InputBox with standard fields and a button control.
If it uses WebForm LogIn authentication, you are presented with a Web Form
with semi-standard Form Elements to fill in.
In the former case, it is quite simple to perform an authentication throu WebRequest/HttpWebResponse or, if you really need to use a WebBrowser control,
to setup its .Navigate property to achieve the same result.
If your case is the latter, since you are using a WebBrowser control to navigate to an URI, you don't really need any PInvoke at all.
Mind that WebBrowser.Document contains the HtmlDocument that describes the HTML page.
It also lets you access all the object that the page defines.
So, if you know in advance which Site you are connecting to (ie, you need to perform this operation
for this one Site only), you can use the .DocumentCompleted Event of your WebBrowser and set
your parameters directly from there:
Consider:
["UserName"], ["Password"], ["LoginButton"]
as the IDs of the Html Elements that represent an <input> Textbox, an <input> Password,
and a <input> Button that forwards the form parameters in a .Click Event .
So, read from the Html Page the IDs of the elements in the form and just insert your values:
In WebBrowser1_DocumentCompleted:
WebBrowser1.Document.All(["UserName"]).SetAttribute("Value", "UserID")
WebBrowser1.Document.GetElementById(["Password"]).SetAttribute("Value", "Password")
WebBrowser1.Document.All(["LoginButton"]).InvokeMember("Click")
I'm using .Document.All and .Document.GetElementById to show that there are two different
methods to accomplish the same task.
If you don't know in advance what the content of the Html Page is, you need to perform a simple parsing of the page (using the HtmlDocument Object), retrieve the elements of the form and then repeat the
previous task.
As I said, you need to be more specific.
If you have questions, comment and I will edit my answer.

Ask for password when opening Database - LotusNotes/DominoDesigner

My task is, when opening a database in Lotus Notes, the current user will be ask to input his/her password that was given by his superior. Is there a way how to do that? Just a simple prompt or form that will ask for your password before viewing the database.
Please understand that I do not intend this answer to be disrespectful, but this is really not a task for a beginner at Notes and Domino, as you have stated that you are. You should tell that to your boss. This is a task for someone who has deep understanding of the principles of security and of the mechanisms Notes and Domino provide for it. If you do not understand my comments on #Thomas Adrian's answer, then that applies to you. Again, no disrespect intended.
As security guru Bruce Schneier said, "if you ask amateurs to act as front-line security personnel, you shouldn't be surprised when you get amateur security".
Yes you can put code in queryopendatabase which is located in database script.
Create a button for your superior to store the password in a general profile document within the database
2 when users open the database use the queryopendatabase script to present a password prompt. You can use inputbox in lotus script. Verify the password against the profile document. If a wrong password is entered close the database.
You can use the following code as an embryo, This code use a "real" document but you can easily modify this to be a profile document.
Remember when you test this to close Domino Designer as the NSF is cached as long as DDE is open
Sub Postopen(Source As Notesuidatabase)
Dim db As NotesDatabase
Set db = source.Database
Dim d As NotesDocument, flag As Integer, upw As String, pw As String
upw = InputBox("Enter Password")
Set d = db.getView("Main").getFirstDocument()
If Not d Is Nothing Then
pw = d.password(0)
If pw = upw Then
flag = 1
End If
End If
If flag <> 1 Then Call source.Close()
End Sub

Authenticating against ADAM using LDAP

I'm trying to authenticate using ADAM and LDAP. I really have no experience with this stuff, but I've been thrown in the deep end at work to figure it out.
Here's what I know. I'm using a program called JXplorer to look at the ADAM server, running on a VM on my computer. Here are the login details
This works perfectly. What I'm trying to do is replicate this process using VB.NET. I've tried a bunch of stuff and nothing seems to be working, I'm getting constant exceptions, ranging from bad password to unknown error. Here's the code I've started with -
Dim userName As String = "ADAM_TESTER"
Dim userPassword As String = "password"
Dim serverAddress As String = "LDAP://10.0.0.142:389"
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Dim de As DirectoryEntry = New DirectoryEntry("LDAP://10.0.0.142:389/OU=Users,DC=TEST,DC=corp", userName, userPassword)
Dim deSearch As DirectorySearcher = New DirectorySearcher()
deSearch.SearchRoot = de
deSearch.Filter = "(&(objectClass=user) (cn=" + userName + "))"
Dim results As SearchResultCollection = deSearch.FindAll()
If (results.Count > 0) Then
Dim d As DirectoryEntry = New DirectoryEntry(results(0).Path, userName, userPassword)
If (d.Guid.ToString IsNot Nothing) Then
'The directory entry is valid
'DoSomething()
End If
End If
I've also tried changing the userName above to the details in User DN in JXplorer. I'm really stuck here and have been looking for answers for hours.
Any help would be appreciated.
FYI, Users is a container, not an OU. I believe you could have also used "LDAP://10.0.0.142:389/CN=Users,DC=TEST,DC=corp"
It is almost certainly a need for userName to be the full DN. ADAM needs a full DN for logins in most cases.
Thanks for the thoughts Geoff, I eventually figured it out. It turned out that I needed the connection string not including the OU=Users. The final string ended up being -
LDAP://10.0.0.142:389/DC=TEST,DC=corp
I've no idea why it didn't want the OU=Users. I spend about a day trying all the different combinations until finally this was accepted.

Opening a file using impersonation

I have been searching the web looking for a way to open a WORD file from a secure network folder by impersonating a user who has access. The closest I've come to finding the answer was this from 2 years ago:
Impersonating in .net (C#) & opening a file via Process.start
Here is the code that I am using. When I set the arguments = LocalFile_Test, everything works perfectly because the user is accessing the local c:\ that is has access to. But when I set arguments = RemoteFile_Test, Word opens up a blank document which is the same effect as if I put garbage in the arguments. So it appears that it cannot find the file even though when I login with the user/domain/password that I specify in the properties below, I can find that exact file name and it is not empty. Does anything jump out at you right away? I appreciate your time.
Dim LocalFile_Test As String = "C:\New.docx"
Dim RemoteFile_Test As String = "\\Server1\Apps\File\New.docx"
Dim MyStartInfo As New System.Diagnostics.ProcessStartInfo
MyStartInfo.FileName = "C:\Program Files\Microsoft Office\Office12\WINWORD.exe "
MyStartInfo.Arguments = LocalFile_Test
MyStartInfo.LoadUserProfile = True
MyStartInfo.UseShellExecute = False
MyStartInfo.UserName = "specialuser"
MyStartInfo.Domain = "mydomainname"
MyStartInfo.Password = New System.Security.SecureString()
MyStartInfo.Password.AppendChar("p"c)
MyStartInfo.Password.AppendChar("a"c)
MyStartInfo.Password.AppendChar("s"c)
MyStartInfo.Password.AppendChar("s"c)
Process.Start(MyStartInfo)
My understanding is that you are trying to get a password protected file from a server, and when you do process start, it just opens up a blank word doc. I think the error is how you are trying to get the file, I think you have to map the actual physical path of the file on the server, like
System.Web.HttpContext.Current.Server.MapPath("\\Server1\Apps\File\New.docx")
From there, I am fairly certain, you need to create network credentials for the user like
System.Net.NetworkCredential=New NetworkCredential(userName:=, password:=)
Finally, once that is done, you can either write the file, or transmit the file like so...
System.Web.HttpContext.Current.Response.TransmitFile(file name)
System.Web.HttpContext.Current.Response.WriteFile(file name)
Then,once you get the file, you can try to open it with process start.
Hope that helps, let me know if what I said doesn't work.