Rundeck 如何在我的机器上启动 Excel 文件?
How can Rundeck launch Excel file on my machine?
我有一个用户界面,它在名为 BatForRundeck 的目录中生成一组 CSV 文件(每个用户多个)、xlsm 文件(每个用户一个)和 .bat 文件(每个用户一个)。
这些 CSV 文件的处理是由生成的 xlsm 文件完成的。这个 xlsm 由一个 VBScript 文件启动,带有参数但对所有用户都是通用的。
VBScript 文件由生成的.bat 启动。
这个处理链应该使用 Rundeck 自动化。
我正在使用一个新的 .bat 循环遍历 BatForRundeck 目录来处理用户生成的 .bat。代码如下:
@echo off
for %%f in (C:\Users\myUserName\Documents\BatForRundeck\*10000*.bat) do call %%f
这个 .bat 程序在我的电脑上运行良好。但是在 Rundeck 上,这个程序 运行s 但它不会启动 Excel (xlsm) 并且 CSV 文件不会被处理。
然后我尝试了另一种变体:
@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
备注:我没有删除toto.bat,因为我想看看它包含什么。
我得到了相同的结果,这个 .bat 在我的电脑上运行良好。但是在 Rundeck 上,这个程序不会启动 Excel (xlsm)。
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
.bat Macro_RSI_V10_4-10000442896544.bat 具有以下代码:
@echo off
C:\Users\myUserName\Documents\BatForRundeck\Macro_RSI_V10_4.OID.vbs Macro_RSI_V10_4.10000442896544.xlsm
并且 Macro_RSI_V10_4-10000880367985.bat 包含:
@echo off
C:\Users\myUserName\Documents\BatForRundeck\Macro_RSI_V10_4.OID.vbs Macro_RSI_V10_4.10000880367985.xlsm
VBS Macro_RSI_V10_4.OID.vbs程序包含以下代码:
'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
Rundeck 和我的 PC 之间的通信工作正常。我设法启动 .bat,它以 .txt 或 .csv 格式创建文本文件。但是我无法启动Excel。
我问的问题是 Rundeck 特殊程序是否有某种方法可以 运行 我的机器或另一台远程机器上的 Excel 文件?
一个简单的解决方案是使用 python 脚本来启动您的文件,在 Windows 机器上 python 使用 python 解释器。
在 64 位安装 Python,然后在 32 位安装 Python,使用 OpenPyXL、xlrd、Win32com、Pythoncom 后,我的问题仍然存在。特别是因为脚本 .bat 或 .vbs 在我的 Windows 机器上运行良好并按预期启动 Excel。
留言:
pywintypes.com-error: (-2147352567, 'An exception has occurred.', (0, None, None, None, None, 0, -2146788248), None)
这引起了我的注意,这是 COM 对象的问题。
解决办法是运行DCOMCNFG(快捷键Win+R,输入DCOMCNFG回车),进入组件服务-->我的电脑--> DCOM 配置 --> Microsoft Excel 应用程序。现在访问属性并将身份选项卡中的选项值修改为“交互式用户”。
我有一个用户界面,它在名为 BatForRundeck 的目录中生成一组 CSV 文件(每个用户多个)、xlsm 文件(每个用户一个)和 .bat 文件(每个用户一个)。 这些 CSV 文件的处理是由生成的 xlsm 文件完成的。这个 xlsm 由一个 VBScript 文件启动,带有参数但对所有用户都是通用的。 VBScript 文件由生成的.bat 启动。 这个处理链应该使用 Rundeck 自动化。 我正在使用一个新的 .bat 循环遍历 BatForRundeck 目录来处理用户生成的 .bat。代码如下:
@echo off
for %%f in (C:\Users\myUserName\Documents\BatForRundeck\*10000*.bat) do call %%f
这个 .bat 程序在我的电脑上运行良好。但是在 Rundeck 上,这个程序 运行s 但它不会启动 Excel (xlsm) 并且 CSV 文件不会被处理。
然后我尝试了另一种变体:
@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
备注:我没有删除toto.bat,因为我想看看它包含什么。
我得到了相同的结果,这个 .bat 在我的电脑上运行良好。但是在 Rundeck 上,这个程序不会启动 Excel (xlsm)。
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
.bat Macro_RSI_V10_4-10000442896544.bat 具有以下代码:
@echo off
C:\Users\myUserName\Documents\BatForRundeck\Macro_RSI_V10_4.OID.vbs Macro_RSI_V10_4.10000442896544.xlsm
并且 Macro_RSI_V10_4-10000880367985.bat 包含:
@echo off
C:\Users\myUserName\Documents\BatForRundeck\Macro_RSI_V10_4.OID.vbs Macro_RSI_V10_4.10000880367985.xlsm
VBS Macro_RSI_V10_4.OID.vbs程序包含以下代码:
'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
Rundeck 和我的 PC 之间的通信工作正常。我设法启动 .bat,它以 .txt 或 .csv 格式创建文本文件。但是我无法启动Excel。 我问的问题是 Rundeck 特殊程序是否有某种方法可以 运行 我的机器或另一台远程机器上的 Excel 文件?
一个简单的解决方案是使用 python 脚本来启动您的文件,在 Windows 机器上 python 使用 python 解释器。
在 64 位安装 Python,然后在 32 位安装 Python,使用 OpenPyXL、xlrd、Win32com、Pythoncom 后,我的问题仍然存在。特别是因为脚本 .bat 或 .vbs 在我的 Windows 机器上运行良好并按预期启动 Excel。
留言:
pywintypes.com-error: (-2147352567, 'An exception has occurred.', (0, None, None, None, None, 0, -2146788248), None)
这引起了我的注意,这是 COM 对象的问题。
解决办法是运行DCOMCNFG(快捷键Win+R,输入DCOMCNFG回车),进入组件服务-->我的电脑--> DCOM 配置 --> Microsoft Excel 应用程序。现在访问属性并将身份选项卡中的选项值修改为“交互式用户”。