Run .cmd from action script not working

In case anyone is familiar with the B2B SI Application - there is a stop and start cmd file that runs through a list of checks and either stops or starts services accordingly.
The Stop file works fine no matter how I call it from BigFix - I’ve called it using PS, and just using “run” or “runhidden”, “waithidden” etc etc and the Stop file always works.

The Start file, on the other hand, does nothing. In some of the examples above, BF thinks its completed but nothing happens on the server side.
I’m finding suggestions etc from searching the web, its just that nothing is working in this scenario.

Below is the path and Start script in its entirety - this is NOT a file share btw, but a local drive/path
Thank you in advance…

D:\ibm\si\install\bin\stopWindowsService.cmd

@echo off
REM ########################################################################
REM Licensed Materials - Property of IBM
REM
REM © Copyright IBM Corp. 2007, 2014 All Rights Reserved.
REM
REM US Government Users Restricted Rights - Use, duplication or disclosure
REM restricted by GSA ADP Schedule Contract with IBM Corp.
REM ########################################################################
@echo off
setlocal
set input=noOps
if “%1” EQU “restart” set input=%1

REM Validating JDK of the install

Set MyCurDir=%CD%
Set INSTALL_DIR=D:\IBM\SI\install
set DATETIMESTAMP=%DATE%%TIME%
set DATETIMESTAMP=%DATETIMESTAMP: =%
set DATETIMESTAMP=%DATETIMESTAMP:/=
%
set DATETIMESTAMP=%DATETIMESTAMP:,=%
set DATETIMESTAMP=%DATETIMESTAMP:.=%
set DATETIMESTAMP=%DATETIMESTAMP::=%
set LOGSDIR=D:\IBM\SI\install\logs
set LOGSBACKUPDIR=D:\IBM\SI\install\logs\LOGS
%DATETIMESTAMP%
set LIBERTY_PORT=16017
set SERVICE_NAME=“IBMSILibertyProfileat%LIBERTY_PORT%”

call %MyCurDir%\tmp.cmd

%JAVA% -classpath D:/IBM/SI/install/jar/bootstrapper.jar;D:/IBM/SI/install/jar/install_foundation.jar;D:/IBM/SI/install/jar/antInstaller/0_8/antinstaller.jar -Dvendor=shell -DvendorFile=D:\IBM\SI\install\properties\servers.properties com.sterlingcommerce.woodstock.noapp.NoAppLoader -f D:\IBM\SI\install\properties\dynamicclasspath.cfg -class com.sterlingcommerce.woodstock.install.antinstaller.validate.JDKValidator -f D:/IBM/SI/install/properties/dynamicclasspath.cfg -invokeargs D:/IBM/SI/install/properties/matrix.properties > D:\IBM\SI\install\logs/noapp.log 2>&1
set codeExit=%errorlevel%

REM echo errorlevel : %errorlevel%
REM echo codeExit : %codeExit%
REM rc is 1 - for validation
REM rc is 0 - for skip validation

if %codeExit% EQU 1 (
echo "!! startWindowsService.cmd ABORTED !!"
echo "!!!"
echo "The JDK Version is not supported. "
echo "Please upgrade your JDK to the supported version as per the documentation."
echo "!!!"
echo "exiting…"
exit /B %rc%
)else (

call %MyCurDir%\updateXercesJars.cmd %INSTALL_DIR%\jdk false
call %MyCurDir%\updateJettyJars.cmd
)

if “%1” EQU “restart” (
call D:\IBM\SI\install\bin\db_exec.cmd "Delete from OPS_NODE_INFO where NODE_NAME is not null"
call D:\IBM\SI\install\bin\db_exec.cmd "Update SCHEDULE set SYSTEMNAME=‘node1’"
call D:\IBM\SI\install\bin\db_exec.cmd “Delete from LOCKS where ITEMNAME is not null and CLEARONSTARTUP > 0”
)

call D:\IBM\SI\install\bin\backUpLogs.cmd %LOGSBACKUPDIR%

call D:\IBM\SI\install\bin\startOpsWindowsService.cmd
call D:\IBM\SI\install\bin\startContainerWindowsService.cmd
REM call D:\IBM\SI\install\bin\startActiveMQWindowsService.cmd
call D:\IBM\SI\install\bin\startContainerWindowsService.cmd
call D:\IBM\SI\install\bin\startASIWindowsService.cmd %input%

REM -------------------------------------------------------------------------
REM at this point the system is up, all services have been started, call any clump specific processing

set LAUNCH_CLA2_SERVER=“false”

set CLA2_REGRESSION_PORT=""

if not exist %LOGSBACKUPDIR% (
md %LOGSBACKUPDIR%
move %LOGSDIR%*.log* %LOGSBACKUPDIR% >NUL
)

if %LAUNCH_CLA2_SERVER% EQU “true” set result=true
if %CLA2_REGRESSION_PORT% NEQ “” set result=true
if “%result%” == “true” (
if exist D:\IBM\SI\install\bin\startCLA2WindowsService.cmd (
echo "Starting CmdLine2 client…"
call D:\IBM\SI\install\bin\startCLA2WindowsService.cmd
)
) else (
echo "CmdLine2 Client is disabled. Not starting CmdLine2 client…"
echo “If you wish to enable starting of the CmdLine2 Client be sure to set or add LAUNCH_CLA2_SERVER=true in sandbox.cfg”
)

if exist D:\IBM\SI\install\bin\startSAPControllerWindowsService.cmd (
call D:\IBM\SI\install\bin\startSAPControllerWindowsService.cmd
)

if exist D:\IBM\SI\install\bin\startWebdavWindowsService.cmd (
call D:\IBM\SI\install\bin\startWebdavWindowsService.cmd
)

REM if exist D:\IBM\SI\install\bin\startEventListenersWindowsService.cmd (
REM call D:\IBM\SI\install\bin\startEventListenersWindowsService.cmd
REM )

if exist D:\IBM\SI\install\bin\startSPEWindowsService.cmd (
call D:\IBM\SI\install\bin\startSPEWindowsService.cmd
)

echo %SERVICE_NAME% service is starting.

if exist D:\IBM\SI\install\bin\startLiberty.cmd (
for /F "tokens=3 delims=: " %%H in ('sc query %SERVICE_NAME% ^| findstr “STATE” ') do (
if /I “%%H” NEQ “RUNNING” (
if /I “%%H” NEQ “START_PENDING” (
sc start %SERVICE_NAME% >nul 2>&1
)
)
)
)

echo %SERVICE_NAME% service started successfully.

if exist D:\IBM\SI\install\properties\supplementalPassphrase.properties (
del D:\IBM\SI\install\properties\supplementalPassphrase.properties > NUL
)

It looks like you might have pasted in the stopWindowsService.cmd contents.

Also, use the code block, shown as </> in the editor, to make reading code easier.)

Does startWindowsService.cmd work from a Command window running as the Local System account?

psexec provides this capability. See Running Powershell Script through BigFix as an example.

The content is correct - the path just shows the stop cmd but the path to the start cmd is the same.
I pasted the content as it was created by IBM - I didnt create this :slight_smile:

I have this code that was provided by my BF support contact that I use for other purposes.
I used it to open cmd and run this cmd and the Start cmd still doesnt run, but BF thinks it does.

// Disable wow64 redirection on x64 OSes
action uses wow64 redirection {not x64 of operating system}

delete __createfile

// CREATEFILE
createfile until END_OF_FILE
–add script here–

END_OF_FILE

delete powershell.ps1
move __createfile powershell.ps1

waithidden { pathname of file ((it as string) of value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell” of native registry) } -ExecutionPolicy unrestricted -File powershell.ps1

Maybe @JasonWalker can help with this.

To add to this, just for reference…
With the PS option, I’ve tried these as well…

Invoke-Item D:\ibm\si\install\bin\startWindowsService.cmd
Invoke-Expression -Command "cmd.exe /c D:\ibm\si\install\bin\startWindowsService.cmd"
start-process -wait “D:\ibm\si\install\bin\startWindowsService.cmd”

And random other combos and versions - all of which seem to work fine for the stop cmd but not the start cmd.

I went so far as to recreate the cmd file as a batch file and drop it under C:\temp and again, stop works start doesnt.

I have also checked permissions from top down and System has Full Control down to the files in question.

Thanks a lot for the help…

I agree with @itsmpro92 that the first step is to try to run the batch, in an environment as close to BigFix’s client environment as possible. That means opening a 32-bit command prompt, running as LocalSystem, most easily done via psexec.

psexec -i -s \windows\syswow64\cmd.exe

From that new command prompt window, try running the start service batch. You may find it doesn’t run in 32-bit mode, or that LocalSystem can’t run some of the commands (I’m suspicious of some of the db_exec commands, perhaps LocalSystem needs some kind of database access?)

If that doesn’t work, try it with the 64-bit command prompt via
psexec -i -s \windows\system32\cmd.exe

Let us know about both cases

Installed pstools
Opened admin cmd prompt and ran your commands one at a time then tested the START cmd.
Both 64 and 32 bit windows ran the cmd fine. (did stop then start so services were actually stopped)
Actually did this multiple times just because with no issues.

The BF log just shows completion and Event Viewer has no record of anything.
Truly doesnt make any sense to me.
Is there a way to use appendfile and put the entire code into the action script?
I tried this already but couldnt get it to work right.

Thanks again for the help…

Can you paste the entire ActionScript you are running here?

I dont have anything specific right now. In the first post, I mentioned all of the variations I’ve tried using PS and just calling cmd.exe.
Using the full text of the cmd file was just a guess more or less using this - https://bigfix.me/content/shelltoaction

Throw in a pause at the end of the script, put the script on the remote pc and run it remotely. psexec psexec.exe -s \pcname cmd.exe /C file.bat You should see what the error is

No errors, this works just fine.

Sorry, I don’t think I’ll be able to help identify why your Action Script isn’t working if you can’t post it here.

A bit confused by your comment.
I have no action script to post here.
In my previous comments, I’ve pasted various action script attempts to make this work.
I’ve attempted to use the shelltoaction - https://bigfix.me/content/shelltoaction using BF to create the batch file and run it.
I’ve used various PS one liners - including cmd line options like ‘run’, ‘wait’, ‘waithidden’ etc etc plus these -
Invoke-Item D:\ibm\si\install\bin\startWindowsService.cmd
Invoke-Expression -Command "cmd.exe /c D:\ibm\si\install\bin\startWindowsService.cmd"
start-process -wait “D:\ibm\si\install\bin\startWindowsService.cmd”

There is not one specific method I’m attempting to make work, I’ve tried many different approaches and none are working for that START cmd code in the OP.

https://bigfix.me/content/shelltoaction - the page that says "The following form can be used to convert your *Nix Shell Scripts into Action Script that can be pasted into a fixlet or task."
Your .bat file is Windows.

Even if you had started with a shell script, posting the resultant actionscript may have been helpful.

That’s part of why I can’t help. If you are using

wait Invoke-Item D:\ibm\si\install\bin\startWindowsService.cmd
that’s not going to work, because you aren’t launching PowerShell.

If there’s a misplaced quote, path, wow64 redirection, etc…those can all make it fail, but I can’t tell what you’re doing until you post some actionscript.

The above was in a previous comment.
I’ve attempted to open PS with this and run those PS commands which do work for the STOP cmd, but not the START cmd.

Right, but…the PS script isn’t included.

Does the script contain any { symbols? They’d need to be escaped as {{.

Also maybe an issue with how the cmd.exe and path to the batch file are quoted? I don’t know whether Invoke-Expression is resolving all that as ‘a filename with spaces in it’ rather than ‘a command line with parameters’

I suppose to that point, I would be asking for help on how to write this correctly with or without PS.
I’ve tried using that wrapper with PS one liners that work for the stop cmd but not the start.
I’ve used basic cmd line one liners with “run”, “runhidden”, etc etc that also work for one but not the other.
We have the content of the START cmd in the OP.

I can run this in every way locally and it works fine. My tests using 32 and 64 bit work, test as system work.
Just not when initiated by BF.

The path being D:\ibm\si\install\bin\startWindowsService.cmd - any advice on how to write this correctly as an action script we’d be willing to test.
I’ve enlisted the assistance of a co-worker as well thats more of a PS guru than myself so he’s doing some testing now.

1 Like

The template I’d use for this would be

action uses wow64 redirection false

waithidden cmd.exe /c ""D:\ibm\si\install\bin\startWindowsService.cmd" > "D:\ibm\logfile.txt" 2>&1"

continue if {exit code of action = 0}

That should run the batch file, and save an output log to D:\ibm\logfile.txt. The log should contain both “stdout” and “stderr” so you can see if any errors were displayed by the batch itself.

1 Like

This is what that returns in the log file -

‘C:\Program’ is not recognized as an internal or external command,
operable program or batch file.
\BigFix was unexpected at this time.