Run .cmd from action script not working

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.

Looks like a problem inside the start Windows service.cmd script. I suspect it could be related to this line in it

Set MyCurDir=%CD%

Not handling spaces or parenthesis in the working directory path for C:\Program Files (x86)\BigFix Enterprise\...

So, when you ran this manually, did you first ‘cd’ into the \ibm\install directory? That may be the difference.

You may want to use a small ‘createfile’ to first CD into the script’s directory and then run it…

delete __createfile
createfile until EOF
cd /d "D:\ibm\si\install\bin"
startWindowsService.cmd
EOF

delete wrapper.cmd
move __createfile wrapper.cmd

action uses wow64 redirection false

waithidden cmd.exe /c ""wrapper.cmd" > "D:\ibm\logfile.txt" 2>&1"

continue if {exit code of action = 0
2 Likes

Run locally, I could do it either way, cd in or not and it’d work.
I had my hunch from the beginning that there was something specific to this cmd file that was causing the problem but had no idea how to determine what it was.

Your last recommendation solved the problem here and my appreciation for this cannot be communicated properly here :slight_smile:

Thank you very very much for your patience and help with this…

1 Like

Glad I was able to help!

Might not be so much a problem of ‘must be in that working directory to run the script’, so much as ‘working directory chokes on parentheses in Program Files (x86)’

2 Likes