vbscript - .vbs script to change Connection Specific DNS suffix -


i'm looking way have .vbs file add connection specific dns suffix ethernet adaptor known name of lan

the code forms past of small shell script that:

  1. changes primary dns suffix
  2. flushes dns
  3. checks ip details make sure had held
  4. changes startup type or service
  5. starts said service
  6. pings know server ensure network connectivity

cant seem find code thats viable make first step work. have :

 '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 * win32_service name = 'enterceptagent'")  each objservice in colservicelist     if objservice.state = "stopped"         objservice.startservice()         wscript.sleep 5000         wscript.echo "mcafee started"     else         wscript.echo "mcafee running"         wscript.sleep 5000     end if     errreturncode = objservice.changestartmode("automatic")    next  'network test  set shell = createobject("wscript.shell")  shell.run("ping pmo2 -t") 

cheers

try (configures correct guid, see objnetcard.settingid property):

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 * win32_networkadapterconfiguration ipenabled = true")   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 

see setdnsdomain method return codes


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -