Solved

VBScript Ping/ FlushDNS Script, Windows 7 x86/x64

Posted on 2011-02-17
6
2,939 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

BIND is the most widely used Name Server. A Name Server is the one that translates a site name to it's IP address. There is a new bug in BIND (https://kb.isc.org/article/AA-01272), affecting all versions of BIND 9 from BIND 9.1.0 (inclusive) thro…
If your business is like most, chances are you still need to maintain a fax infrastructure for your staff. It’s hard to believe that a communication technology that was thriving in the mid-80s could still be an essential part of your team’s modern I…
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…
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now