在启动时检查文本文件的应用程序在通过批处理文件启动时找不到文本文件

时间:2019-03-07 11:11:21

标签: batch-file exe

运行下面粘贴的.bat文件将创建应用程序运行所需的文本文件,但是,当通过.bat文件中的START行启动应用程序时,我的应用程序会通知我这些文件不存在。但是情况并非如此,好像我自己打开.exe来运行应用程序一样,我没有问题。

这是.bat文件。

pushd %~dp0
Powershell.exe -executionpolicy remotesigned -File "GetInstalledPrograms.ps1"

@ECHO OFF
SET InstalledProgramNames="InstalledProgramNames.txt"
SET InstalledProgramNames6432Node="InstalledProgramNames6432Node.txt"
SET InstalledProgramVersions="InstalledProgramVersions.txt"
SET InstalledProgramVersions6432Node="InstalledProgramVersions6432Node.txt"

:CheckForFile
IF EXIST %InstalledProgramNames% IF EXIST %InstalledProgramNames6432Node% IF EXIST %InstalledProgramVersions% IF EXIST %InstalledProgramVersions6432Node% GOTO FoundIt

REM If we get here, the file is not found.

REM Wait 5 seconds and then recheck.
REM If no delay is needed, comment/remove the timeout line.
TIMEOUT /T 5 >nul

GOTO CheckForFile

:FoundIt
ECHO Found: %InstalledProgramNames%
ECHO Found: %InstalledProgramNames6432Node%
ECHO Found: %InstalledProgramVersions%
ECHO Found: %InstalledProgramVersions6432Node%

REM Change this when releasing - it wont be debug
START "" "bin\Debug\NIThirdPartySoftwareChecker.exe"

编辑:.ps1文件,根据要求。

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName | Out-File -filepath  InstalledProgramNames6432Node.txt
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName | Out-File -filepath  InstalledProgramNames.txt
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayVersion | Out-File -filepath  InstalledProgramVersions6432Node.txt
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayVersion | Out-File -filepath  InstalledProgramVersions.txt

0 个答案:

没有答案