- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
问题摘要:
我可以在安全模式下从Windows批处理脚本启动Excel文件installer.xlsm,而不提供Excel.exe安装路径吗?
细节
我有一个windows批处理脚本,它可以从远程服务器下载一系列excel加载项的最新版本,将它们放在一个目录(c:\appname\add ins)中,并调用excel文件installer.xlsm。
加载时,installer.xlsm执行VBA宏,该宏卸载旧版本的加载项并安装其新版本。
当前,我使用以下命令启动installer.xlsm:
start "Launching installer file" /wait "<Path to file>\Installer.xlsm"
"<PathToExcel>excel" /safemode "<PathToXls>Installer.xlsm"
,如
this answer中所述,但此方法不使用windows的文件关联,并且要求我提供路径。
start "Launching installer file" /wait "<Path to file>\Installer.xlsm /safemode"
最佳答案
首先,我建议阅读Microsoft TechNet关于Application Registration的文章。它解释了应用程序或应用程序套件(如Microsoft Office)的安装程序应如何注册已安装的应用程序,以便其他应用程序可以找到应用程序的可执行文件。
建议在注册表项下创建
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
excel.exe
的子键,默认字符串值是具有完整路径的可执行文件名,还可以选择添加一个名为
Path
的字符串值,其中仅包含可执行文件的路径。
Path
字符串可以但大多数不存在,并且可以但不能以反斜杠结尾。
excel.exe
注册表项。
@echo off
for /F "skip=1 tokens=2*" %%A in ('%SystemRoot%\System32\reg.exe QUERY "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\excel.exe" /ve 2^>nul') do set "ExcelApp=%%~B"
echo ExcelApp=%ExcelApp%
pause
reg.exe
的输出不同,因此需要以下批处理代码:
@echo off
for /F "skip=3 tokens=3*" %%A in ('%SystemRoot%\System32\reg.exe QUERY "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\excel.exe" /ve 2^>nul') do set "ExcelApp=%%~B"
echo ExcelApp=%ExcelApp%
pause
start "Launching installer file" "C:\Path to file\Installer.xlsm"
@echo off
setlocal EnableExtensions DisableDelayedExpansion
rem First query default string value of HKEY_CLASSES_ROOT\.xlsm from registry.
call :GetDefaultRegValue "HKCR\.xlsm"
rem Is there no key HKEY_CLASSES_ROOT\.xlsm or was the default string empty?
if not defined RegValue goto GetFromAppPaths
SET RegValue
rem Get the shell command line used for opening a *.xlsm file.
call :GetDefaultRegValue "HKCR\%RegValue%\shell\open\command"
rem Could the command line not read successfully from Windows registry?
if not defined RegValue goto GetFromAppPaths
SET RegValue
rem The command line contains as first string usually enclosed in double
rem quotes EXCEL.EXE with full path enclosed in double quotes. And there
rem can be even more arguments on the command line which are not needed
rem here. The command line below is used to get just first string of
rem the command line which should be EXCEL.EXE with full path.
for %%I in (%RegValue%) do set "RegValue=%%~I" & goto CheckExcelExistence
rem It is not good when both registry queries above fail. This means
rem either Microsoft Excel is not installed at all or a version of
rem Excel is installed which does not support *.xlsm files like Excel
rem of MS Office 2003, MS Office 2000 or MS Office 97.
rem However, perhaps just *.xlsm is not correct registered and therefore
rem get full path to excel.exe from application registration key.
:GetFromAppPaths
call :GetDefaultRegValue "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\excel.exe"
if defined RegValue goto CheckExcelExistence
echo Failed to determine installation location of Microsoft Excel.
echo/
endlocal
pause
goto :EOF
:CheckExcelExistence
SET RegValue
rem Remove surrounding double quotes if the Excel executable file name
rem read from Windows registry is still enclosed in double quotes.
set "RegValue=%RegValue:"=%"
if exist "%RegValue%" goto :RunInstall
echo Registered "%RegValue%" does not exist.
echo/
endlocal
pause
goto :EOF
:RunInstall
SET RegValue
ECHO start "Launching installer file" /wait "%RegValue%" "%~dp0Installer.xlsm" /safemode
endlocal
goto :EOF
rem This subroutine queries from Windows registry the default string value of
rem the key passed to the subroutine as first and only parameter and assigns
rem this value to environment variable RegValue. Environment variable RegValue
rem is deleted and therefore is not defined after subroutine exits on failure
rem to get the registry value or when the default value is an empty string.
rem This subroutine works for Windows XP and all later versions of Windows.
:GetDefaultRegValue
set "TypeToken=2"
:Reg3Run
for /F "skip=1 tokens=%TypeToken%*" %%A in ('%SystemRoot%\System32\reg.exe QUERY "%~1" /ve 2^>nul') do (
if "%%A" == "REG_SZ" (
if not "%%~B" == "" (
set "RegValue=%%B"
goto :EOF
)
) else if "%%A" == "NAME>" (
set "TypeToken=3"
goto Reg3Run
)
)
set "RegValue="
goto :EOF
start
的echo left…在label
RunInstall
下面的块中。
SET RegValue
。这4行只输出从windows注册表成功查询并存储在环境变量
RegValue
中的字符串值。这4个命令有助于理解执行批处理文件时发生的情况。最后从批处理文件中删除这四条命令行,并删除大写的单个echo。
#
开头的行的最后一个双引号前插入一个像
call :GetDefaultRegValue
这样的单个字符,就不会再找到修改后的注册表项。
call /?
echo /?
endlocal /?
for /?
goto /?
if /?
pause /?
reg /?
reg query /?
rem /?
setlocal /?
start /?
2>nul
的解释。重定向运算符
>
必须用插入符号
^
转义,以便在windows命令解释器在执行命令之前处理此命令行时,将命令行解释为文本字符,而该命令行在单独的命令进程中执行嵌入的
reg.exe
命令行。从后台开始。
关于excel - 从Windows批处理脚本以安全模式启动Excel文件,使用默认文件关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45509710/
我一直在尝试找到一种正确的方法来将一些信息(例如密码)传递到我的小程序。由于代码是在客户端上执行的,我不想将该信息以明文形式放在“param”中。 我使用 php 作为脚本来生成网页。所以,我想知道是
我有一些同事构建了 WCF 服务。他们的安全设置如下: security mode="None" transport clientCredentialType="Windows" proxyCr
我正在寻找一些关于如何在客户端 JavaScript 中处理基本安全需求(例如授权)的良好资源、模式和实践。 我正在构建一个网站,其后端系统运行常见的 MVC 框架之一。后端将处理所有真正的安全需求:
我最近构建了一个 WCF 服务,现在准备为其添加安全性。我想让它通过 https 可用,面向互联网,客户端将使用用户名和密码进行身份验证。我只会有 3 个用户,所以我想使身份验证尽可能简单。此外,请求
我知道我可以关闭 MySQL 中的安全模式,所以我不会尝试解决这个问题。 我有一个简单的表格: create table rubbish( id int auto_increment prim
我愚蠢地尝试了 MySQL_update,因为我在授予远程 ips 权限时遇到问题,但我使用/usr/bin/mysqld_safe --skip-grant-tables 进入了安全模式 现在我无法
我无法在 Drupal 7 中上传图像,因为我已将其移至新服务器:已启用 php 安全模式。所以在 php.ini 中我设置了 safe_mode = Off(通过 ssh,我有 CentOS)。 p
我安装 Visual Studio 2017 Enterprise 扩展后,VS 在启动时崩溃。在以前的版本中,有一个/safemode 开关。我试过了,但似乎不再支持。当 Visual Studio
我使用 Firefox 驱动程序运行大量自动化,这需要一段时间(20-30 分钟)。当然,在它运行期间,我会继续处理其他事情。 但是,在我做事时,我偶尔会在新的 Firefox 实例启动时按下 Shi
我正在调试一个调用 Word 2007 来呈现某些办公文件的 C# 程序。只要 Word 正常启动和关闭,一切都会正常运行。 在少数没有出现的情况下,下一次 Word 会弹出一条消息。它基本上说它上次
关于PHP安全模式的问题: 默认情况下,它在 PLESK 共享主机帐户环境中打开:虽然在我的网站上似乎运行良好,但关闭时它可能运行得更快/更好?我不太理解下面的文字,尤其是 PHP 的解释: 普莱斯克
根据PHP Safe Mode Docs在 safe_mode_gid 上: By default, Safe Mode does a UID compare check when opening f
我使用 FeedDemon 并且我注意到一些 Tumblr RSS 提要最近停止工作。我认为这是随机的,但我发现所有停止工作的提要都是针对 NSFW 博客的。 似乎 Tumblr 的默认安全模式过滤器
security mode="Transport"有什么区别和 security mode="TransportCredentialOnly"当我与 BasicHttpBinding 一起使用时并在
有谁知道如何确定 .NET 中的安全模式(混合模式或 Windows 身份验证)? 编辑:我正在使用普通的 ADO.NET 对象(SqlConnection、SqlCommand 等)连接到数据库。
我是一名优秀的程序员,十分优秀!