cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
thurein
Level 3

Deleting the existting IIS Virtual Directory

Hi.

Is there any ways that the MSI can delete the IIS Virtual Diectory (or web application) under the Default Web Site, before installing a feature.

Thanks
Thurein
Labels (1)
0 Kudos
(9) Replies
Vijay__K
Level 7

Hi,
I don't know of a way to do it through installshield.
I used a custom action.

function DeleteVirtualDir(hMSI, szDeleteVR)
OBJECT objIIS_Root, objIIS_Sub;
begin

set objIIS_Root = CoGetObject("IIS://localhost/W3SVC/1/Root", "");
set objIIS_Sub = CoGetObject("IIS://localhost/W3SVC/1/Root/" + szDeleteVR, "");

if (IsObject(objIIS_Sub)) then
objIIS_Root.Delete("IISWebVirtualDir", szDeleteVR);
SprintfMsiLog ( "DeleteVirtualDir deleted virtual directory: %s" , szDeleteVR);
else
SprintfMsiLog ( "DeleteVirtualDir could not delete virtual directory: %s" , szDeleteVR);
endif;

end;


hope this helps.
Vijay
0 Kudos
thurein
Level 3

I was trying to get the IIS object by using the following code almost the same logic as urs

set objIIS_Root = CoGetObject("IIS://localhost/W3SVC/1/Root", "");
if (IsObject(objIIS_Root)) then
\\do delete
but the objIIS_Root object got empty all the time so it won't pass the if statement and the delete logic will not be executed. I have tested the above code in both IIS 6 and 7. Pls advice what I am doing wrong.

Thanks Thurein
0 Kudos
Vijay__K
Level 7

What part of the ROOT are you deleting?
Post your full code example.
0 Kudos
thurein
Level 3

following is my code. When I check the MSI log, it said "could not delete virtual directory" which means it is only going through the else statement. In my IIS, I have a "Default Web Site" and under that I created a Application called "MyVitualDir".

function MyFunction(hMSI)

OBJECT objIIS_Root, objIIS_Sub;
begin

set objIIS_Root = CoGetObject("IIS://localhost/W3SVC/1/Root", "");
set objIIS_Sub = CoGetObject("IIS://localhost/W3SVC/1/Root/MyVitualDir" , "");

if (IsObject(objIIS_Sub)) then
objIIS_Root.Delete("IISWebVirtualDir", "MyVitualDir");
SprintfMsiLog ( "DeleteVirtualDir deleted virtual directory: %s" , "MyVitualDir");
else
SprintfMsiLog ( "DeleteVirtualDir could not delete virtual directory: %s" , "MyVitualDir");
endif;

end;

Thanks
0 Kudos
Vijay__K
Level 7

Hi,

Is the action you have created, deferred in system context?

On operating systems with UAC.
It needs to be deferred in system context to remove the iis. So you might aswell try this before the IIS website are created again in the execute part of the msi installation.
0 Kudos
thurein
Level 3

Hi,
I have set the "In-Script Execution" to "Deffered Execution in System Context" and "Install Exec Sequence" to "After InstallInitialize" but it is still going through the else statement. Any idea ?

Thanks
0 Kudos
Vijay__K
Level 7

Are you running it in the execute part of the installation and not from a button click?
0 Kudos
thurein
Level 3

I just double clicked on the setup.exe.

Thanks
0 Kudos
Vijay__K
Level 7

Yes, you need to run the installation using the setup.exe, but where/how are you running the custom action to delete the virtual directory?
0 Kudos