Solved

windows firewall priviligies code problem

Posted on 2008-10-12
2
260 Views
Last Modified: 2012-05-05
Hello Experts,
i am trying to put a useful coding regarding the windows firewall but i am getting some problem,it doesn't work.




ps
i checked with "regedit" for the right path and everything seems ok
char path[512];
char dspname[] = "Winservice";
 
 
 
int AddToWindowsFirewall(char *displayname,char * path)
{
    
    
    HKEY hKey;
    
    char filedata[MAX_PATH] = "";
 
    wsprintf(filedata,"%s:*:Enabled:%s",path,displayname);
 
    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"System\\ControlSet001\\Services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\\AuthorizedApplications\\List",0,KEY_ALL_ACCESS,&hKey)) return 0;
    //if(RegSetValueEx(hKey,path,0,REG_SZ,(unsigned char*)filedata,sizeof(filedata),37)) 
    if(RegSetValueEx(hKey,path,0,REG_SZ,reinterpret_cast<const BYTE*>(filedata),58)) return 0;
    
    RegCloseKey(hKey);
    
}    
 
 
 
int WINAPI WinMain( HINSTANCE,  HINSTANCE, LPSTR, int)
    
 
{
  some code here
 
  AddToWindowsFirewall(dspname,path);
 
 other code here
 
 
}

Open in new window

0
Comment
Question by:kagami01
2 Comments
 
LVL 6

Accepted Solution

by:
ChristianWimmer earned 300 total points
ID: 22710697
I think you need to use the Firewall COM API : http://msdn.microsoft.com/en-us/library/aa366453(VS.85).aspx
There is also an example available: http://msdn.microsoft.com/en-us/library/aa364726(VS.85).aspx

If you can read Delphi code you can also check out the whole usage of this API:
http://jedi-apilib.svn.sourceforge.net/viewvc/jedi-apilib/jwscl/trunk/source/JwsclFirewall.pas?revision=645&view=markup
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL400 max size 5 93
allswap challenge 6 99
Path to  STL Map header file 1 58
Beginner to Unreal Engine 4 5 80
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This video teaches viewers about errors in exception handling.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question