高分求解:如何编程修改本地计算机策略(组策略),达到自动修改Windows升级服务器位置
我想在Intranet内设立一台Windows升级服务器(已实现),然后将客户机的Windows升级源都指到这一台服务器。手工修改策略的方法是:
1、用gpedit.msc打开组策略编辑器,确认左边树形菜单中“本地计算机”策略--计算机配置--管理模板--Windows组件 是否有Windows Update。
2、如果没有,则在上述的“管理模板”上点右键选择“添加/删除模板”,然后选择“添加”wuau.adm,然后将出现Windows Update。
3、在Windows Update下设置“配置自动更新”、“指定Intranet Microsoft更新服务位置”。
但考虑到以上办法太麻烦,因此想编程实现。
通过查找特征值,我想通过修改注册表来实现,但未能成功,代码如下:
//停止Windows Automatic Updates服务
winexec(PChar('net stop wuauserv'), SW_HIDE);
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.DeleteKey('\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update');
if Reg.OpenKey('\Software\Policies\Microsoft\Windows\WindowsUpdate', True) then
begin
Reg.WriteString('WUServer','http://10.151.18.114');
Reg.WriteString('WUStatusServer','http://10.151.18.114');
if Reg.OpenKey('\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU', True) then
begin
Reg.WriteInteger('AUOptions',3);
Reg.WriteInteger('NoAutoUpdate',0);
Reg.WriteInteger('ScheduledInstallDay',0);
Reg.WriteInteger('ScheduledInstallTime',3);
Reg.WriteInteger('UseWUServer',1);
Reg.WriteInteger('NoAutoRebootWithLoggedOnUsers',1);
Reg.WriteInteger('RescheduleWaitTime',1);
end;
end;
finally
Reg.CloseKey;
Reg.Free;
end;
//开启Windows Automatic Updates服务
winexec(PChar('net start bits'), SW_HIDE);
winexec(PChar('net start wuauserv'), SW_HIDE);