Returning an Error to SCCM from a CMD File

I use SCCM to deploy a very simple CMD file to copy one file over the top of a file, of the same name, in a folder on the Public user's Desktop. This method (I thought) has been working flawlessly for me, but for this deployment, I have had reports that even though SCCM returned a successful completion, the file copy did not work, as evidenced by the date on the file in the folder.

The Package is deployed with a program Command line of "cmd /c <cmdfile.cmd>", Run Hidden, No action required after running, Whether or not a user is logged on, Suppress program notifications and nothing else unusual. The text of the CMD file is  "copy /y <filename.xxx" "%public%\desktop\<Folder Name>\"

First, I would ask is there a better way to deploy a file copy?  I'm not a good vb-scripter, so I've used CMD and batch files by default. But I am not opposed to using VB scripts. Second, Is there some simple code to place in a CMD file to return a success or failure code to SCCM. 

Any advice you can give would be appreciated. Thank you.

April 29th, 2013 9:18pm

An alternative approach would be ditching the .cmd file and using the native xcopy command e.g.
xcopy /y "<filename>.xxx" "%public%\desktop\<Folder Name>\"

Xcopy should return a standard windows error code. The copy command would probably fail if the target folder (<Folder Name>) did not exist whereas xcopy should create a folder if it does not exist already.

  • Marked as answer by DebS301 Tuesday, April 30, 2013 2:47 PM
Free Windows Admin Tool Kit Click here and download it now
April 30th, 2013 12:39pm

An alternative approach would be ditching the .cmd file and using the native xcopy command e.g.
xcopy /y "<filename>.xxx" "%public%\desktop\<Folder Name>\"

Xcopy should return a standard windows error code. The copy command would probably fail if the target folder (<Folder Name>) did not exist whereas xcopy should create a folder if it does not exist already.

  • Marked as answer by DebS301 Tuesday, April 30, 2013 2:47 PM
April 30th, 2013 12:39pm

Thank you, I'll run some tests to try to make it fail.  Thanks.
Free Windows Admin Tool Kit Click here and download it now
April 30th, 2013 5:46pm

exit 0 ---- returns 0 which is successful.

I assume SCCM can receive other error types from batch files.... I was just thinking about researching this and came across this page.

October 3rd, 2013 5:18pm

Info from: exit /?

EXIT [/B] [exitCode]

  /B          specifies to exit the current batch script instead of
              CMD.EXE.  If executed from outside a batch script, it
              will quit CMD.EXE

  exitCode    specifies a numeric number.  if /B is specified, sets
              ERRORLEVEL that number.  If quitting CMD.EXE, sets the process
              exit code with that number.

you can also catch errors from commands within a batch file... using ERRORLEVEL...

Free Windows Admin Tool Kit Click here and download it now
October 3rd, 2013 5:19pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics