我正在寻找一种方法让.vbs文件为已知名称为LAN的以太网适配器添加特定于连接的DNS后缀
代码形成了一个小的shell脚本:
似乎找不到任何能够使第一步工作的代码。目前我有:
'add dns
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Policies\Microsoft\Windows NT\DNSClient"
oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
strValueName = "AppendToMultiLabelName"
'Enabled
strValue = "mysuffix.com"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
'flush dns
set shell = createobject("wscript.shell")
shell.run("ipconfig /flushdns")
Wscript.echo "DNS Flushed."
'check DNS
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("ipconfig /all")
strIpConfig = objScriptExec.StdOut.ReadAll
WScript.Echo strIpConfig
'start McAfee
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name = 'enterceptAgent'")
For Each objService in colServiceList
If objService.State = "Stopped" Then
objService.StartService()
Wscript.Sleep 5000
Wscript.Echo "McAfee Started"
Else
Wscript.Echo "McAfee already running"
Wscript.Sleep 5000
End If
errReturnCode = objService.ChangeStartMode("automatic")
Next
'network test
set shell = createobject("wscript.shell")
shell.run("ping pmo2 -t")
干杯
答案 0 :(得分:0)
尝试此操作(配置为正确的GUID,请参阅objNetCard.SettingID
属性):
option explicit
'On Error Resume Next
On Error GoTo 0
Dim strResult: strResult = Wscript.ScriptName
Dim strComputer, objWMIService, colNetCards, objNetCard
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
strResult = strResult _
& vbNewLine & objNetCard.Caption & vbTab & "'" & objNetCard.DNSDomain & "'" & vbTab & CBool( IsEmpty( objNetCard.DNSDomain)) & vbTab & CBool( IsNull( objNetCard.DNSDomain))
strResult = strResult _
& vbNewLine & objNetCard.SetDNSDomain("mysuffix.com")
'' strResult = strResult & vbNewLine & objNetCard.SetDNSSuffixSearchOrder("mysuffix.com")
Next
'strResult = strResult & vbNewLine
Wscript.Echo strResult