There are many examples on the Internet about using DELPHI to establish a virtual directory of IIS, but they all require loading the class library. I use the method of writing a registry to implement it. The method is simple, mainly because there is no need to add classes, the only one The difference is that you need to restart the computer before it can take effect. The code is as follows:
PRocedure TForm1.Button1Click(Sender: TObject);
var
RegODBC:TRegistry;
registerTemp: TRegistry;
SysPath: array [0..255] of char;
Begin
RegODBC:=TRegistry.create; //Access the registry
RegODBC.RootKey:=HKEY_LOCAL_MACHINE;
RegODBC.OpenKey('/SYSTEM/ControlSet001/Services/W3SVC/Parameters/Virtual Roots',True);
getsystemdirectory(SysPath, 255);
if regodbc.ValueExists('/fire') then
Begin
suimessage1.Text:='Native WEB already has a virtual directory named fire. '+#13#10+' Please delete or rename this fire. ';
suimessage1.IconType:=suitop;
suimessage1.ButtonCount:=1;
suimessage1.Caption:='Error';
if suimessage1.ShowModal=mrok then
winexec(pchar(SysPath+'/inetsrv/inetmgr.exe'),sw_shownormal);
exit;
end
else
Begin
registerTemp := TRegistry.Create; //Create a Registry instance
with registerTemp do
Begin
RootKey:=HKEY_LOCAL_MACHINE;//Set the root key value to HKEY_LOCAL_MACHINE
//Find or create /SYSTEM/ControlSet001/Services/W3SVC/Parameters/Virtual Roots, write IIS configuration information
if OpenKey('/SYSTEM/ControlSet001/Services/W3SVC/Parameters/Virtual Roots',True) then
Begin
WriteString('/fire','E:/fire,,205');
end
else//Create key value failed
Begin
suimessage1.Text:='IIS configuration failed and this program will be closed soon. '+#13#10+' After closing, please check the Internet service manager first, troubleshoot errors or install them before running this program. ';
suimessage1.IconType:=suitop;
suimessage1.ButtonCount:=1;
suimessage1.Caption:='Error';
if suimessage1.ShowModal=mrok then
application.Terminate;
end;
CloseKey;
Free;
end;
end;
RegODBC.Free;
end;
Note: The suimessagedialog component of the suipack4 control is used in the code. The example confirmation window can also be replaced by Application.MessageBox(). If you are interested in this, please contact me. [email protected] QQ:49055028