惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
H
Help Net Security
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 司徒正美
量子位
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
Scott Helme
Scott Helme
The Last Watchdog
The Last Watchdog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
AI
AI
WordPress大学
WordPress大学
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
U
Unit 42
V2EX - 技术
V2EX - 技术
MongoDB | Blog
MongoDB | Blog
Schneier on Security
Schneier on Security
博客园 - Franky
H
Heimdal Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
N
News | PayPal Newsroom
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
雷峰网
雷峰网

博客园 - loose_went

MacOS下打开和编辑.bash_profile文件 Mac开发利器之程序员编辑器MacVim学习总结(转) Mac下安装Home-brew成功 Canon MF113W激光打印机双面打印方法 MacBook Pro App Store无法下载和更新软件解决方案 收不到Win10正式版预订通知?一个批处理搞定 创业公司失败的20大原因:没市场需求排第一 phpAmin如何导入导出大数据文件? [转]项目管理心得:一个项目经理的个人体会、经验总结 项目经理角色定位 Windows下在本机创建SVN服务 整理的英语短语 软件版本Beta,RC,Demo,Build等是什么意思呢? 无线不能连接 --- 源于Wireless Zero Configuration服务不能自动启动 Excel 2007 如何画双纵坐标图 管理学中的知名定律之阿什法则 Word 2007突然不能显示图片的解决方法 管理学中的知名定律之阿尔布莱特法则 管理学中的知名定律之阿尔巴德定理
用PUSHD/POPD获得bat文件执行的路径
loose_went · 2011-07-07 · via 博客园 - loose_went

PUSHD/POPD是为了获得bat文件执行的路径。

这个很实用,比如我们想在程序里调用bat文件,bat文件内容如下,先安装一个windows service,然后启动它:

installutil.exe /i "MyWindowsService.exe"
net.exe start "MyWindowsService"

如果我是在做一个安装程序,我需要把这些文件包括bat文件先copy到一个安装目录,而且这个目录一般是用户自己选择的,安装程序并不知道。那我们要想让安装程序调用这个bat文件,就需要把bat文件写成这样:

PUSHD "%~dp0" //获得bat文件执行的路径
installutil.exe /i "MyWindowsService.exe"
net.exe start "MyWindowsService"
POPD

当然,为了保险起见,我们需要把installutil.exe和net.exe(都在c:\windows\system32\)copy到和bat文件相同的目录。这是为了保证有些操作系统可能是精简版或没有这些工具,安装程序也能顺利进行。