代码如下,就是将当前的目录设为默认的虚拟目录,相信能够举一反三吧!
var
WebSite, WebServer, WebRoot: Variant;
vFileName: String;
vInifile: Tinifile;
begin
frmServer.Cursor := crHourGlass;
vFileName := ExtractFilePath(ParamStr(0)) + 'Config/iadmin.ini';
vInifile := Tinifile.Create(vFileName);
try
Label5.Visible := true;
try
Application.ProcessMessages;
WebSite := CreateOleObject('IISNamespace');
WebSite := WebSite.GetObject('IIsWebService', 'localhost/w3svc');
WebServer := WebSite.GetObject('IIsWebServer', '1');
WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root');
Sleep(2000);
WebRoot.Path := ExtractFileDir(ParamStr(0));
WebRoot.AccessRead := true;
WebRoot.SetInfo;
vInifile.WriteString('configure','Path',ExtractFileDir(ParamStr(0)));
MessageBox(Handle,'WEB服务器虚拟目录设置完毕! ','系统信息',0+64);
except
On E: Exceptiondo
MessageBox(Handle,PChar('WEB服务器虚拟目录设置失败:' + E.Message),'系统消息',0+16);
end;
finally
Label5.Visible := false;
frmServer.Cursor := crDefault;
WebSite := Null;
WebServer := Null;
WebRoot := Null;
vInifile.Destroy;
end;
end;