Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello everybody.

I have write Window Service follow at reference : Simple Windows Service Sample[^]

Now , i want to block a application or port on window such as : Block Port 123, Block program notepad.exe . I think it`s write in Service Onstart event

VB
Protected Overrides Sub OnStart(ByVal args() As String)

        'Block Port on Window
         'Block application on window , Example Block notepad.exe
    End Sub



Do you help me about this topic or reference link for me.

Thank you.
Posted
Updated 18-Jun-12 7:20am
v2
Comments
Nelek 18-Jun-12 13:21pm    
Edit: clickable link
headshot9x 18-Jun-12 23:43pm    
Hi Dave Kreskowiak
I have read your link, as it, in OnStart methos, we do what to do, as in this, of course Notepad window, for example, to find its path, and then lock it
Example Notepad :

Target : %windir%\system32\notepad.exe
Start in : %HOMEDRIVE%%HOMEPATH%

Protected Overrides Sub OnStart(ByVal args() As String)

'Block Port on Window
' I dont`t known

'Block application on window , Example Block notepad.exe
' Get GetCommandLineArgs Notepad
' Then change Registry of them

End Sub

If there is something wrong you can tell me
Thank you

1 solution

This is called a firewall you're attempting to write. Unless you know the Windows network stack, you'll find this extremely difficult to implement.

For testing, you could pass this information in through the services OnStart method arguments. It works just like you wrote. The arguments would be passed in as a couple of strings in an array.

http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.onstart.aspx[^]

For a production application, a firewall config is usually stored somewhere else, like an encrypted entry in the Registry or a config file.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900