加入星计划,您可以享受以下权益:

  • 创作内容快速变现
  • 行业影响力扩散
  • 作品版权保护
  • 300W+ 专业用户
  • 1.5W+ 优质创作者
  • 5000+ 长期合作伙伴
立即加入
  • 正文
    • 需求
    • win配置
    • 结语
  • 推荐器件
  • 相关推荐
  • 电子产业图谱
申请入驻 产业图谱

如何在命令提示符/Powershell 启动时运行自定义命令

2023/02/17
1717
阅读需 4 分钟
加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论

今天分享的内容是如何在命令提示符/Powershell 启动时运行自动命令

需求

之前写过一篇文章,在ubuntu下设置bash,打开终端显示自己的banner,这是ubuntu设置的文章的链接,在window下怎么操作呢,我想打开命令提示符或 PowerShell或者windows Terminal,这个时候终端也可以显示自定义banner,如下实现情况:

win配置

设置自动 PowerShell 命令
要在 PowerShell 中自动运行命令,需要编辑配置文件。要开始使用,先检查是否已有个人资料。打开 PowerShell 输入以下内容:

Test-Path $Profile

这将返回 True 或 False。

如果为假,运行以下命令:

New-Item –Path $Profile –Type File –Force

这会覆盖任何现有的配置文件。如果前面的命令返回 True,不需要任何操作。

设置自动命令,使用notepad打开配置文件:

notepad $Profile

我里面增加pyfiglet.exe工具执行空心字的打印。

这样就可以在 PowerShell 启动时候执行一遍pyfiglet.exe LiuYuNing。这个原理和Linux中编辑“~/.bash_profile”文件基本相同。

在大多数情况下,PowerShell 的执行策略会阻止此脚本运行。要自动脚本运行,还要以管理员身份启动 PowerShell 执行如下命令:

Set-ExecutionPolicy RemoteSigned

阅读提示并输入 Y 以设置新的执行策略。

设置自动命令提示符命令
与用于在 PowerShell 中自动运行命令的 Unix 风格方法相比,命令提示符更像 Windows。有两种不同的方法可以做到这一点,具体取决于您喜欢的工作方式。

附:如果我们需要进行开机自动启动的脚本:将启动bat脚本放入:%appdata%MicrosoftWindowsStart MenuProgramsStartup这个目录,脚本就会在电脑启动时候自动执行。

此外关于Powershell自动运行命令还可以参考官方文章:https://rishivoice.com/post/37061.html

结语

这就是我自己在openwrt制作patch补丁使用分享。如果大家有更好的想法和需求,也欢迎大家加我好友交流分享哈。

作者:良知犹存,白天努力工作,晚上原创公号号主。公众号内容除了技术还有些人生感悟,一个认真输出内容的职场老司机,也是一个技术之外丰富生活的人,摄影、音乐 and 篮球。关注我,与我一起同行。

推荐器件

更多器件
器件型号 数量 器件厂商 器件描述 数据手册 ECAD模型 风险等级 参考价格 更多信息
CSTCC4M91G56A-R0 1 Murata Manufacturing Co Ltd Resonators 4.910MHZ .5% CHIP RESON MS5
暂无数据 查看
510BBA156M250BAG 1 Silicon Laboratories Inc LVDS Output Clock Oscillator,

ECAD模型

下载ECAD模型
$3.56 查看
TORX1952A(F) 1 Toshiba America Electronic Components FIBER OPTIC RECEIVER
$8.35 查看
OpenWrt

OpenWrt

Welcome to the OpenWrt Project The OpenWrt Project is a Linux operating system targeting embedded devices. Instead of trying to create a single, static firmware, OpenWrt provides a fully writable filesystem with package management. This frees you from the application selection and configuration provided by the vendor and allows you to customize the device through the use of packages to suit any application. For developers, OpenWrt is the framework to build an application without having to bui…

Welcome to the OpenWrt Project The OpenWrt Project is a Linux operating system targeting embedded devices. Instead of trying to create a single, static firmware, OpenWrt provides a fully writable filesystem with package management. This frees you from the application selection and configuration provided by the vendor and allows you to customize the device through the use of packages to suit any application. For developers, OpenWrt is the framework to build an application without having to bui…收起

查看更多

相关推荐

电子产业图谱

一个程序员,喜欢写文章,还喜欢打篮球,也喜欢吉他钢琴的驳杂之人。日常更新自己,分享包括但不限于C/C++、嵌入式、物联网、Linux等编程学习笔记,同时,公众号内包含大量的学习资源。欢迎关注,一同交流学习,共同进步!