Solved

VBScript Ping/ FlushDNS Script, Windows 7 x86/x64

Posted on 2011-02-17
6
2,977 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

Question has a verified solution.

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

Suggested Solutions

Let’s list some of the technologies that enable smooth teleworking. 
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now