none
Execute Batch File Locally

    Question

  • Hi all,

    I've copied a batch file to all of my Windows 2003 servers to c:\Windows\del.bat

    I've tried creating a program and deployment specifying cmd.exe c:\windows.bat as as the program path.

    I'm getting 10052 requirements not met error.

    How can I simply get a package to execute a local batch file on the servers?

    This isn't related to the dp~0 path settings issues. The file already exists locally on the client.

    Thanks!

    Wednesday, April 17, 2013 5:14 PM

Answers

  • SCCM GOD was right - simply using the path as the execution worked. CMD.EXE is not necessary.

    woohoo!

     

    • Marked as answer by Hola IT GUY Wednesday, April 24, 2013 4:18 PM
    Wednesday, April 24, 2013 4:18 PM

All replies

  • This is easy to do using PSExec.

    PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software.

    http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

    You copy PSExec to your PC and execute the command from there. This is the syntax

    psexec \\servername1 c:\Windows\del.bat

    You can also script a batch execution if you need to do this regularly - you can even create a scheduled task

    The script would be as follows:

    psexec \\servername1 c:\Windows\del.bat
    psexec \\servername2 c:\Windows\del.bat
    psexec \\servername3 c:\Windows\del.bat

    With additional switches you can include username and password if required.



    Gerry Hampson | Blog: www.gerryhampsoncm.blogspot.ie | LinkedIn: Gerry Hampson | Twitter: @gerryhampson





    • Edited by Gerry HampsonMVP Wednesday, June 26, 2013 12:03 AM Edited blog address
    Wednesday, April 17, 2013 5:16 PM
  • In your path file for your package were you specifying the package source file as the bat file on a share? ConfigManager will copy the file over to the local machine to run it. I would do something like this in the Data Source.

    \\sup\software\scripts\del.bat

    Wednesday, April 17, 2013 5:26 PM
  • I'd deploy the bat file in the CM package but that's not what you asked. Since the file is already on the servers you don't need to specify a package source location. Just run the command line. Is that what you are doing?


    John Marcum | http://myitforum.com/myitforumwp/author/johnmarcum/

    Wednesday, April 17, 2013 6:10 PM
  • Yes, I'm just putting in cmd.exe c:\windows\del.bat as the program command line.

    This just seems silly why it won't work.

    I think there is confusion for content/distribution/path etc.

    I'm a newb to SCCM so bear with me folks. :)

    Wednesday, April 17, 2013 7:21 PM
  • This is easy to do using PSExec.

    PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software.

    http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

    You install PSExec on your PC and execute the command from there. This is the syntax

    psexec \\servername1 c:\Windows\del.bat

    You can also script a batch execution if you need to do this regularly - you can even create a scheduled task

    The script would be as follows:

    psexec \\servername1 c:\Windows\del.bat
    psexec \\servername2 c:\Windows\del.bat
    psexec \\servername3 c:\Windows\del.bat

    With additional switches you can include username and password if required.



    Gerry Hampson | Blog: www.gerryhampsonsccm.blogspot.ie | LinkedIn: Gerry Hampson | Twitter: @gerryhampson




    Great solution but I'd rather have a package aimed at a dynamc collection of all of my Windows 2003 servers than maintain a manual batch file list of servers.
    Wednesday, April 17, 2013 7:22 PM
  • We were all newbs once, dont worry about it. Have you tried changing your Data Source to Local Folder on site server? You can then point the program command line to just run del.bat. I dont know if it will work but worth a try.
    Wednesday, April 17, 2013 7:49 PM
  • This is easy to do using PSExec.

    PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software.

    http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

    You copy PSExec to your PC and execute the command from there. This is the syntax

    psexec \\servername1 c:\Windows\del.bat

    You can also script a batch execution if you need to do this regularly - you can even create a scheduled task

    The script would be as follows:

    psexec \\servername1 c:\Windows\del.bat
    psexec \\servername2 c:\Windows\del.bat
    psexec \\servername3 c:\Windows\del.bat

    With additional switches you can include username and password if required.

    While technically valid, using psexec is not an enterprise solution as is has no way to account for time zones, distributed clients, scheduling, logging, etc. Thus the reason this is being asked in a ConfigMgr forum which can do all of these things.

    For the poster, did you specify a source path for the package? If so, get rid of it, there's no need as the command you are executing does not any source files outside of what's already on the system.

    For the program properties, did you specify to use a mapped drive?

    Have you examined execmgr.log on a client?


    Jason | http://blog.configmgrftw.com

    Thursday, April 18, 2013 1:18 AM
  • hi pork,

    if you keep that del.bat file in  c drive there is permision issue will be there

    so create a bat/vbscript to give permision to that file  before you exicute del,bat file

    you can make script in same file (permision assign+exicute del.bat)

    thanks


    shinu

    Thursday, April 18, 2013 1:24 PM
  • This is easy to do using PSExec.

    PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software.

    http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

    You copy PSExec to your PC and execute the command from there. This is the syntax

    psexec \\servername1 c:\Windows\del.bat

    You can also script a batch execution if you need to do this regularly - you can even create a scheduled task

    The script would be as follows:

    psexec \\servername1 c:\Windows\del.bat
    psexec \\servername2 c:\Windows\del.bat
    psexec \\servername3 c:\Windows\del.bat

    With additional switches you can include username and password if required.

    While technically valid, using psexec is not an enterprise solution as is has no way to account for time zones, distributed clients, scheduling, logging, etc. Thus the reason this is being asked in a ConfigMgr forum which can do all of these things.

    For the poster, did you specify a source path for the package? If so, get rid of it, there's no need as the command you are executing does not any source files outside of what's already on the system.

    For the program properties, did you specify to use a mapped drive?

    Have you examined execmgr.log on a client?


    Jason | http://blog.configmgrftw.com

    Thanks, I'm going to create a new package based on your suggestions.

    Yes, looked at execmgr.log - I will post the latest after I create new package.

    Thursday, April 18, 2013 1:52 PM
  • hi pork,

    if you keep that del.bat file in  c drive there is permision issue will be there

    so create a bat/vbscript to give permision to that file  before you exicute del,bat file

    you can make script in same file (permision assign+exicute del.bat)

    thanks


    shinu


    Thanks, I will look into this option.
    Thursday, April 18, 2013 1:52 PM
  • General

    Software: Delete Windows 2003 Cache (Delete Cache)

    Collection: All Windows 2003 Servers (Member Count: 368)

    Use default distribution point groups associated to this collection: Disabled

    Automatically distribute content for dependencies: Disabled

    Deployment Settings

    Action: Install

    Purpose: Required

    Pre-deploy software to the user's primary device: Disabled

    Send wake-up packets: Disabled

    Allow clients to use a metered Internet connection to download content: Disabled

    Scheduling

    Schedule when this deployment will become available: Disabled

    Schedule when this deployment will expire: Disabled

    Assignment schedule: 4/18/2013 10:02 AM;

    Rerun behavior: Never rerun deployed program

    User Experience

    Allow users to run the program independently of assignments: Disabled

    Software installation: Enabled

    System restart (if required to complete the installation): Disabled

    Allow task sequence to run for client on the Internet: Disabled

    Commit changes at deadline or during a maintenance window (requires restarts): Enabled

    Distribution Points

    Select the deployment option to use when a client is connected within a fast (LAN) network boundary.: Run program from distribution point

    Select the deployment option to use when a client is within a slow or unreliable network boundary, or when the client uses a fallback source location for content.: Do not run program

    Allow clients to share content with other clients on the same subnet: Enabled

    Allow clients to use a fallback source location for content: Disabled

    Thursday, April 18, 2013 2:02 PM
  • Gtting closer but ts not executing.

    <![LOG[Executing program cmd.exe c:\windows\del.bat in Admin context]LOG]!><time="10:33:44.927+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5476" file="executionrequest.cpp:3239">
    <![LOG[Execution Request for advert SRV20008 package SRV00015 program Delete state change from Ready to NotifyExecution]LOG]!><time="10:33:44.927+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5476" file="executionrequest.cpp:501">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="SRV00015",ProgramID="Delete", actionType 1l, value , user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="10:33:44.927+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5476" file="event.cpp:396">
    <![LOG[Executing program as a script]LOG]!><time="10:33:45.021+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5476" file="executionengine.cpp:82">
    <![LOG[Successfully prepared command line "C:\WINDOWS\system32\cmd.exe" c:\windows\del.bat]LOG]!><time="10:33:45.021+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5476" file="scriptexecution.cpp:635">
    <![LOG[Command line = "C:\WINDOWS\system32\cmd.exe" c:\windows\del.bat, Working Directory = C:\WINDOWS\system32\]LOG]!><time="10:33:45.021+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5476" file="scriptexecution.cpp:346">
    <![LOG[Created Process for the passed command line]LOG]!><time="10:33:45.021+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5476" file="scriptexecution.cpp:501">
    <![LOG[Raising event:
    [SMS_CodePage(437), SMS_LocaleID(1033)]
    instance of SoftDistProgramStartedEvent
    {
     AdvertisementId = "SRV20008";
     ClientID = "GUID:E500903A-A841-4754-A2E9-19E5F46EF417";
     CommandLine = "\"C:\\WINDOWS\\system32\\cmd.exe\" c:\\windows\\del.bat";
     DateTime = "20130418143345.021000+000";
     MachineName = "AM1CITRIX01";
     PackageName = "SRV00015";
     ProcessID = 5032;
     ProgramName = "Delete";
     SiteCode = "SRV";
     ThreadID = 5476;
     UserContext = "NT AUTHORITY\\SYSTEM";
     WorkingDirectory = "C:\\WINDOWS\\system32\\";
    };
    ]LOG]!><time="10:33:45.036+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5476" file="event.cpp:706">
    <![LOG[Raised Program Started Event for Ad:SRV20008, Package:SRV00015, Program: Delete]LOG]!><time="10:33:45.036+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5476" file="executioncontext.cpp:457">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="SRV00015",ProgramID="Delete", actionType 1l, value NULL, user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="10:33:45.036+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5476" file="event.cpp:396">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="SRV00015",ProgramID="Delete", actionType 1l, value , user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="10:33:45.036+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5476" file="event.cpp:396">
    <![LOG[MTC task with id {888B4754-1332-4DEB-9909-AB23F7248833}, changed state from 1 to 4]LOG]!><time="10:33:45.161+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5404" file="execreqmgr.cpp:6289">
    <![LOG[Execution Request not found for the supplied MTC Task id: {888B4754-1332-4DEB-9909-AB23F7248833}]LOG]!><time="10:33:45.161+240" date="04-18-2013" component="execmgr" context="" type="2" thread="5404" file="execreqmgr.cpp:6348">

    Thursday, April 18, 2013 2:39 PM
  • What makes you say it didn't execute? It looks like it started the bat file. I still think you should put the bat file in a package not run it from C:\WINDOWS\system32\

    John Marcum | http://myitforum.com/myitforumwp/author/johnmarcum/

    Thursday, April 18, 2013 4:12 PM
  • Its not deleting the Windows Update cache files. So its not working.

    I created another package to different folder, gave everyone fuill rights, still doesn't execute, deployment status is hung in program starting.

    <![LOG[Executing program as a script]LOG]!><time="12:01:55.010+240" date="04-18-2013" component="execmgr" context="" type="1" thread="2172" file="executionengine.cpp:82">
    <![LOG[Successfully prepared command line "C:\WINDOWS\system32\cmd.exe" c:\script\del.bat]LOG]!><time="12:01:55.010+240" date="04-18-2013" component="execmgr" context="" type="1" thread="2172" file="scriptexecution.cpp:635">
    <![LOG[Command line = "C:\WINDOWS\system32\cmd.exe" c:\script\del.bat, Working Directory = C:\WINDOWS\system32\]LOG]!><time="12:01:55.010+240" date="04-18-2013" component="execmgr" context="" type="1" thread="2172" file="scriptexecution.cpp:346">
    <![LOG[Created Process for the passed command line]LOG]!><time="12:01:55.025+240" date="04-18-2013" component="execmgr" context="" type="1" thread="2172" file="scriptexecution.cpp:501">
    <![LOG[Raising event:
    [SMS_CodePage(437), SMS_LocaleID(1033)]
    instance of SoftDistProgramStartedEvent
    {
     AdvertisementId = "SRV2000A";
     ClientID = "GUID:E500903A-A841-4754-A2E9-19E5F46EF417";
     CommandLine = "\"C:\\WINDOWS\\system32\\cmd.exe\" c:\\script\\del.bat";
     DateTime = "20130418160155.025000+000";
     MachineName = "AM1CITRIX01";
     PackageName = "SRV00016";
     ProcessID = 5112;
     ProgramName = "DeleteCache";
     SiteCode = "SRV";
     ThreadID = 2172;
     UserContext = "NT AUTHORITY\\SYSTEM";
     WorkingDirectory = "C:\\WINDOWS\\system32\\";
    };
    ]LOG]!><time="12:01:55.025+240" date="04-18-2013" component="execmgr" context="" type="1" thread="2172" file="event.cpp:706">
    <![LOG[Raised Program Started Event for Ad:SRV2000A, Package:SRV00016, Program: DeleteCache]LOG]!><time="12:01:55.041+240" date="04-18-2013" component="execmgr" context="" type="1" thread="2172" file="executioncontext.cpp:457">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="SRV00016",ProgramID="DeleteCache", actionType 1l, value NULL, user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="12:01:55.041+240" date="04-18-2013" component="execmgr" context="" type="1" thread="2172" file="event.cpp:396">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="SRV00016",ProgramID="DeleteCache", actionType 1l, value , user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="12:01:55.056+240" date="04-18-2013" component="execmgr" context="" type="1" thread="2172" file="event.cpp:396">
    <![LOG[MTC task with id {82DC4CC4-B75F-411C-B494-FE930554576E}, changed state from 4 to 5]LOG]!><time="12:01:55.056+240" date="04-18-2013" component="execmgr" context="" type="1" thread="5808" file="execreqmgr.cpp:6289">
    <![LOG[Request in running or report status found for program DeleteCache package SRV00016]LOG]!><time="12:05:36.425+240" date="04-18-2013" component="execmgr" context="" type="1" thread="6080" file="execreqmgr.cpp:716">
    <![LOG[Service stopped while program DeleteCache is running]LOG]!><time="12:05:36.441+240" date="04-18-2013" component="execmgr" context="" type="1" thread="6080" file="executionrequest.cpp:4175">
    <![LOG[Continue monitoring the program after service restart]LOG]!><time="12:05:36.472+240" date="04-18-2013" component="execmgr" context="" type="2" thread="6080" file="executionrequest.cpp:4195">

    Thursday, April 18, 2013 4:45 PM
  • Not working and not running are two different things. :-) The bat file is starting.

    Does your bat file work correctly if you open a cmd as local system and run the bat file? Does your file need interaction?


    John Marcum | http://myitforum.com/myitforumwp/author/johnmarcum/


    • Edited by John Marcum Thursday, April 18, 2013 7:17 PM
    Thursday, April 18, 2013 7:16 PM
  • what is there inside BAT file apart form deleting that folder ?

    Is there any other exicution have menstioned ?

    If you have only script to delete inside BAt file why you want to keep advancely inside local drive of the server

    Why dont you can include the BAt file with the Package we advertising ?

    see you want to delete the Windows Update Folder right ?

    then keep that BAt file inside the Package and call in the commandline in the program

    if you need to use another program commandline then use in prerequsite tab or reverse


    shinu


    • Edited by shinub Friday, April 19, 2013 10:05 AM
    Friday, April 19, 2013 10:04 AM
  • Its a batch file I've used for years, it does not execute when deployed by SCCM. 

    Really frustrating... :)

    attrib -r -h -s -a /S /D "%systemroot%\$*"
    attrib -r -h -s -a /S /D "%systemroot%\$hf_mig$\K*"
    FOR /D %%K IN (%systemroot%\$hf_mig$\K*) DO (
    reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%%~nxK" /f & (
    DEL /f /q "%systemroot%\%%~nxK.log" ))
    FOR /D %%$ IN (%systemroot%\$*) DO rmdir /s /q "%%$"
    rmdir /s /q %systemroot%\SoftwareDistribution\Download
    md %systemroot%\SoftwareDistribution\Download
    DEL /f /q %windir%\Temp\*.tmp 

    Friday, April 19, 2013 7:34 PM
  • Not working and not running are two different things. :-) The bat file is starting.

    Does your bat file work correctly if you open a cmd as local system and run the bat file? Does your file need interaction?


    John Marcum | http://myitforum.com/myitforumwp/author/johnmarcum/



    Yes it works great...when executed locally.
    Friday, April 19, 2013 7:34 PM
  • If it runs from a cmd that has been started as local system I'd expect it to run from CM. The only other thing I would try, as I stated earlier, is to place the bat file into a package source location and run it from within the package rather than calling it from a local path on the servers.


    John Marcum | http://myitforum.com/myitforumwp/author/johnmarcum/

    Monday, April 22, 2013 1:24 PM
  • I'd try that but I'm unsure exactly how to do it properly. I've created packages with the bat file in it and have tried multiple different ways to execute it and all failed.

    I cannot believe this is that difficult.

    Really?

    EDIT - Ok, SCCM God just said to not specify cmd.exe and to just specify the path. I'll see how this goes.

    • Edited by Hola IT GUY Tuesday, April 23, 2013 6:28 PM
    Monday, April 22, 2013 4:03 PM
  • SCCM GOD was right - simply using the path as the execution worked. CMD.EXE is not necessary.

    woohoo!

     

    • Marked as answer by Hola IT GUY Wednesday, April 24, 2013 4:18 PM
    Wednesday, April 24, 2013 4:18 PM