ConfigMgr 101: Using DOS commands and RunFromDP

I recently responded to a cry for help in troubleshooting an issue with a simple program that just did not want to do what it should.  It is a common scenario for the ConfigMgr guy to be asked to deploy shortcuts or files to systems and the easiest way to do this is usually with our old friend XCOPY.

Utilising programs such as XCOPY work fine when the client is caching the content locally and running from there, however when the advertisement is set to “Run from Distribution Point” then nothing seems to happen even though a success code is often returned.  What gives?

Well, XCOPY, like most MS-DOS born command utilities, relies on an instance of the windows command processor and this itself does not support UNC paths as the ‘working directory’.  This is not a ConfigMgr issue as such – it is a limitation of the command processor and you can easily replicate the problem by creating a simple .bat or .cmd file on a network share containing just a ‘pause’ command and try running it directly from the network share…

The result is that the working directory for the program launched by ConfigMgr is being set to the “c:\windows\system32” folder instead of the SMSDP location – and in the case of an XCOPY command line like ours it is likely that the files to be copied will not be found.  “File not Found” with XCOPY generates an exitcode of 0 (zero) which as far as ConfigMgr is concerned is a success.  Even worse, is that if your command line is to XCOPY everything using wildcards (*.*) then you could end up trying to duplicate everything in the windows\system32 folder!

So how do we workaround this?  Well you could of course move into this decade and write a VBScript that performs your file copies etc. and there are numerous examples and guides available on the net and so I won’t be writing one here.

You could also make use of the little known “%~dp0” variable, which stores the SMSDP location being used – however this cannot be used directly on your ConfigMgr program command line and you will need to instead use it within a .bat or .cmd file and call that instead.

@echo off

xcopy %~dp0*.* %public%\desktop

Note that the %~dp0 variable will contain a trailing “\” so do not add one yourself.

A third solution, is to enable the “Requires Drive Letter” option in the “Environment” tab of your program.

This will cause ConfigMgr to temporarily map a spare drive letter to the SMSDP, setting it as the working directory and running your program command line.

I hope this information serves you well one day!

Andy