Solved

need to make batch error output go away

Posted on 2013-06-28
13
405 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 83

Expert Comment

by:oBdA
ID: 39285147
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
ID: 39285182
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
ID: 39285301
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
How our DevOps Team Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 53

Expert Comment

by:Bill Prew
ID: 39285722
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
ID: 39285729
Thanks Bill.  <hanging head in shame>   :)
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39285790
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
 

Author Comment

by:icecom4
ID: 39298224
@ 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 83

Expert Comment

by:oBdA
ID: 39298324
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
ID: 39298360
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
ID: 39300500
@ Obda,

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

Accepted Solution

by:
oBdA earned 500 total points
ID: 39300580
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
ID: 39337663
thank you very much!
0
 
LVL 43

Expert Comment

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

Steve
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

825 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