Solved

VBScript Ping/ FlushDNS Script, Windows 7 x86/x64

Posted on 2011-02-17
6
3,055 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 400 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 400 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 400 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

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

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

Resolve DNS query failed errors for Exchange
When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

726 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