batch-file - 如何在第一次触发时跳过 bat 文件的运行但之后运行?
问题描述
我已安排以下任务在用户登录后每 XXX 次重复一次(这是触发 bat 文件的时间)。我想在消息框触发时跳过/不显示(意味着它第一次运行时),但在以下重复中不显示。关于如何解决这种情况的任何建议?
@echo off
SET client=Dear ABC,
SET MESSAGE=XYZ
@echo WScript.CreateObject("WScript.Shell").Popup "%client% %MESSAGE% & I will dissapear after 00 seconds.", 00, "title" > %TEMP%\wait.vbs
wscript %TEMP%\wait.vbs
解决方案
解决此问题的一种简单方法如下:
' Checks for the existence of a file which will
' serve as a flag, indicating if the script in
' question has already been run or not, acting
' accordingly afterwards.
Set objShell = CreateObject("WScript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
homeFolder = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
flagFile= homeFolder & "\flag.txt"
If (objFSO.FileExists(flagFile)) Then
' Display your message
msgbox("This is my message")
'...(do other things you want)
Else
' Do not display your message
' Creates flag to indicate that
' this script has already been executed
Set objFile = objFSO.CreateTextFile(flagFile,True)
'...(do other things you want)
End If
推荐阅读
- javascript - $("#id").val() 与 document.getElementById("id").value 的工作方式不同
- python - CNN 模型中的核权重初始化在哪里?
- android - 执行 adb 命令的脚本文件
- node.js - 模块导入在开发中与反应一起使用,但在构建中不使用
- go - 如何在终端中使用 Go 本地包
- reactjs - 如何将视图上的道具传递给 redux 连接的反应组件?
- java - 如何在一个窗口中制作两种颜色?
- javascript - BIRT - getPersistentGlobalVariable 只给出最后一行
- node.js - Raspberry Pi 本地网络为网站提供节点和控制模拟输出
- r - 在 R 中的“if 语句”中计算空值的问题