Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change DNS Setting programically
#1
When I am fixing one of my customers computers, one thing I always do is change their DNS settings to a better (more secure) DNS server. Usually Comodo, Google or Symantec DNS because they offer protection from bad sites. Is there a way to change these settings without having delve into the control panel and change them? I want to try and speed up (and automate) many of my routine tasks while fixing a computer and it would be great if I could automate the DNS settings change.

For example, change the current DNS to "156.154.70.22 and 156.154.71.22" (Comodo)

Thanks,
Jason
#2
QM does not have a function for this, but it is possible, I found something in google.
#3
I will search Google, thank you Gin.
#4
This is vbscript below works

Code:
Copy      Help
On Error Resume Next

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
    arrDNSServers = Array("156.154.70.22", "156.154.71.22")
    objNetCard.SetDNSServerSearchOrder(arrDNSServers)
Next

But if I was to convert it to QM, any ideas how its done.

Currently I do this below but didnt work. :?:

Code:
Copy      Help
lpstr code=
  On Error Resume Next

  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
      arrDNSServers = Array("156.154.70.22", "156.154.71.22")
      objNetCard.SetDNSServerSearchOrder(arrDNSServers)
  Next
VbsExec code

But this simple msgbox below works. :?:

Code:
Copy      Help
lpstr code=
  MsgBox "hi its me."
VbsExec code
#5
Maybe some lines in the VBScript code are empty. Then the multiline string ends. Must be space.

Macro Macro650
Code:
Copy      Help
lpstr code=
;On Error Resume Next
;
;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
;;;;;arrDNSServers = Array("156.154.70.22", "156.154.71.22")
;;;;;objNetCard.SetDNSServerSearchOrder(arrDNSServers)
;Next
VbsExec code
#6
Thanks alot, it work perfectly now, maybe you right, I left some spaces in between.

One more question, how do I go about converting this vbscript below correctly to QM vbscript format?
Code:
Copy      Help
Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")

' open maximized and wait
WSHShell.Run "notepad.exe", 3, true
' open minimized and wait
WSHShell.Run "notepad.exe", 2, true
' open normal and don't wait
WSHShell.Run "notepad.exe", 1, false

Set WSHShell = Nothing
WScript.Quit(0)

I know its mention wscript cant be use in QM, for Wscript.Echo, I can replace with MsgBox but what about Wscript.Shell like the above code? :?:
#7
Delete WScript. and will work.

Set WSHShell = CreateObject("WScript.Shell")
#8
Thanks it work, heres the working code. BTW Wscript.Quit(0) have to be remove too.Big Grin

Macro VbscriptNotepad
Code:
Copy      Help
lpstr code=
;Dim WSHShell
;Set WSHShell = CreateObject("WScript.Shell")
;
;;
;WSHShell.Run "notepad.exe", 3, true
;
;WSHShell.Run "notepad.exe", 2, true
;
;WSHShell.Run "notepad.exe", 1, false
;
;Set WSHShell = Nothing

VbsExec code


Forum Jump:


Users browsing this thread: 1 Guest(s)