使用powershell编写windwos环境安装程序并指定安装目录

#定义可输出改变盘符变量
$DriveLetter = "D:"
$NewDriveLetter = Read-Host "请输入盘符"

#判断输入的是否为英文字母,不是英文字母则终止运行
if ($NewDriveLetter -notmatch "^[A-Za-z]$") {
    Write-Host "输入无效,请输入只包含英文字母的盘符"
    exit
}

#判断输入的盘符是否存在,不存在则终止运行
if (-not (Test-Path "$NewDriveLetter`:\")) {
    Write-Host "输入的盘符不存在,运行终止"
    exit
}

Write-Host "修改前的盘符: $DriveLetter"
Write-Host "修改后的盘符: $NewDriveLetter"

$DriveLetter = $NewDriveLetter + ":"

Write-Host "修改后的盘符变量: $DriveLetter" 

#定义路径变量
$Codepath = "softwares\VSCode\VSCodeUserSetup-x64-1.49.0.exe"
$Codeinstallpath = "softwares\VSCode"

#VScode安装
$installerPath = Join-Path $DriveLetter $Codepath  # 安装包.exe程序所在目录
$installPath = Join-Path $DriveLetter $Codeinstallpath  # 定义安装目录

#安装程序
Write-Host "正在安装VScode"
Start-Process -FilePath $installerPath -ArgumentList "/verysilent", "/mergetasks=!runcode", "/dir=$installPath" -Wait  # 安装到指定目录并静默安装完成后禁止自动运行

Write-Host "VScode安装完成!"

#robo 3t安装
$roboPath = "softwares\Robo 3T 1.4.1\robo3t-1.4.1-windows-x86_64-122dbd9.exe"
$roboinstallPath = "softwares\Robo 3T 1.4.1"
$installerPath = Join-Path $DriveLetter $roboPath # 安装包.exe程序所在目录
$installPath = Join-Path $DriveLetter $roboinstallPath # 定义安装目录

#安装程序
Write-Host "正在安装robo3t"
Start-Process -FilePath $installerPath -ArgumentList "/S", "/D=$installPath" -Wait  # 安装到指定目录并静默安装

Write-Host "robo3t安装完成!"

#Another安装
$AnotherPath = "softwares\Another Redis Desktop Manager\Another-Redis-Desktop-Manager.1.5.6.exe"
$AnotherinstallPath = "softwares\Another Redis Desktop Manager"
$installerPath = Join-Path $DriveLetter $AnotherPath # 安装包.exe程序所在目录
$installPath = Join-Path $DriveLetter $AnotherinstallPath # 定义安装目录

#安装程序
Write-Host "正在安装 Another Redis Desktop Manager..."
Start-Process -FilePath $installerPath -ArgumentList "/S", "/D=$installPath" -Wait # 安装到指定目录并静默安装

Write-Host "Another Redis Desktop Manager 安装完成!"

#jdk1.8安装
$jdkPath = "apps\softwares\jdk-8u281-windows-x64.exe"
$installerPath = Join-Path $DriveLetter $jdkPath # 安装包.exe程序所在目录

#安装程序
Write-Host "正在安装 jdk1.8"
Start-Process -FilePath $installerPath -ArgumentList "/s" -Wait # 安装程序静默安装到默认目录

Write-Host " jdk1.8安装完成!"

# 安装PM2
Write-Host "正在安装PM2..."
npm install pm2@5.3.0 -g

Write-Host "PM2安装完成!"

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秃头的花季少年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值