2

I am trying to deploy an application through a .bat via SCCM. The .bat executes perfectly when I run it on my local workstation via CMD. When I deploy it and try to install it via Software Center, it says it can't find the .exe. How do I specify it should look in the same directory location as the .bat file?

Here's what I've written up:

@echo off

REM Install VooV
start VooVMeeting.exe /S

REM Create Shortcut
set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"

echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "C:\Users\%USERNAME%\Desktop\VooV Meeting.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "C:\Program Files (x86)\Tencent\VooVMeeting\voovmeetingapp_new.exe" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%

cscript /nologo %SCRIPT%
del %SCRIPT%

REM Sleep Script
timeout /t 30 /nobreak>NUL

REM Send Exit Code
EXIT /B 0

I feel like this is a simple fix but I am too stupid to figure it out. Thanks for any pointers.

  • Well you haven't told the command parser where the executable file is! You have not defined a working directory within the script, and as you've not use an absolute file path. When you run it via SCCM it is beginning from a different working directory than when you run it directly in cmd.exe. There is never an excuse to not use full paths and filenames with extensions in a script, that type of shorthand is only ever intended for quick interactive typing in the console. Change `VooVMeeting.exe` to `"F:\ull\PathTo\VooVMeeting.exe"`, and change `cscript` to `%SystemRoot%\System32\cscript.exe`. – Compo Jun 28 '22 at 11:57
  • As a side note, if you, _(I would recommend that you do)_, double quote `"F:\ull\PathTo\VooVMeeting.exe"`, please remember to change `start "F:\ull\PathTo\VooVMeeting.exe" /S` to `Start "" "F:\ull\PathTo\VooVMeeting.exe" /S`. If you want to specify the location as the same one in which the running batch script resides, it is even simpler, so what you'll need is `Start "" "%~dp0VooVMeeting.exe" /S`. The `%0` is a special variable for the current script, `~` expands it and `d` designates its drive, whilst `p` designates its \path\ – Compo Jun 28 '22 at 12:18
  • I'm also wondering why you cannot just use one VBScript file. The VBScript could run the executable file and create the shortcut without any need whatsover for a batch file, and using a temporary file etc. Can SCCM not run a .vbs file directly? – Compo Jun 28 '22 at 12:38

1 Answers1

0

When using .bat or .cmd files from SCCM/MECM, which I almost never do now with a custom template for Powershell App Deployment Toolkit, pushd "%~dp0" is a winner.

Start the .bat with

@echo off
pushd %~dp0

As previously said in comments, add "" or "your window title" to start command, and add /wait to fix any detection error after installation

start "VooV installation" /wait VooVMeeting.exe /S

With SCCM/MECM installations, I would also send the shortcut to "%ALLUSERSPROFILE%\Desktop\VooV Meeting.lnk" or better objShell.SpecialFolders("AllUsersDesktop") or Startmenu objShell.SpecialFolders("AllUsersPrograms"). %USERNAME% will not create the shortcut in a folder for the user to see, but SYSTEM profile or an account for SCCM.

DaSe
  • 64
  • 5