473,804 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding a port to the XP-Firewall

Hi,

is there a programmatical way to add a port to the XP SP2 Firewall and
open it or does this have to be configured manually??

Martin
Nov 16 '05 #1
2 16947
Hi Martin,

We can use the hnetcfg.dll Com object.
Here is a link you may take a look.
Adding a Port to Current Profile (VBScript)
http://msdn.microsoft.com/library/de...us/ics/ics/wf_
adding_port_to_ profile.asp

We can convert it into C# as below.
Here is the code below.
[NOTE: we need add a COM reference to the hnetcfg.dll
first(<windows> \system32\hnetc fg.dll)

using System;
using NetFwTypeLib;
using System.Runtime. InteropServices ;
using System.Reflecti on;
using System.Diagnost ics;
namespace OpenPort
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
INetFwMgr icfMgr =null;
try
{
Type TicfMgr = Type.GetTypeFro mProgID("HNetCf g.FwMgr");
icfMgr = (INetFwMgr)Acti vator.CreateIns tance(TicfMgr);
}
catch (Exception ex)
{
Trace.WriteLine (ex.ToString()) ;
return;
}
try
{

INetFwProfile profile;
INetFwOpenPort portClass;
Type TportClass = Type.GetTypeFro mProgID("HNetCf g.FWOpenPort");
portClass = (INetFwOpenPort )Activator.Crea teInstance(Tpor tClass);
// Get the current profile
profile = icfMgr.LocalPol icy.CurrentProf ile;

// Set the port properties
portClass.Scope = NetFwTypeLib.NE T_FW_SCOPE_.NET _FW_SCOPE_ALL;
portClass.Enabl ed = true;
portClass.Name = "TestPort";
portClass.Port = 1124;
portClass.Proto col =
NetFwTypeLib.NE T_FW_IP_PROTOCO L_.NET_FW_IP_PR OTOCOL_TCP;;

// Add the port to the ICF Permissions List
profile.Globall yOpenPorts.Add( portClass);
return;
}
catch (Exception ex)
{
Trace.WriteLine (ex.ToString()) ;
}
}
}
}
Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #2
Thanks Peter!

This is a really good one.

Martin
Peter Huang [MSFT] wrote:
Hi Martin,

We can use the hnetcfg.dll Com object.
Here is a link you may take a look.
Adding a Port to Current Profile (VBScript)
http://msdn.microsoft.com/library/de...us/ics/ics/wf_
adding_port_to_ profile.asp

We can convert it into C# as below.
Here is the code below.
[NOTE: we need add a COM reference to the hnetcfg.dll
first(<windows> \system32\hnetc fg.dll)

using System;
using NetFwTypeLib;
using System.Runtime. InteropServices ;
using System.Reflecti on;
using System.Diagnost ics;
namespace OpenPort
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
INetFwMgr icfMgr =null;
try
{
Type TicfMgr = Type.GetTypeFro mProgID("HNetCf g.FwMgr");
icfMgr = (INetFwMgr)Acti vator.CreateIns tance(TicfMgr);
}
catch (Exception ex)
{
Trace.WriteLine (ex.ToString()) ;
return;
}
try
{

INetFwProfile profile;
INetFwOpenPort portClass;
Type TportClass = Type.GetTypeFro mProgID("HNetCf g.FWOpenPort");
portClass = (INetFwOpenPort )Activator.Crea teInstance(Tpor tClass);
// Get the current profile
profile = icfMgr.LocalPol icy.CurrentProf ile;

// Set the port properties
portClass.Scope = NetFwTypeLib.NE T_FW_SCOPE_.NET _FW_SCOPE_ALL;
portClass.Enabl ed = true;
portClass.Name = "TestPort";
portClass.Port = 1124;
portClass.Proto col =
NetFwTypeLib.NE T_FW_IP_PROTOCO L_.NET_FW_IP_PR OTOCOL_TCP;;

// Add the port to the ICF Permissions List
profile.Globall yOpenPorts.Add( portClass);
return;
}
catch (Exception ex)
{
Trace.WriteLine (ex.ToString()) ;
}
}
}
}
Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3444
by: Ed | last post by:
Here's the scene: 1) XP Pro, with IIS installed and running, as well as complete .NET Architect Enterprise development environment 2) Tomcat server 4.1.27 in the default directory jakarta-tomcat-4.1.27 3) Java NetBeans "cobundle" installed in the default directory (j2sdk_nb\j2sdk1.4.2) 4) JSP environment variables set (JAVA_HOME and CATALINA_HOME) WHen I run Internet Explorer and enter the address http://localhost:8080/ I
0
3269
by: I.P. | last post by:
Hi, it's my story. I have two 4.0.14 mysql server on one machine with win XP Professional polish version. First acts as master: on port 3300 Second acts as slave: on port 3301 below my configuration:
0
2150
by: I.P. | last post by:
No one has replied to my post. ----- Original Message ----- From: "I.P." <jancio_wodnik@wp.pl> To: <mysql@lists.mysql.com> Sent: Monday, August 18, 2003 1:01 PM Subject: mysql 4.0.14 + replication + windows XP PROF Hi, it's my story.
0
583
by: I.P. | last post by:
------=_NextPart_000_03FF_01C368A4.75720DC0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable Hi, it's my story. I have two 4.0.14 mysql server on one machine with win XP Professional polish version.
3
3713
by: Billism | last post by:
My email client (I programmed) recently has stopped being able to send email with my XP machine. I have had 3 other friends test it and the same thing happens. The program has not changed, but Windows XP has. My program can connect to any other port (that I've tried) on a remote machine. However, when trying to connect to port 25 (SMTP), immediately, socket error 10053 occurs, and the socket fails to connect because of it. The problem is...
6
7248
by: Novice Experl | last post by:
I'd like to write a simple application that interfaces with the parallel port, and changes the data on it according to keyboard input. I hope I can get it to run under windows xp and / or windows 2000. How can I do this? What do I need to know? It doesn't look like the standard library (the one under my pillow) has that feature. In addition, I've heard that with newer versions of windows don't let you communicate with the port directly,...
20
2892
by: Jason Dravet | last post by:
Some time ago I wrote an application that controls the projectors in our classrooms(turn on, turn off, and volume control). This application is written in VB.net 2003. It was working perfectly until XP SP2 was installed on the PCs. Now when the power on or power off button is pressed the following message is displayed: An unhandled exception has occurred in your application. If you click Continue, the application will ignore this...
3
11358
by: Sells, Fred | last post by:
I'm using MSW XP Pro with Python 2.4 to develop but production will be Linux with Python 2.3. (could upgrade to 2.4 if absolutely necessary) I can also switch to Linux for development if necessary. I am writing some python to replace proprietary software that talks to a timeclock via UDP. The timeclock extracts the sending port from the UDP header and uses that for all response messages.
9
2977
by: Alexandre Brisebois | last post by:
Hi all, How can I have my application running on port 80 while ISS and other applications also run through port 80? for remoting (without hosting it in IIS) and or simply using sockets. regards, Alexandre Brisebois
6
9321
by: abhi | last post by:
Hello, I want to create a small project which will display scrolling text on LED that will be attached to Parallel port. I want to create this project in C language(possibly in Mingw) on Windows XP. I want to know how can i access(read and write data) on parallel port in XP. I have a program that do the same thing but in its documentation it says that it will not work on Windows XP.
0
9711
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
9593
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
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
10343
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
10335
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
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
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
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.