I have a user interface that generates, on a directory called BatForRundeck, a set of CSV files (several per user), xlsm files (one per user) and .bat files (one per user). The processing of these CSV files is done by the generated xlsm file. This xlsm is launched by a VBScript file with parameters but common to all users. The VBScript file is started by the generated .bat. This processing chain should be automated using Rundeck. I am using a new .bat that loops over the BatForRundeck directory to process user generated .bat. The code is as following:
@echo off
for %%f in (C:\Users\myUserName\Documents\BatForRundeck\*10000*.bat) do call %%f
This .bat program works fine on my PC. But on Rundeck, this program runs but it does not launch Excel (xlsm) and CSV files are not processed.
I then tried another variant:
@echo off
for %%f in (C:\Users\myUserName\Documents\BatForRundeck\*10000*.bat) do echo call %%f >> C:\Users\myUserName\Documents\BatForRundeck\toto.bat
start C:\Users\myUserName\Documents\BatForRundeck\toto.bat
Remarque : I didn't delete toto.bat, because I wanted to see what it contains.
I have the same result, this .bat works fine on my PC. But on Rundeck, this program does not launch Excel (xlsm).
Example content of toto.bat:
call C:\Users\myUserName\Documents\BatForRundeck\Macro_RSI_V10_4-10000442896544.bat
call C:\Users\myUserName\Documents\BatForRundeck\Macro_RSI_V10_4-10000880367985.bat
The .bat Macro_RSI_V10_4-10000442896544.bat has the following code :
@echo off
C:\Users\myUserName\Documents\BatForRundeck\Macro_RSI_V10_4.OID.vbs Macro_RSI_V10_4.10000442896544.xlsm
And the Macro_RSI_V10_4-10000880367985.bat contains:
@echo off
C:\Users\myUserName\Documents\BatForRundeck\Macro_RSI_V10_4.OID.vbs Macro_RSI_V10_4.10000880367985.xlsm
The VBS Macro_RSI_V10_4.OID.vbs program contains the following code:
'Microsoft Excel Automation Basics
':: Open and Execute an Excel File.
'---------------------------------
'Retrieve the parameters that were passed.
Dim Arg
Set Arg = WScript.Arguments
'The first parameter begins with 0 as index.
Dim MacroName
MacroName = Arg(0) 'Ex : Macro_RSI_V10_4.10000442896544.xlsm
'create the excel object
Set objExcel = CreateObject("Excel.Application")
'view the excel program and file, set to false to hide the whole process
objExcel.Visible = False
'open an excel file (make sure to verify the location) .xls for 2003 or earlier
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\myUserName\Documents\BatForRundeck\" & MacroName)
'close the workbook
'objWorkbook.Close
'exit the excel program
objExcel.Quit
'release objects
Set objExcel = Nothing
Set objWorkbook = Nothing
Communication between Rundeck and my PC is working fine. I manage to launch .bat which create Text files in .txt or .csv formats. But I can't start Excel. The question I ask is whether there is some way to Rundeck special procedure to run an Excel file on my machine or another remote machine?
After installing Python in 64 bits and then Python in 32 bits, after using OpenPyXL, xlrd, Win32com, Pythoncom, my problem persisted. Especially since the scripts .bat or .vbs worked very well on my Windows machine and launched Excel as expected.
The message:
pywintypes.com-error: (-2147352567, 'An exception has occurred.', (0, None, None, None, None, 0, -2146788248), None)
which caught my attention to the fact that it is rather a problem of the COM objects.
The solution is to run DCOMCNFG (shortcut Win+R, type DCOMCNFG and then Enter), go to Component Services --> My Computer --> DCOM Config --> Microsoft Excel Application. Now access the Properties and modify the option value in the Identity tab to "The interactive user".