• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3293
  • Last Modified:

VBScript Ping/ FlushDNS Script, Windows 7 x86/x64

Can someone educate me on making a vb script to accomplish the following on Windows 7 x86/x64?
1. Run a command prompt in administrator mode.
2. Run ipconfig /registerdns
3. Run ipconfig /flushdns
4. Ping server.company.com (Comapny Server)
5. Wait 5 seconds to see the result
6. Close the command prompt.

0
checkonetwo
Asked:
checkonetwo
  • 4
3 Solutions
 
answer_dudeCommented:
This is how I would do it.  Put this code in a file with a .vbs extension then run it.


Sub PingFlush()

    Dim objShell
    Dim sShellCmd
    
    'Set variable
    Set objShell = CreateObject("Wscript.Shell")
    
    'Delete and rename files
    sShellCmd = "%comspec% /c "
    sShellCmd = sShellCmd & "echo on & "
    sShellCmd = sShellCmd & "ipconfig /registerdns & "
    sShellCmd = sShellCmd & "ipconfig /flushdns & "
    'sShellCmd = sShellCmd & "ipconfig & "
    sShellCmd = sShellCmd & "Ping server.company.com & "
    sShellCmd = sShellCmd & "sleep 5"
    objShell.Run sShellCmd

    Set objShell = Nothing

End Sub

Call PingFlush

Open in new window

0
 
answer_dudeCommented:
sorry about the "delete and rename files" comment -- that's a result of a copy/paste error... there is no file deletion going on here... :-(
0
 
checkonetwoAuthor Commented:
It runs in a continous loop down the screen and states, The request operation requires elevation in the command window.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
sam0x01Commented:
Ipconfig /flushdns and ipconfig /registerdns require local adminstrator privileges.
Either
Account does is not a member of the local administrators group or
You ran the .vbs with cscript under Vista or Windows 7 with a CMD prompt that was not an Administrator CMD window.

0
 
answer_dudeCommented:
Try commenting out the two lines:

    'sShellCmd = sShellCmd & "ipconfig /registerdns & "
    'sShellCmd = sShellCmd & "ipconfig /flushdns & "

and uncomment out the line:

    sShellCmd = sShellCmd & "ipconfig & "

then re run it -- that will ensure that the script is behaving as expected (you should see your IP address and the ping results).  If so, then it's a permission/run as admin issue which I can help you with, too.

-Paul
0
 
answer_dudeCommented:
If this is a permissions issue, then you have a couple of ways to solve it:

1)  Use a scheduled task.  Setup the above as a .VBS file (e.g., pingflush.vbs) then use the MS Scheduled Task feature to run the vbs and set the "Run as" option (see image).  This has the value of encrypting the password as part of the task.

Scheduled Task Example
2)  Create a special directory (e.g., c:\testdir\vbscript) and put the two VBS files attached (PingFlush.vbs and ElevatePingFlush.vbs) in that directory then run the ElevatePingFlush.vbs.  You will be prompted to enter admin information.

3)  If you want to do it completely from VBS, without any popups, etc., and without using a scheduled task, then the only other way I know is to actually embed your admin password in the VBS file using the 'runas' command.  I don't recommend that since it leaves your password in the clear.
PingFlush.vbs
ElevatePingFlush.vbs
0

Featured Post

What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now