Jump to content

BATCH - Ping script erroring when not run as admin


Recommended Posts

Hi all,

I'm having a very odd issue with a batch file, simply designed to ping a machine and report it up or down.

The script is as follows;

ping -n 1 192.168.0.1 | find "TTL=" >nul
if errorlevel 1 (
echo Host down.
) else (
echo Host up.
)

 

The weirdness comes from the fact that, if I run the above as Admin, it works fine. However, if I just double click the batch file as a standard user, it returns;

^C^C^C^C^C^C^C^C^C^C^C^Cthe process tried to write to a nonexistent pipe^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C
^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C
^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C

etc...

The CTRL+C (^C) prompts come up over and over for a while, until CMD crashes out. I'm not pressing CTRL+C.

I have no idea what's going on!

Edited by haze1434
amended coding syntax
Link to post
Share on other sites

I just tried your BAT file on a freshly installed Win7, and it runs just fine as a normal user. I think something is gummed up in your system, try running just 'ping -n 1 192.168.0.1 | find "TTL=" ' without the null redirect at the end, and not in a BAT file, see what happens

Link to post
Share on other sites
13 hours ago, kdodge said:

I just tried your BAT file on a freshly installed Win7, and it runs just fine as a normal user. I think something is gummed up in your system, try running just 'ping -n 1 192.168.0.1 | find "TTL=" ' without the null redirect at the end, and not in a BAT file, see what happens

I get no return, but then that's expected. It doesn't crash CMD though. None of the odd behaviour above.

What's confusing me is that it runs as Admin, same file from the same location, but not as my standard user account. Weird. It's on my standard user account's Desktop as well, so it should have no issues running it.

Link to post
Share on other sites

i know in linux, ping requires special permissions to run over the iface, so maybe its a permission issue in windows? I think the windows tool is "icacls", but I'm not too sure about that. Also how did you create the BAT file? Did you make it on a different system and move it to the windows machine? If so, try opening plain old notepad and typing it out (no cut/pasting, e.g. no CRLF/LF problems) and don't try running it from a USB drive.

Link to post
Share on other sites

What version of windows are you running?

Link to post
Share on other sites
On 12/29/2016 at 4:28 AM, haze1434 said:

7

Create a shortcut to the bat script. Right click the shourtcut, and then click advanced, and check "Run as administrator" and try again. Let me know what happens. 

 

http://imgur.com/a/VhYNX

Edited by digip
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...