Click here to Skip to main content
11,631,992 members (70,000 online)
Click here to Skip to main content

Create IIS Virtual Directory

, 22 Dec 2006 CDDL 37.9K 717 15
Rate this:
Please Sign up or sign in to vote.
This is a command line program that will enable users to create a Virtual Directory on a local host.

Create Virtual Directory

Create Virtual Directory

Invalid Parameters

Invalid Parameters

IIS Entry

Entry In IIS

Introduction

As per the name, it's easy to guess what this project is all about, creating a virtual directory in the default web site (80). The program uses the IIS Administration SDK, which has the Active Directory Service Interfaces (ADSI) that helps VC++ to access the required functions and interfaces.

Background

I started looking on the net for similar programs that uses ADSI with VC++, but was not able to find one, so thought of creating one.

Using the code

To access the ADSI functions, we need to have the following header files.

// The basic header files used
iads.h
adshlp.h
iiisext.h
iisext_i.c
// Constant used to access the default port 80 
// We take IIS://localhost/w3svc/1/Root
// as the path to access the default web site 
const LPWSTR adsPATH = L"IIS://localhost/w3svc/1/Root"; 
IDispatch *pDisp = NULL; //Idispatch interface object
IADs* iAds = NULL; //Active Directory Interface 
IADsContainer* iContainer = NULL; //Active Directory Container Interface 
IISApp *pApp = NULL; //Active Directory IIS Application interface 

Access the ADSI object

//Get Object of  Active Drectory Container ADsGetObject(adsPATH, 
IID_IADsContainer,(void **)&iContainer);

Creating a virtual directory

hr = iContainer->Create(L"IIsWebVirtualDir", cAppName,  &pDisp);

Creating the application with the use of QueryInterface

hr = iAds->QueryInterface( IID_IISApp, (void **)&pApp  );

Accessing the virtual directory property using the iAds interface

hr = iAds->Put(L"AccessRead",CComVariant(VARIANT_TRUE));    
hr = iAds->Put(L"AccessWrite",CComVariant(VARIANT_TRUE));    
hr = iAds->Put(L"AccessScript",CComVariant(VARIANT_TRUE));    
hr = iAds->Put(L"AppIsolated",CComVariant(1));    
hr = iAds->Put(L"EnableDirBrowsing",CComVariant(VARIANT_TRUE));    
hr = iAds->Put(L"AppFriendlyName",CComVariant(cAppName));
hr = iAds->Put(L"Path",CComVariant(clPath)); //Virtual Dir Physicial Path    

Update the changes to the ASDI objects

hr = iAds->SetInfo();
//Save Virtual Dir Application Information

Linking issues

You might end up in getting a link error. To solve this,s the following libraries need to be included:

Activeds.lib 
Adsiid.lib

The currently supported languages are: C++.

Points of interest

While trying out lots of options, I had to interpret .NET code and transform it in to VC++, and one thing I found is whatever the language is, you just need a vision to make it work.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)

Share

About the Author

moonwalker_n2700
Web Developer
India India
Sreeji Gopal working in VOIP domain and languages VC++,COM,C++,VB. Working as Sr.Software Engineer, with Alcatel-Lucent. I am working in this industry for 6 yrs.

You may also be interested in...

Comments and Discussions

 
GeneralCompile in VS 2005 Pin
shahhmatist12-Apr-07 4:52
membershahhmatist12-Apr-07 4:52 
I try to compile your project in VS 2005, but there are some error messagies - "IISApp: undeclared identifier" and "IID_IISApp' : undeclared identifier". Can you tell me how they can be fixed.

GeneralRe: Compile in VS 2005 Pin
Zeef21-May-07 7:46
memberZeef21-May-07 7:46 
QuestionHow to set username and password Pin
Aarif Mohammad11-Jan-07 23:09
memberAarif Mohammad11-Jan-07 23:09 
QuestionWhy? Pin
Mark Nischalke22-Dec-06 18:05
memberMark Nischalke22-Dec-06 18:05 
AnswerRe: Why? Pin
moonwalker_n270022-Dec-06 18:32
membermoonwalker_n270022-Dec-06 18:32 
GeneralRe: Why? Pin
Mark Nischalke23-Dec-06 2:50
memberMark Nischalke23-Dec-06 2:50 
GeneralRe: Why? Pin
moonwalker_n270023-Dec-06 5:30
membermoonwalker_n270023-Dec-06 5:30 
GeneralRe: Why? Pin
Mark Nischalke23-Dec-06 7:31
memberMark Nischalke23-Dec-06 7:31 
GeneralRe: Why? Pin
moonwalker_n270023-Dec-06 17:24
membermoonwalker_n270023-Dec-06 17:24 
GeneralRe: Why? Pin
Zeef21-May-07 7:50
memberZeef21-May-07 7:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150728.1 | Last Updated 22 Dec 2006
Article Copyright 2006 by moonwalker_n2700
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid