原文 http://hi.baidu.com/0531_sunmiles/item/ce22554ab7d33d0be9350477
下面的这段代码是用Inno Setup 做安装包的时候创建IIS新的站点用的。因为是测试的,所以罗列了很多功能。虽然我现在用不到这么多,还是怕忘记了,做个备份。注释的部分也很宝贵啊。
本文同期发布在 论坛: http://www.jn18178.cn
{---IIS部分---}
const
IISServerName = 'localhost';
IISServerNumber = '1';
IISURL = 'http://127.0.0.1';
procedure IISButtonOnClick(Sender: TObject);
var
IIS, WebSite, WebServer, WebRoot, VDir: Variant;
WNumber,NNumber,flag,ErrorCode: Integer;
begin
if MsgBox('安装将要连接到IIS服务器 ''' + IISServerName + ''' 并创建虚拟目录,要继续吗?', mbInformation, mb_YesNo) = idNo then
Exit;
try
IIS := CreateOleObject('IISNamespace');
except
RaiseException('请先安装IIS!.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)');
end;
WebSite := IIS.GetObject('IIsWebService', GetComputerNameString() + '/w3svc');
WNumber := 1;
Repeat
flag := 0;
try
WebServer := WebSite.GetObject('IIsWebServer', inttostr(WNumber));
except
flag := 1;
WNumber := WNumber + 1;
end;
if (flag = 0) or (WNumber > 100) then
begin
NNumber := WNumber + 1;
WNumber :=0;
end;
until WNumber=0;
//MsgBox('X'+inttostr(NNumber), mbInformation, mb_Ok);
WebServer := WebSite.Create('IIsWebServer','911');
WebServer.ServerComment := '发票打印系统';
WebServer.Serverbindings := ':8888:';
WebServer.defaultDoc := 'default.asp';
WebServer.AccessScript := TRUE;
WebServer.AccessExecute := TRUE;
WebServer.AccessRead := TRUE;
WebServer.SetInfo();
WebServer := WebSite.GetObject('IIsWebServer', '911');
WebRoot := WebServer.Create('IIsWebVirtualDir', 'Root');
WebRoot.Path := 'C:\temp';
WebRoot.AppFriendlyName := '默认应用程序';
WebRoot.AppCreate(True);
WebRoot.AccessRead := TRUE;
WebRoot.AccessScript := TRUE;
WebRoot.AccessExecute :=TRUE;
WebRoot.AccessRead := TRUE;
WebRoot.SetInfo();
//try
// WebRoot.Delete('IIsWebVirtualDir', 'innosetup');
// WebRoot.SetInfo();
//except
//end;
VDir := WebRoot.Create('IIsWebVirtualDir', 'innosetup');
VDir.AccessRead := True;
VDir.AppFriendlyName := '发票打印程序';
VDir.Path := 'D:\temp';
VDir.AppCreate(True);
VDir.SetInfo();
MsgBox('Created virtual directory ''' + VDir.Path + '''.', mbInformation, mb_Ok);
{ Write some html and display it }
if MsgBox('Setup will now write some HTML and display the virtual directory. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
Exit;
ForceDirectories(VDir.Path);
//SaveStringToFile(VDir.Path + '/index.htm', '<html><body>Inno Setup rocks!</body></html>', False);
//if not ShellExec('open', IISURL + '/innosetup/index.htm', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode) then
// MsgBox('Can''t display the created virtual directory: ''' + SysErrorMessage(ErrorCode) + '''.', mbError, mb_Ok);