Creating exception in Windows firewall using VB.Net - vb.net

How can I add my application to the exception list of windows firewall, using vb.net code?
Thanks

Windows Vista and 7 provide a rather robust firewall API that can be used to add exceptions to the firewall. The code below will add an exception to the windows firewall for the specified application, provided that the code is run with administrator privileges. Add a reference to %systemroot%\system32\FirewallAPI.dll to your application.
Imports NetFwTypeLib
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Create the Application we want to add to the exception list
Dim appType As Type = Type.GetTypeFromProgID("HnetCfg.FwAuthorizedApplication")
Dim app As INetFwAuthorizedApplication
app = DirectCast(Activator.CreateInstance(appType), INetFwAuthorizedApplication)
' Set the application properties
app.Name = "Negative0's Sandbox"
app.ProcessImageFileName = "C:\Users\Negative0\vbsandbox2.exe"
app.Enabled = True
' Get the firewall manager, so we can get the list of authorized apps
Dim fwMgrType As Type = Type.GetTypeFromProgID("HnetCfg.FwMgr")
Dim fwMgr As INetFwMgr
fwMgr = DirectCast(Activator.CreateInstance(fwMgrType), INetFwMgr)
' Get the list of authorized applications from the Firewall Manager, so we can add our app to that list
Dim apps As INetFwAuthorizedApplications
apps = fwMgr.LocalPolicy.CurrentProfile.AuthorizedApplications
apps.Add(app)
End Sub
Source

Related

VB.NET 2008 - Input to data to website controls and download results

this is my first Q on this website so let me know if I have missed any important details, and thanks in advance.
I have been asked to access a website and download the results from a user-inputted form. The website asks for a username/password and once accepted, several questions which are used to generate several answers.
Since I am unfamiliar with this area I have set up a simple windows form to tinker around with websites and try to pick things up. I have used a webbrowser control and a button to use it to view the website in question.
When I try to view the website through the control, I just get script errors and nothing loads up. I am guessing I am missing certain plug-ins on my form that IE can handle without errors. Is there anyway I can identify what these are and figure out what to do next? I am stumped.
The script errors are:
"Expected identifier, string or number" and
"The value of the property 'setsection' is null or undefined"
Both ask if I want to continue running scripts on the page. But it works in IE and I cannot see why my control is so different. It actually request a username and password which works fine, it is the next step that errors.
I can provide screenies or an extract from the website source html if needed.
Thanks,
Fwiw my code is:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate("http://website.com")
'WebBrowser1.Navigate("http://www.google.com")
End Sub
Thanks for Noseratio I have managed to get somewhere with this.
Even though the errors I was getting seemed to be related to some XML/Java/Whatever functionality going askew it was actually because my webbrowser control was using ie 7.0
I forced it into using ie 9 and all is now well. So, using my above example I basically did something like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'WebBrowser1.ScriptErrorsSuppressed = True
BrowserUpdate()
WebBrowser1.Navigate("http://website.com")
'WebBrowser1.Navigate("http://www.google.com")
End Sub
Sub BrowserUpdate()
Try
Dim IEVAlue As String = 9000 ' can be: 9999 , 9000, 8888, 8000, 7000
Dim targetApplication As String = Process.GetCurrentProcess.ToString & ".exe"
Dim localMachine As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim parentKeyLocation As String = "SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl"
Dim keyName As String = "FEATURE_BROWSER_EMULATION"
Dim subKey As Microsoft.Win32.RegistryKey = localMachine.CreateSubKey(parentKeyLocation & "\" & keyName)
subKey.SetValue(targetApplication, IEVAlue, Microsoft.Win32.RegistryValueKind.DWord)
Catch ex As Exception
'Blah blah here
End Try
End Sub

Net Connection Issue using Visual Studio 2010

i have developed a very simple program using vs2010 as under and found exception like unable to connect to the remote server. i also tried to update the visual studio and reinstalled it but problem still exist.i tried to connect the visual studio by option online privacy statement under help menu but it even cant open google home page. i think there is a problem in visual studio in my pc or any port is closed or some thing else is going wrong.
Public Class Form1
Dim doc As HtmlDocument = New HtmlDocument
Dim a As HtmlDocument = New HtmlDocument
Dim web As HtmlWeb = New HtmlWeb
Private _loadURL As HtmlDocument
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
doc = web.Load("http://Dawn.com/") ' (connection exception occur at this point)
End Sub
End Class
I think your network connection is connected through the PROXY SERVER or behind the proxy server. So you've to configure proxy server settings first for accessing any website or internet resource. The code below may help you.
Dim o As New MyWebService.Name
Dim pr As New System.Net.WebProxy("100.0.1.1", 80)
pr.Credentials = System.Net.CredentialCache.DefaultCredentials
o.Proxy = pr
Dim ds As New DataSet
ds = o.GetMyData(Me.TextBox1.Text, "password")
Me.DataGridView1.DataSource = ds.Tables(0)
You've to modify it according to your proxy configuration. (you can see proxy server address in browser settings or options)

Add firewall exception

I'm working on a server/client TCP communication and it works fine, altough I can't make an application to add the software to the Windows firewall exception. I did found a sample, but it didn't worked.
My code:
Imports NetFwTypeLib
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim appType As Type = Type.GetTypeFromProgID("HnetCfg.FwAuthorizedApplication")
Dim app As INetFwAuthorizedApplication
app = DirectCast(Activator.CreateInstance(appType), INetFwAuthorizedApplication)
' Set the application properties
app.Name = "My App"
app.ProcessImageFileName = "c:\users\klein\documents\visual studio 2012\projects\tcp_server\tcp_server\bin\debug\tcp_server.exe"
app.Enabled = True
' Get the firewall manager, so we can get the list of authorized apps
Dim fwMgrType As Type = Type.GetTypeFromProgID("HnetCfg.FwMgr")
Dim fwMgr As INetFwMgr
fwMgr = DirectCast(Activator.CreateInstance(fwMgrType), INetFwMgr)
' Get the list of authorized applications from the Firewall Manager, so we can add our app to that list
Dim apps As INetFwAuthorizedApplications
apps = fwMgr.LocalPolicy.CurrentProfile.AuthorizedApplications
apps.Add(app)
End Sub
End Class
The code runs perfectly, no exception detected. Yet, the program is not listed after the form is loaded.
Thank you.
Look at this:
Programatically Add Exceptions to a Windows Firewall Using C#

Add application to startup

How can I add my application in startup items? I want my application to get added in startup when setup is run at Client's computer.
Also, how can it be automatically started after setup finishes?
Thanks
Furqan
Create a new string value in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run in registry.
For example if you application name is Test and resides in c:\programfiles\test\test.exe then
create a string value called Test and save the path c:\programfiles\test\test.exe in the string value.
Let me know if you want the setup to add your application as startup application.
Edit 1:
Sample code :
Imports Microsoft.Win32
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim regStartUp As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
Dim value As String
value = regStartUp.GetValue("Myapp")
If value <> Application.ExecutablePath.ToString() Then
regStartUp.CreateSubKey("Myapp")
regStartUp.SetValue("Myapp", Application.ExecutablePath.ToString())
End If
End Sub
End Class
You can find more details about registry here and details about registry class here.
Let me know if you have any problem with the code.
Create a shortcut or a batch file that runs your program in in Start menu > Programs > Startup folder
for example in win XP this folder would be C:\Documents and Settings\All Users\Start Menu\Programs\Startup or C:\Documents and Settings[YOURUSERNAME]\Start Menu\Programs\Startup

I need Help Making my VB 2008 Express Web Browser

Every time I click on a link it opens in Internet Explorer but I want it to open in another window of my web browser.
Details:
I created a tabbed web browser which is using a tab control. Other Controls would be a normal web browser.
You have to hookup the newwindow2 of the (old activex) browser control event like this:
Private Sub AxWebBrowser1_NewWindow2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NewWindow2Event) Handles AxWebBrowser1.NewWindow2
Dim frmWB As Form1
frmWB = New Form1()
frmWB.AxWebBrowser1.RegisterAsBrowser = True
e.ppDisp = frmWB.AxWebBrowser1.Application
frmWB.Visible = True
End Sub
Details can be found here http://support.microsoft.com/?scid=kb%3Ben-us%3B311282&x=8&y=21