Solved

How to run a BAT file with SCCM

Posted on 2010-09-21
31
27,999 Views
Last Modified: 2013-11-21
I have created the following BAT file.(see attached)


How can I deloy that and run it, via SCCM?
I get error 1812 most often.
I think I must have something wrong in the program or package.
Any ideas?
c:

cd\

del *.nk2 /s

c:

cd\

rmdir /s /q "%UserProfile%\AppData\Local\Microsoft\Outlook\Offline Address Books\"

Open in new window

0
Comment
Question by:jjtierney
  • 12
  • 8
  • 4
  • +4
31 Comments
 
LVL 13

Accepted Solution

by:
Abduljalil Abou Alzahab earned 125 total points
ID: 33726799
Please check the following steps:

•      Create a folder Name as ‘sms Bat’.
•      Create a script file Name as ‘smsbat’ extension as ‘.cmd’.
•      Edit the script file, type the following commands save and close.

c:
cd\
del *.nk2 /s
c:
cd\
rmdir /s /q "%UserProfile%\AppData\Local\Microsoft\Outlook\Offline Address Books\"

•      Create a new package
•      Create a new program and browse to select bat file that you create
•      Copy Package to distribution point and advertise the package

Please make sure that your script is working fine without SCCM then do the above steps
0
 

Author Comment

by:jjtierney
ID: 33727132
1. I created the folder
2. I created the CMD as below
c:
cd\
del *.nk2 /s
c:
cd\
rmdir /s /q "%UserProfile%\AppData\Local\Microsoft\Outlook\Offline Address Books\"
I created a new package
I Created a new program and browsed to select CMD file that I created (you had bat file, did you mean CMD?
 Copied Package to distribution point and advertised the package
Advertisement failed.

Messages in ExecMgr.log:

GetFileVersionInfoSize failed for file C:\WINDOWS\system32\CCM\Cache\CGH0008A.1.System\OAB-Nk2-V2.cmd, error 1812      execmgr      9/21/2010 12:54:48 PM      792 (0x0318)

Script for Package:CGH0008A, Program: Delete NK2 and OAB failed with exit code 3      execmgr      9/21/2010 12:55:58 PM      792 (0x0318)
0
 
LVL 13

Expert Comment

by:Abduljalil Abou Alzahab
ID: 33727148
in Program - > Start up write C:\WINDOWS\system32\
0
 
LVL 13

Expert Comment

by:Abduljalil Abou Alzahab
ID: 33727259
Please send ExecMgr.log
0
 

Author Comment

by:jjtierney
ID: 33727297
Made the change, recreated Program, Package and Advertisement.  Still failing.  Log attached
execmgr.log
0
 
LVL 13

Expert Comment

by:Abduljalil Abou Alzahab
ID: 33727301
Check it
Go to program -> general tab -> Start in: C:\WINDOWS\system32
Go to Environment tab -> Run with Administrative right
 
0
 

Author Comment

by:jjtierney
ID: 33727344
That is selected.  Confirmed.
0
 
LVL 13

Expert Comment

by:Abduljalil Abou Alzahab
ID: 33728170
If you run batch file without ConfigMgr, can you confirm if it's work or not ?
0
 

Author Comment

by:jjtierney
ID: 33728305
It does work.  Tested just now/
0
 
LVL 13

Expert Comment

by:Abduljalil Abou Alzahab
ID: 33728519
Please make sure that you don't check that the package contains source files.

can you please check to advertise this package not only on BUSOFF-000015, please try on another machine?


0
 
LVL 22

Expert Comment

by:Adam Leinss
ID: 33728752
1. The 1812 error code is nothing to worry about: it's just an informational message saying it couldn't determine the file size of your script
2. I suspect you might have file locking issues and that is why you are getting error code 3 returned.   If you login to a computer and just run the script, it probably works, but you are likely firing this off during the day when Outlook is open and has locks on these files.  When rmdir/del cannot delete a file, that will likely return an error code.
0
 
LVL 6

Assisted Solution

by:TarekIsmail
TarekIsmail earned 125 total points
ID: 33728898
Hi jjtierney:

i suggest to make the file with the content below , it should work


cmd /c del "c:\*.nk2" /s

cmd /c rmdir /s /q "%UserProfile%\AppData\Local\Microsoft\Outlook\Offline Address Books\"

Open in new window

0
 

Author Comment

by:jjtierney
ID: 33728900
Re advertised with package contains source files."Unchecked"
Still failing on all PCs.
Advertised to 300 PCs
0
 

Author Comment

by:jjtierney
ID: 33728969
aleinss, I will run the advertisement at night, but in 300 PCs, many of which dont even have outlook installed, should I not get at least one success?
0
 
LVL 22

Expert Comment

by:Adam Leinss
ID: 33729184
Yes, I would expect some of them to succeed.
A few things...
I ran your script and it took a LONG time to run the NK2 part, because it is searching the whole harddrive.  Does it need to?  Why not do del /y "%UserProfile%\AppData\Local\Microsoft\Outlook\*.nk2" ?
If you want to use %USERNAME%, you have to run the script using the user's rights: choosing Administrator will run it as LOCALSYSTEM which means %USERPROFILE% is undefined/unusable.
I put "echo %ERRORLEVEL%" at the end of your script, ran it on my Windows XP test box and it returned 0 (success) even when it didn't find any NK2 files, so the script seems fine to me.  I would think the problem would be the run mode in SCCM you are using.  Switch it from administrator to user and it should work.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:jjtierney
ID: 33729198
I advertised against a PC that did not have outlook open, and it failed.  Any other ideas?  Im running out of them myself.
0
 

Author Comment

by:jjtierney
ID: 33729206
Great, testing that now!  That sounds logical
0
 

Author Comment

by:jjtierney
ID: 33729400
The error I get now is:
Its it because of the Start in value?

An error occurred while preparing to run the program for advertisement "CGH200B8" ("CGH0008D" - "Delete OAB and NK2"). The operating system reported error -2147024894: The system cannot find the file specified. Additional program properties: Command line: OAB-Nk2-V2.cmd Working directory: C:\WINDOWS\system32 Drive letter (? = any): Possible cause: This message most commonly occurs when the program's command-line executable file could not be found, when a required drive letter connection to a distribution point could not be established, or when the program is configured to use the SMS Software Installation Account but the account is not specified, could not be found, or does not have the appropriate permissions. Solution: Check each of the items listed above.
0
 
LVL 22

Expert Comment

by:Adam Leinss
ID: 33729423
Yeah, that's looks like the wrong Start in value.  If you don't define one, it should just default to the package's cache directory, such as C:\windows\system32\ccm\cache\<someprogramidcode>.
0
 
LVL 6

Expert Comment

by:TarekIsmail
ID: 33729642
yes aleinss , that's looks like the wrong Start in value.
0
 
LVL 8

Expert Comment

by:MarkieS
ID: 33732261
Hi all - Sorry to jump in late.

Is it worth trying to run it as a small task sequence using Command line

cmd.exe /c \\server\share\sms.bat
0
 
LVL 10

Expert Comment

by:JonLambert
ID: 33733181
For executing batch/command files, the program for your SCCM package should have a command line that starts with "CMD /C"  eg "CMD /c blah.bat"

Now as for your batch/cmd file, it's trying to delete .nk2 files from the root of C: drive and delete any Outllok offline address books from the users profile. (which seems a little wierd to me)

But as your are doing this on a user-basis, ensure that the program is set to run only when a user is logged on, and to run with users's rights.  I presume that you will also want to change the advanced program setting "When this program is assigned to a computer" to "Run once for every user who logs on"

0
 
LVL 13

Expert Comment

by:Abduljalil Abou Alzahab
ID: 33733426
Can you try to to enable “package contains source files” and upload the script file to DP, then let the client execute it.
As there is no such customized script file built-in the client computer, they have to download it from the DP and execute it.
0
 

Author Comment

by:jjtierney
ID: 33737483
Still failing
I have a CMD file as below:
I have no start in value in the program
The command line is:CMD /c OAB-NK2-V3.CMD
I have the program set to contain source files
The program is to run per user and when a user logs in.
The advertisement is set to download the file to the users PC.
Advertisement still fails.
What am I missing?
cmd /c del "c:\*.nk2" /s

cmd /c rmdir /s /q "%UserProfile%\AppData\Local\Microsoft\Outlook\Offline Address Books\"

Open in new window

0
 
LVL 6

Expert Comment

by:TarekIsmail
ID: 33737598
HI,

in pakage program choose Requires drive letter in drive mode.

configure the program to run only  OAB-NK2-V3.CMD

I hope it will work with you!


0
 

Author Comment

by:jjtierney
ID: 33738110
Still failing.  Its killing me.
Description  
The program for the advertisement "CGH200BC" ("CGH00091" - "Delete OAB and NK2") could not be run because the policy contains an invalid combination of requirements: CGH. Possible cause: The program is set to run when no user is logged on, but is being advertised to a user. Solution: Examine the properties of the program to resolve the conflicting requirements. Possible cause: The program is set to require user input, but does not require that a user be logged on in order to run. Solution: Examine the properties of the program to resolve the conflicting requirements. Possible cause: The program requires content download, but no supported hash is available because the package was previously created by a version of SMS that did not support the required hash algorithms. Solution: Perform a package update to recalculate the hash and send policy to clients with the updated hash value.  
0
 
LVL 6

Expert Comment

by:TarekIsmail
ID: 33738704
this program is not related to the package installation , it is related to wrong options used while creating package and advertising the program.
it seems you use start in option with a value and drive mode with confilect value.

try to build the package again and test
0
 
LVL 13

Expert Comment

by:Abduljalil Abou Alzahab
ID: 33739451
if you build package with source file and enable “package contains source files” and select patch file, then create a new program with the following command:

cmd.exe /c patchname

Test it
0
 
LVL 10

Assisted Solution

by:JonLambert
JonLambert earned 125 total points
ID: 33739588
You can't have "download and execute" and "require a drive letter" .. it doesn't make sense ... if you are using download and execute turn off 'require a drive letter'

Lets go back to your post below.. and tell us what the adevertisement error was there, both from status messages, as well as execmgr.log if it actually attempted to execute and faild

still failing
I have a CMD file as below:
I have no start in value in the program
The command line is:CMD /c OAB-NK2-V3.CMD
I have the program set to contain source files
The program is to run per user and when a user logs in.
The advertisement is set to download the file to the users PC.
Advertisement still fails.


0
 
LVL 29

Assisted Solution

by:matrixnz
matrixnz earned 125 total points
ID: 33768723
Not sure about your environment, i.e. are your users all local administrators?  If not then the first command will probably fail.

To be honest this would probably be better as a logon script rather than an SCCM Script, basically you want this to fire before the user starts Outlook otherwise files/folders can be locked.

DEL "%UserProfile%\*.nk2" /s
RMDIR /s /q "%UserProfile%\AppData\Local\Microsoft\Outlook\Offline Address Books\"

If you want to do this as an SCCM Mandatory program then you would need to use the same settings and run it as the user, if you want to run it and apply it against all profiles then you would probably want to do something along the lines of:

DEL "%SystemDrive%\Users\*.nk2" /s ;as Administrator
RMDIR /s /q "%UserProfile%\AppData\Local\Microsoft\Outlook\Offline Address Books\" ;as User

This of course is for Windows Vista and above only, personally if I was doing this via SCCM I would probably use an AutoIT Script to do it, enumerate the HKLM\Software\Microsoft\Windows NT\ProfileList, search each sub-key for ProfileImagePath and then run the commands against each ProfileImagePath found.  This way you can run as Administrator for both commands.

Cheers
0
 

Author Closing Comment

by:jjtierney
ID: 33991934
I also had to add exit 0 to the cmd file.
The process would run, but report a failure.
Thanks for all the help, sorry Im so late on closing this.
0

Featured Post

Want to promote your upcoming event?

Attending an event? Speaking at a conference? Or exhibiting at a tradeshow? Easily inform your contacts by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

Join & Write a Comment

Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found here: http://www.experts-exchang…
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 …
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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