Jump to content


karoljay

Application run by batch file - failed status

Recommended Posts

I created an application in SCCM, which is initiated by a batch script - it launches MRT security scan - The computer on which I run the application is scanned successfully, the MRT also creates a success log but in the end in Software Center the application is visible as failed.

The application is in "installing" state untill the scan is finished, when the actions are finished it fails - it does not time out as the timeout is set to arround 500 minutes.

What I thought of is adding "exit /b 0" to give SCCM the "error 0" exit code - unfortunately no success.

 

The batch file has in it:

 

%SYSTEMROOT%\System32\mrt.exe /F:Y /Q
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I
set datetime=%datetime:~0,4%-%datetime:~4,2%-%datetime:~6,2%_%datetime:~8,2%-%datetime:~10,2%-%datetime:~12,2%
echo f | xcopy /f /y "%SYSTEMROOT%\Debug\"mrt.log "\\servername\log_folder\"%datetime%-%computername%scan.log
exit /b 0
Now when I look at the script - maybe I should put the MRT script in one batch and create a 2nd batch which would call the MRT scan script and on the end of this batch I should have the exit /b 0 ? What do you think?

Share this post


Link to post
Share on other sites


You problem will likely be your xcopy.

 

Remember that CM12 runs a local system account, which likely doesn't have access to the network share.

Share this post


Link to post
Share on other sites

Actually I made the share available for all users and the script does everything it needs to do including the copy process, it only shows failed status in Software Center - which is confusing for end users and new service desk staff.

Share this post


Link to post
Share on other sites

2 things. Is this a "application" deployment or a "package" deployment. If applcation, then the result is based on the outcome of the "detection method" and not a exit code. You could put exit 0 a thousand times but software center will still report an error.

 

If you are deploying as a "package" then exit 0 should work fine. Garth is right in saying sccm uses the local system account. The solution for this is very easy. Add a "net use" command to your script just before you access the share. No drive letter required!

 

Your script should look like:

%SYSTEMROOT%\System32\mrt.exe /F:Y /Q

for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I

set datetime=%datetime:~0,4%-%datetime:~4,2%-%datetime:~6,2%_%datetime:~8,2%-%datetime:~10,2%-%datetime:~12,2%

echo f | xcopy /f /y "%SYSTEMROOT%\Debug\"mrt.log

Net use "\\servername\log_folder"

"\\servername\log_folder\"%datetime%-%computername%scan.log

exit /b 0

 

Net use is required to create a temporary mapping to your share. Without it, sccm will nlt be able to access your share UNLESS you run the script using user credentials

Share this post


Link to post
Share on other sites

Thank you both for your help!

I needed to apply a quick fix to get this working and I created a package with the "exit /b 0" at the end.

 

YPCC, yes this was an application - to be honest I don't have that much experience yet with creating applications from scripts and not from msi, so definitely I made a mistake, most probably with the detection method.

I just put there some random file name as my understanding is that if sccm doesn't find the file the application can run - right?

OK - when I wrote the above sentence I just realized, where the problem is :) , after the installation the random file just isn't there and this is why Software Center shows as failed - please correct me if I'm wrong.

 

BTW - there was no net use command previously and the logs were saved on the file share --> "\\servername\log_folder\"

 

Happy New Year!

Share this post


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.

Loading...

×
×
  • Create New...