Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBScript Ping/ FlushDNS Script, Windows 7 x86/x64

Posted on 2011-02-17
6
Medium Priority
?
3,254 Views
Last Modified: 2012-05-11
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
Comment
Question by:checkonetwo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 10

Accepted Solution

by:
answer_dude earned 1600 total points
ID: 34922091
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
 
LVL 10

Expert Comment

by:answer_dude
ID: 34922101
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
 

Author Comment

by:checkonetwo
ID: 34922401
It runs in a continous loop down the screen and states, The request operation requires elevation in the command window.
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 3

Expert Comment

by:sam0x01
ID: 34922891
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
 
LVL 10

Assisted Solution

by:answer_dude
answer_dude earned 1600 total points
ID: 34927473
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
 
LVL 10

Assisted Solution

by:answer_dude
answer_dude earned 1600 total points
ID: 34928024
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

Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had an issue with InstallShield not being able to use Computer Browser service on Windows Server 2012. Here is the solution I found.
During and after that shift to cloud, one area that still poses a struggle for many organizations is what to do with their department file shares.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question