ShellExecute(Handle,'open','cmd.exe',PChar('/c "C:\WINDOWS\system32\aa.bat"'),nil,SW_HIDE); //SW_SHOW/SW_HIDE
将下面的批处理文件不写成bat文件,在delphi内部写如何处理?
type C:\WINDOWS\system32\drivers\etc\hosts
type C:\WINDOWS\system32\drivers\etc\hosts | find "192.168.1.161" && goto yes
::echo 192.168.1.161 192.168.1.161 >> ""
echo 192.168.1.161 192.168.1.161 >> C:\WINDOWS\system32\drivers\etc\hosts
:yesreg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\192.168.1.161" /v http /t REG_DWORD /d 0x00000002 /f
将下面的批处理文件不写成bat文件,在delphi内部写如何处理?
type C:\WINDOWS\system32\drivers\etc\hosts
type C:\WINDOWS\system32\drivers\etc\hosts | find "192.168.1.161" && goto yes
::echo 192.168.1.161 192.168.1.161 >> ""
echo 192.168.1.161 192.168.1.161 >> C:\WINDOWS\system32\drivers\etc\hosts
:yesreg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\192.168.1.161" /v http /t REG_DWORD /d 0x00000002 /f
s:string;
begin
str:=TStringlist.Create;
try
str.LoadFromFile('C:\WINDOWS\system32\drivers\etc\hosts');
if pos('192.168.1.161',str.Text)>0 then
begin
str.Append('');
str.Append('192.168.1.161 192.168.1.161');
str.SaveToFile('C:\WINDOWS\system32\drivers\etc\hosts');
s:='reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\'
+'Internet Settings\ZoneMap\Domains\192.168.1.161" /v http /t REG_DWORD /d 0x00000002 /f';
WinExec(PChar(s),SW_HIDE);
end;
finally
str.Free;
end;
end;
var str:TStrings;
s:string;
begin
str:=TStringlist.Create;
try
str.LoadFromFile('C:\WINDOWS\system32\drivers\etc\hosts');
if pos('192.168.1.161',str.Text)<1 then //文件中找不到 192.168.1.161
begin //在文件中加入一行 192.168.1.161 192.168.1.161:
str.Append('192.168.1.161 192.168.1.161');
str.SaveToFile('C:\WINDOWS\system32\drivers\etc\hosts');
end;
//在注册表增加一个 192.168.1.161 键:
s:='reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\'
+'Internet Settings\ZoneMap\Domains\192.168.1.161" /v http /t REG_DWORD /d 0x00000002 /f';
WinExec(PChar(s),SW_HIDE);
finally
str.Free;
end;
end;