Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6982845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:20:31+00:00 2026-05-27T18:20:31+00:00

i am trying to get my application to be allowed through firewall, as I

  • 0

i am trying to get my application to be allowed through firewall, as I have to do ftp in active and passive mode is not an option as servers are not configured for that. so i tried the below code which compiles fine, I exexcute it using:

 MyApp.Classes.INetFwMgr mgr = new MyApp.Classes.INetFwMgr();
    mgr.AuthorizeApplication(Application.ProductName, Application.StartupPath,
        NET_FW_SCOPE_.NET_FW_SCOPE_ALL,
        NET_FW_IP_VERSION_.NET_FW_IP_VERSION_ANY);

And the class which does the job:

private const string CLSID_FIREWALL_MANAGER = 
"{304CE942-6E39-40D8-943A-B913C40C9CD4}"; 
private static NetFwTypeLib.INetFwMgr GetFirewallManager() 
{ 
Type objectType = Type.GetTypeFromCLSID( 
new Guid(CLSID_FIREWALL_MANAGER)); 
return Activator.CreateInstance(objectType) 
as NetFwTypeLib.INetFwMgr; 
} 


private const string PROGID_AUTHORIZED_APPLICATION = 
"HNetCfg.FwAuthorizedApplication"; 
public bool AuthorizeApplication(string title, string applicationPath, 
NET_FW_SCOPE_ scope, NET_FW_IP_VERSION_ ipVersion) 
{ 
// Create the type from prog id 
Type type = Type.GetTypeFromProgID(PROGID_AUTHORIZED_APPLICATION); 
INetFwAuthorizedApplication auth = Activator.CreateInstance(type) 
as INetFwAuthorizedApplication; 
auth.Name = title; 
auth.ProcessImageFileName = applicationPath; //Getting Access Denied Exception Here
auth.Scope = scope; 
auth.IpVersion = ipVersion; 
auth.Enabled = true; 
NetFwTypeLib.INetFwMgr manager = GetFirewallManager(); 
try 
{ 
manager.LocalPolicy.CurrentProfile.AuthorizedApplications.Add(auth); 
} 
catch (Exception ex) 
{ 
return false; 
} 
return true; 
}

using above code, but i get Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) c# exception on line

auth.ProcessImageFileName = applicationPath;

any ideas what to do ?

Edit1: How would i run this as an admin using code?

Edit2: I also tried Putting <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> in manifest did not make a difference

P.S.This programs execution context can be Win 7, vista, xp

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:20:32+00:00Added an answer on May 27, 2026 at 6:20 pm

    i have observed that if i change the order of ftp download statements to following windows dialog appears asking that do you want to allow this program access through firewall; if i click allow access the code works perfectly.

    requestDownload = (FtpWebRequest)WebRequest.Create(uri);
                                requestDownload.UsePassive = false;
                                requestDownload.KeepAlive = false;
                                requestDownload.UseBinary = true;
                                requestDownload.Method = WebRequestMethods.Ftp.DownloadFile;
    
    
                                requestDownload.Credentials = new NetworkCredential(ftpInfoDownload[3], ftpInfoDownload[4]);
    
                                responseDownload = (FtpWebResponse)requestDownload.GetResponse();
                                Stream ftpStream = responseDownload.GetResponseStream();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get an application to pass the Windows 7 Software Logo Toolkit
Trying to get an ASP application deployed; it worked for a while but then
I am trying to get my ZEND application up on my apache server running
I'm trying to get a CakePHP application to work. For this, I've set up
I am trying to get my Blackberry application to display a custom modal dialog,
I've been trying desperately to get my application (15 C# dlls and 1 C++/CLI
I'm running CentOS 5, and am trying to get a django application working with
We are trying to get quaqua out of our application. We had been using
I'm trying to get a new Enterprise Application Project set up in Eclipse using
I am trying to get logging via the application.ini file going and I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.