Installshield12 创建自定义Web站点
任务:使用Installshield12 Installscript Msi Project 打包ASP.NET应用程序,创建用户自定义的站点。
步骤:1,创建WEBNAME的Property。
2.在IS的IDE里配置IIS,如:
把WEB的虚拟目录设为[WEBNAME],安装后将使用这个属性的值,同样可以把Website名称用属性表示。注:IS在创建站点时,默认创建80端口站点,如果已有80端口的站点,虚拟目录将建在IS中80端口的站点下面,(正是我想要的,如默认会建到Default Web Site下面). 其他Virtual Diectory设置及权限设置等同于在IIS中设置
3.用脚本获取用户输入虚拟目录的名称
用SdShowDlgEdit1对话框即可,获取用户输入的名称,对WEBNAME Property赋值,Property 使用 方法。
关于卸载:这样用户自定义名称后,卸载不干净,我没有找到好的方法卸载IIS里面的虚拟目录。我相信有简单的法子就像创建时一样。以下是我使用的卸载脚本(WriteLog是我自定义的方法,adsutil.vbs可以从C:\Inetpub\AdminScripts下面找到)。把须删除的虚拟目录名称传入DelVirtualOnDefault即可:
/////////////////////////////////////////////////////////
// Function: DelVirtul
// Purpose: 删除虚拟目录
// Arguments: szWebName - BYREF
// Usage:
// Note: w3svc/1/root/ webname是1下的虚拟目录
/////////////////////////////////////////////////////////
function DelVirtul(WebName,VirtualFolder)
STRING szCmdLine,szCmd,szCmdLine2,szMsg;
NUMBER nResult;
begin
szCmd = WindowsFolder ^ "system32" ^ "cscript.exe";
szCmdLine = SUPPORTDIR ^"adsutil.vbs delete w3svc/"+WebName+"/root/"^VirtualFolder;
szCmdLine2 = SUPPORTDIR ^"adsutil.vbs delete w3svc/1/root/"^VirtualFolder;
nResult=LaunchAppAndWait(szCmd, szCmdLine, NOWAIT|LAAW_OPTION_HIDDEN);
Sprintf(szMsg,"Run "+szCmdLine+" result is %ld",nResult);
WriteLog(szMsg);
nResult=LaunchAppAndWait(szCmd, szCmdLine2, NOWAIT|LAAW_OPTION_HIDDEN);
Sprintf(szMsg,"Run "+szCmdLine2+" result is %ld",nResult);
WriteLog(szMsg);
WriteLog("del virtualFolder:"+VirtualFolder+" on:"+WebName);
end;
/////////////////////////////////////////////////////////
// Function: DelVirtualOnDefault
// Purpose: 把建在默认80端口的站点的同名虚拟目录删掉
// Arguments: VirtualFolder - 虚拟目录的名称
// Usage:
// Note: 须引用IsGetObj.dll
/////////////////////////////////////////////////////////
prototype ISGetObj.VBGetObject(byval string, byval string, byref OBJECT);
prototype ISGetObj.ForEachStart(byref OBJECT, byref VARIANT);
prototype ISGetObj.ForEachGetNextItem(byref VARIANT, byref OBJECT);
//////////////////////////////////////////////////////////
prototype DelVirtualOnDefault(STRING);
function DelVirtualOnDefault(VirtualFolder)
OBJECT objIIS_Root, objVirtDir,objWebService,objWebSite;
NUMBER nResult,nCount,nIndex;
VARIANT vTemp,strTemp,strTemp2;
VARIANT __varEnumHolder; //Hold IEnumVariant during the ForEachLoop, don't use OBJECT type, this is an IUnknown!!
begin
UseDLL(SUPPORTDIR ^ "IsGetObj.dll");
set objWebService = CoGetObject("IIS://Localhost/W3svc", "");
if IsObject( objWebService ) then
ForEachStart(objWebService, __varEnumHolder);
nResult = ForEachGetNextItem(__varEnumHolder, objWebSite);
while ( nResult = ERROR_SUCCESS )
if IsObject(objWebSite) then
if objWebSite.class = "IIsWebServer" then
vTemp= objWebSite.ServerBindings;
strTemp = vTemp(0);
if(strTemp==":80:")then
// 找到80端口下的站点Name
strTemp2=objWebSite.Name ;
WriteLog("webname:"+strTemp2);
DelVirtul(strTemp2,VirtualFolder);
endif;
endif;
endif;
nResult = ForEachGetNextItem(__varEnumHolder, objWebSite);
endwhile;
endif;
UnUseDLL("IsGetObj.dll");
end;
/***************************************************/
// Function: DelVirtul
// Purpose: 删除虚拟目录
// Arguments: szWebName - BYREF
// Usage:
// Note: w3svc/1/root/ webname是1下的虚拟目录
/////////////////////////////////////////////////////////
function DelVirtul(WebName,VirtualFolder)
STRING szCmdLine,szCmd,szCmdLine2,szMsg;
NUMBER nResult;
begin
szCmd = WindowsFolder ^ "system32" ^ "cscript.exe";
szCmdLine = SUPPORTDIR ^"adsutil.vbs delete w3svc/"+WebName+"/root/"^VirtualFolder;
szCmdLine2 = SUPPORTDIR ^"adsutil.vbs delete w3svc/1/root/"^VirtualFolder;
nResult=LaunchAppAndWait(szCmd, szCmdLine, NOWAIT|LAAW_OPTION_HIDDEN);
Sprintf(szMsg,"Run "+szCmdLine+" result is %ld",nResult);
WriteLog(szMsg);
nResult=LaunchAppAndWait(szCmd, szCmdLine2, NOWAIT|LAAW_OPTION_HIDDEN);
Sprintf(szMsg,"Run "+szCmdLine2+" result is %ld",nResult);
WriteLog(szMsg);
WriteLog("del virtualFolder:"+VirtualFolder+" on:"+WebName);
end;
/////////////////////////////////////////////////////////
// Function: DelVirtualOnDefault
// Purpose: 把建在默认80端口的站点的同名虚拟目录删掉
// Arguments: VirtualFolder - 虚拟目录的名称
// Usage:
// Note: 须引用IsGetObj.dll
/////////////////////////////////////////////////////////
prototype ISGetObj.VBGetObject(byval string, byval string, byref OBJECT);
prototype ISGetObj.ForEachStart(byref OBJECT, byref VARIANT);
prototype ISGetObj.ForEachGetNextItem(byref VARIANT, byref OBJECT);
//////////////////////////////////////////////////////////
prototype DelVirtualOnDefault(STRING);
function DelVirtualOnDefault(VirtualFolder)
OBJECT objIIS_Root, objVirtDir,objWebService,objWebSite;
NUMBER nResult,nCount,nIndex;
VARIANT vTemp,strTemp,strTemp2;
VARIANT __varEnumHolder; //Hold IEnumVariant during the ForEachLoop, don't use OBJECT type, this is an IUnknown!!
begin
UseDLL(SUPPORTDIR ^ "IsGetObj.dll");
set objWebService = CoGetObject("IIS://Localhost/W3svc", "");
if IsObject( objWebService ) then
ForEachStart(objWebService, __varEnumHolder);
nResult = ForEachGetNextItem(__varEnumHolder, objWebSite);
while ( nResult = ERROR_SUCCESS )
if IsObject(objWebSite) then
if objWebSite.class = "IIsWebServer" then
vTemp= objWebSite.ServerBindings;
strTemp = vTemp(0);
if(strTemp==":80:")then
// 找到80端口下的站点Name
strTemp2=objWebSite.Name ;
WriteLog("webname:"+strTemp2);
DelVirtul(strTemp2,VirtualFolder);
endif;
endif;
endif;
nResult = ForEachGetNextItem(__varEnumHolder, objWebSite);
endwhile;
endif;
UnUseDLL("IsGetObj.dll");
end;
/***************************************************/
由于Installscript中没有for each ,其中调用了一个自定义的DLL:IsGetObj.dll
Download: IsGetObje.DLL文件