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

  • Home
  • SEARCH
  • 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 619481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:39:36+00:00 2026-05-13T18:39:36+00:00

I am working on an ASP.Net Web Site Provisioning software using WMI(System.Managment) and C#.

  • 0

I am working on an ASP.Net Web Site Provisioning software using WMI(System.Managment) and C#.

I am trying to create FTP site on my “Target Server” located somewhere on LAN while executing code on my host machine. I have trouble starting the FTP Site after its creations.

The error being reported is “Invalid Class” on the following line:

ManagementObject site = new ManagementObject(
          new ManagementPath(string.Format(@"IIsFtpServer.Name='MSFTPSVC/{0}'", siteId)), null);
        **site.InvokeMethod("Start", null);**

Here is my Complete Function.

public static String CreateFtpsite(String serverName,
    String ip,String ServerComment,int AccessFlags,
    String pathToRoot, String hostName, String domainName, int port)
{
    //ConnectionOptions options = new ConnectionOptions();
    //options.Authentication = AuthenticationLevel.Connect;
    //options.EnablePrivileges = true;
    //options.Impersonation = ImpersonationLevel.Impersonate;
    ConnectionOptions options = SetUpAuthorization();
    ManagementScope scope =
       new ManagementScope(string.Format(@"\\{0}\root\MicrosoftIISv2", serverName), options);
    scope.Connect();
    ManagementObject oW3SVC = new ManagementObject(scope,
    new ManagementPath(@"IIsFtpService='MSFTPSVC'"), null);

    ManagementBaseObject[] serverBindings = new ManagementBaseObject[3];
    /*serverBindings[0] = CreateServerBinding(scope, 
                        string.Format("{0}.{1}", hostName, domainName), ip, port);
    */
    serverBindings[0] = CreateServerBinding(scope,
                        string.Format("{0}", hostName, domainName), ip, port);
    serverBindings[1] = CreateServerBinding(scope,
                        string.Format(ip, hostName, domainName), ip, port);
    serverBindings[2] = CreateServerBinding(scope,
                        string.Format("127.0.0.1", hostName, domainName), ip, port);

    ManagementBaseObject inputParameters = oW3SVC.GetMethodParameters("CreateNewSite");

    inputParameters["ServerBindings"] = serverBindings;
    inputParameters["ServerComment"] = ServerComment;
    inputParameters["PathOfRootVirtualDir"] = pathToRoot;

    ManagementBaseObject outParameter =
      oW3SVC.InvokeMethod("CreateNewSite", inputParameters, null);

    string siteId = Convert.ToString(
     outParameter.Properties["ReturnValue"].Value).Replace(
     "IIsFtpServer='MSFTPSVC/", "").Replace("'", "");
    ManagementObject oFtpVirtDir = new ManagementObject(scope,
    new ManagementPath(string.Format(
        @"IIsFtpVirtualDirSetting.Name='MSFTPSVC/{0}/root'", siteId)), null);
    oFtpVirtDir.Properties["AccessFlags"].Value = AccessFlags ;
    oFtpVirtDir.Properties["Path"].Value = pathToRoot;

    ManagementObject oFtpVirtDirProperties = new ManagementObject(scope,
    new ManagementPath(string.Format(@"IIsFtpServerSetting.Name='MSFTPSVC/{0}'", siteId)), null);
    oFtpVirtDirProperties.Properties["AllowAnonymous"].Value  = true;
    oFtpVirtDirProperties.Properties["AnonymousOnly"].Value = true;
    oFtpVirtDirProperties.Properties["AnonymousUserName"].Value = @"DevIIS\Administrator";
    oFtpVirtDirProperties.Properties["AnonymousUserPass"].Value = "Passw0rd";
    oFtpVirtDirProperties.Properties["MaxConnections"].Value = 555;
    oFtpVirtDirProperties.Properties["ServerAutoStart"].Value = true;
    oFtpVirtDirProperties.Properties["UserIsolationMode"].Value = 1;
    oFtpVirtDirProperties.Properties["ConnectionTimeout"].Value = 1234 ;
    oFtpVirtDirProperties.Properties["LogFileTruncateSize"].Value = 54321;
    oFtpVirtDirProperties.Put();

    ManagementObject site = new ManagementObject(
      new ManagementPath(string.Format(@"IIsFtpServer.Name='MSFTPSVC/{0}'", siteId)), null);
    site.InvokeMethod("Start", null); //Error occurs Here (Invalid Class)
    return siteId;
}

public static ConnectionOptions SetUpAuthorization()
    {
        ConnectionOptions options = new ConnectionOptions();

        options.Authentication = AuthenticationLevel.PacketPrivacy;
        options.EnablePrivileges = true;
        options.Impersonation = ImpersonationLevel.Impersonate;
        options.Username = @"DevIIS\Administrator";
        options.Password = "Passw0rd";
        return options;
    }

On analyzing the Code, i find that the “site” object throws exception of “Invalid Class” on "site.ClassPath".

I have also tried to use the following line but the same error is there.

ManagementObject site = new ManagementObject(scope, 
      new ManagementPath(Convert.ToString(
      outParameter.Properties["ReturnValue"].Value)), null);

        site.InvokeMethod("Start", null);

But the FTP Site is created and all its properties are set but it doesn’t start via code. One may manually start it by going to IIS Manager .

The Code works perfectly fine on IIS 6.0 and (since i am using using WMI ) i expect that it should run fine on IIS 7.0 or later too.

I am doing something wrong but couldn’t guess where. Kindly help. Thanks.

Thanks

  • 1 1 Answer
  • 1 View
  • 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-13T18:39:36+00:00Added an answer on May 13, 2026 at 6:39 pm

    in iis7 it does not create “MSFTPSVC” folder in the metabase. it places ftpsite in the website container in the database. so the answer will be :
    use @”IIsWebService=’W3SVC'” as a management path, instead of what you are using.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an asp.net web site. We have to use com interop to
Very often when working on an ASP.NET web site, the options View Code and
I'm working on an ASP .NET 2.0 site which uses a Web Application project
I am working on an asp.net web site that is based upon a single
I am currently working with a ASP.NET Web site project in Visual Studio 2008
I'm currently working on an ASP.NET web-site. In one of my pages, I had
While working on ASP.NET MVC 2 web site I faced to the following problem.
I am working on a ASP.NET MVC web site which has a form that
I am working on a ASP.NET MVC web site that has multiple submit buttons.
I am working on a asp.net web site, like normal user, we use asp.net

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.