Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 32550
  • Last Modified:

How to run a BAT file with SCCM

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
jjtierney
Asked:
jjtierney
  • 12
  • 8
  • 4
  • +4
4 Solutions
 
Abduljalil Abou AlzahabInfrastructure Team Leader – Professional ServicesCommented:
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
 
jjtierneyAuthor Commented:
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
 
Abduljalil Abou AlzahabInfrastructure Team Leader – Professional ServicesCommented:
in Program - > Start up write C:\WINDOWS\system32\
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Abduljalil Abou AlzahabInfrastructure Team Leader – Professional ServicesCommented:
Please send ExecMgr.log
0
 
jjtierneyAuthor Commented:
Made the change, recreated Program, Package and Advertisement.  Still failing.  Log attached
execmgr.log
0
 
Abduljalil Abou AlzahabInfrastructure Team Leader – Professional ServicesCommented:
Check it
Go to program -> general tab -> Start in: C:\WINDOWS\system32
Go to Environment tab -> Run with Administrative right
 
0
 
jjtierneyAuthor Commented:
That is selected.  Confirmed.
0
 
Abduljalil Abou AlzahabInfrastructure Team Leader – Professional ServicesCommented:
If you run batch file without ConfigMgr, can you confirm if it's work or not ?
0
 
jjtierneyAuthor Commented:
It does work.  Tested just now/
0
 
Abduljalil Abou AlzahabInfrastructure Team Leader – Professional ServicesCommented:
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
 
Adam LeinssCommented:
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
 
TarekIsmailCommented:
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
 
jjtierneyAuthor Commented:
Re advertised with package contains source files."Unchecked"
Still failing on all PCs.
Advertised to 300 PCs
0
 
jjtierneyAuthor Commented:
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
 
Adam LeinssCommented:
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
 
jjtierneyAuthor Commented:
I advertised against a PC that did not have outlook open, and it failed.  Any other ideas?  Im running out of them myself.
0
 
jjtierneyAuthor Commented:
Great, testing that now!  That sounds logical
0
 
jjtierneyAuthor Commented:
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
 
Adam LeinssCommented:
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
 
TarekIsmailCommented:
yes aleinss , that's looks like the wrong Start in value.
0
 
MarkieSCommented:
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
 
JonLambertCommented:
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
 
Abduljalil Abou AlzahabInfrastructure Team Leader – Professional ServicesCommented:
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
 
jjtierneyAuthor Commented:
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
 
TarekIsmailCommented:
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
 
jjtierneyAuthor Commented:
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
 
TarekIsmailCommented:
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
 
Abduljalil Abou AlzahabInfrastructure Team Leader – Professional ServicesCommented:
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
 
JonLambertCommented:
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
 
matrixnzCommented:
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
 
jjtierneyAuthor Commented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 12
  • 8
  • 4
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now