Solved

need to make batch error output go away

Posted on 2013-06-28
13
402 Views
Last Modified: 2013-07-18
Hello script experts,

I get the below message in one of my batches
"CMD.exe was started with the above path as the current directory"
"UNC paths are not supported.  Defaulting to windows directory".  

What I am doing is starting a batch, over the network, from an Intranet iframe page I made.  Anyway, the batch executes fine, does not have any problems,...I would just like that error to go away because I dont want people staring at it.

I converted it to exe, because some some computers open batch files as notepad instead of executing.  Not sure if that has anything to do with it, but when I use just the batch instead of the exe I dont notice this error, but it moves much faster and that is probably why.  

Is there anyway to add something in the batch that will prevent this error message output, or possibly any/all error message output?
0
Comment
Question by:icecom4
  • 4
  • 3
  • 3
  • +2
13 Comments
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
If your script works correctly, you can just ignore this message. To "sort of" get rid of it, you can just put "cls" as first command in your script, which will clear the screen.
With a registry tweak (per user, though), you can disable the check as well:
Cmd.exe does not support UNC names as the current directory
http://support.microsoft.com/kb/156276
0
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
If you don't want to see ANY error messages you can redirect stderr to null

batch 2>null
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
You could also set the working directory of the batch file to a local drive, i.e. make the shortcut point at \\server\share\path\file.cmd and the working directory of %windir% say or run it from a mapped drive.

The error is as has been said because you can't set the current directory to \\x\y for a cmd window.

Steve
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
If you want to suppress ALL error output from the batch (now exe) when you run it you can do:

myfile.exe 2>nul

(notice this is NUL not NULL as mentioned earlier)

What does the BAT file actually do or look like?  And how do you initiate it from the intranet site? Maybe there is a way to run it hidden?

~bp
0
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
Thanks Bill.  <hanging head in shame>   :)
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
If .bat files arent associated correctly on some machines try renaming it as .cmd file instead too ... or fix the file association I suppose!
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:icecom4
Comment Utility
@ Bill
you said do "myfile.exe 2>nul"
So you mean call the exe from another batch file?  

The batch just looks to see if the user is on a workstation, if so it starts mstsc, if they are on a terminal server already it starts the application.  I can always make the exe run invisible, but I can't because it provides various messages to the end user.  

CLS in the beginning does not work, It seems that the error I mentioned above displays BEFORE anything in my batch executes.  I guess the CMD.EXE service sees that I am trying to execute a file over the network and displays that error.  

I may need to do as you suggested, call the exe from another batch, or just live with the error message.

maybe there is a setting I can deploy to the desktops using active directory?
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
You can
Ignore the error
Port the batch file to another scripting language (VBScript, Powershell, AutoIt, Kix, ...)
Add the following line to your script; the error will show up once more for each user and then be suppressed (see the article I linked above): reg.exe add "HKCU\Software\Microsoft\Command Processor" /v DisableUNCCheck /t REG_DWORD /d "1" /f >NUL
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
or just change the working directory to a mapped or local drive like I said if it is a shortcut, or run it from a mapped drive rather than a UNC path.

Steve
0
 

Author Comment

by:icecom4
Comment Utility
@ Obda,

Not a bad idea, will disabling UNC check impact anything else I wonder?
0
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
Shouldn't impact anything else as long as you're aware of the possible issues with UNC locations.
What you should do as one of the first commands in your batch if you disable the check (sorry, should have mentioned that earlier) is a "cd /d C:\Windows" (or any other known local path like %UserProfile%) so that you have a non-UNC current path; when you disable the check, cmd.exe doesn't change the path automatically anymore by itself.
0
 

Author Closing Comment

by:icecom4
Comment Utility
thank you very much!
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
Well personally I'd use "cls" or better http:#a39298360 but as long as you are happy...

Steve
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

10 Experts available now in Live!

Get 1:1 Help Now