【玩转腾讯云】购买Windows CVM时自动安装Chrome、Firefox浏览器

2024-06-06 19:26:13 浏览数 (3)

Server2022之前的server系统默认是IE浏览器,微软已经不再支持IE了,所以新购的服务器安装一个好用的浏览器很关键。

我比较常用的是Chrome和Firefox浏览器,希望购买CVM后自动安装Chrome、Firefox。研究了下,实现起来不难。

购买机器有两种方式,图形界面购买和API接口购买,下面2种方式我都介绍下如何自动安装Chrome、Firefox,尾部有我录的视频。

一、网页控制台购买

https://buy.cloud.tencent.com/cvm

自定义参数

【Chrome】

代码语言:javascript复制
<powershell>
$Path = "C:chrome_installer.exe";
(new-object System.Net.WebClient).DownloadFile("http://dl.google.com/chrome/install/375.126/chrome_installer.exe",$Path);
Start-Process -FilePath $Path -Args "/silent /install" -Verb RunAs -Wait;
Remove-Item $Path
</powershell>

或者

代码语言:javascript复制
<powershell>
$Path = "C:chrome_installer.exe";
Invoke-WebRequest "http://dl.google.com/chrome/install/375.126/chrome_installer.exe" -OutFile $Path;
Start-Process -FilePath $Path -Args "-ms /MaintenanceService=false /DesktopShortcut=true";
Remove-Item $Path;
</powershell>

前后那对标签<powershell></powershell>就不说了,参考官网文档https://cloud.tencent.com/document/product/213/17526

4句代码

第1句:指定路径

第2句:下载

第3句:安装

第4句:删除

举一反三,我们也可以按照同样办法在新购Windows CVM时自动安装Firefox浏览器

【Firefox】

安装文件下载地址:https://www.mozilla.org/en-US/firefox/all/#product-desktop-release

Firefox有.msi和.exe两种安装包,对应两种安装方式

.msi方式

代码语言:javascript复制
<powershell>
$Path = "C:Firefox-latest.msi";
(new-object System.Net.WebClient).DownloadFile("http://download-installer.cdn.mozilla.net/pub/firefox/releases/115.11.0esr/win64/zh-CN/Firefox Setup 115.11.0esr.msi",$Path);
MsiExec.exe /i $Path  INSTALL_MAINTENANCE_SERVICE=false DESKTOP_SHORTCUT=true /qn
start-sleep -s 60
Remove-Item $Path
</powershell>

.exe方式

代码语言:javascript复制
<powershell>
$Path = "C:Firefox-latest.exe";
(new-object System.Net.WebClient).DownloadFile("http://download-ssl.firefox.com.cn/releases-sha2/stub/official/zh-CN/Firefox-latest.exe",$Path);
Start-Process -FilePath $Path -Args "-ms /MaintenanceService=false /DesktopShortcut=true"
start-sleep -s 60
Remove-Item $Path
</powershell>

base64编码在线工具很多:

base64.us

http://www.jsons.cn/base64/

是否勾选base64编码是很关键的,不勾选则是填明文,勾选则填base64编码后的字符串

二、API接口购买

https://console.cloud.tencent.com/api/explorer?Product=cvm&Version=2017-03-12&Action=RunInstances

JSON入参仅供参考

代码语言:javascript复制
{
        "InstanceChargeType": "POSTPAID_BY_HOUR",
        "Placement": {
            "Zone": "ap-beijing-6",
            "ProjectId": 0
        },
        "VirtualPrivateCloud": {
            "VpcId": "DEFAULT",
            "SubnetId": "DEFAULT",
            "Ipv6AddressCount": 0
        },
        "InstanceType": "S5.MEDIUM2",
        "ImageId": "img-m07ny34j",
        "SystemDisk": {
            "DiskSize": 50,
            "DiskType": "CLOUD_PREMIUM"
        },
        "InternetAccessible": {
            "InternetMaxBandwidthOut": 1,
            "PublicIpAssigned": true,
            "InternetChargeType": "TRAFFIC_POSTPAID_BY_HOUR"
        },
        "InstanceName": "abcdefgh-{R:111}",
        "LoginSettings": {
            "Password": "auNv4Pg5xpc="
        },
        "SecurityGroupIds": [ "sg-4z1vm5yx" ],
        "InstanceCount": 2,
        "EnhancedService": {
            "SecurityService": {
                "Enabled": true
            },
            "MonitorService": {
                "Enabled": true
            },
            "AutomationService": {
                "Enabled": true
            }
        },
        "HostName": "abcdefgh-{R:111}",
        "DryRun": false,
        "UserData": "PHBvd2Vyc2hlbGw ClNldC1FeGVjdXRpb25Qb2xpY3kgLVNjb3BlIEN1cnJlbnRVc2VyIFVucmVzdHJpY3RlZCAtZm9yY2UKaWYoLU5PVCAoW1NlY3VyaXR5LlByaW5jaXBhbC5XaW5kb3dzUHJpbmNpcGFsXVtTZWN1cml0eS5QcmluY2lwYWwuV2luZG93c0lkZW50aXR5XTo6R2V0Q3VycmVudCgpKS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GM9IgplY2hvICJSRUdFRElUNCIgPiBjOlx0ZW1wLnJlZwplY2hvICJbSEtFWV9MT0NBTF9NQUNISU5FXFNPRlRXQVJFXE1pY3Jvc29mdFxXaW5kb3dzIE5UXEN1cnJlbnRWZXJzaW9uXFdpbmxvZ29uXSIgPj4gYzpcdGVtcC5yZWcKZWNobyAiYCJBdXRvQWRtaW5Mb2dvbmAiPWAiMWAiIj4 IGM6XHRlbXAucmVnCmVjaG8gImAiRGVmYXVsdFVzZXJOYW1lYCI9YCJBZG1pbmlzdHJhdG9yYCIiICA PiBjOlx0ZW1wLnJlZwplY2hvICJgIkRlZmF1bHRQYXNzd29yZGAiPWAiYXVOdjRQZzV4cGM9YCIiID4 IGM6XHRlbXAucmVnCmNtZCAvYyAicmVnIGltcG9ydCBjOlx0ZW1wLnJlZyIKZGVsICJjOlx0ZW1wLnJlZyIgMj4mMSA ICRudWxsCnJlc3RhcnQtY29tcHV0ZXIgLWZvcmNlCjwvcG93ZXJzaGVsbD4K"
    }

自定义数据明文代码安装Chrome、Firefox并设置重启后自动登录(注意代码里的密码改成自己的密码),示例代码仅供参考

代码语言:javascript复制
<powershell>
Set-ExecutionPolicy -Scope CurrentUser Unrestricted -force
if(-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")){
$arguments = "& '"   $myinvocation.mycommand.definition   "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}

$Path = "C:chrome_installer.exe";
(new-object System.Net.WebClient).DownloadFile("http://dl.google.com/chrome/install/375.126/chrome_installer.exe",$Path);
Start-Process -FilePath $Path -Args "/silent /install" -Verb RunAs -Wait;
Remove-Item $Path;

$Path = "C:Firefox-latest.exe";
(new-object System.Net.WebClient).DownloadFile("http://download-ssl.firefox.com.cn/releases-sha2/stub/official/zh-CN/Firefox-latest.exe",$Path);
Start-Process -FilePath $Path -Args "-ms /MaintenanceService=false /DesktopShortcut=true";
start-sleep -s 60;
Remove-Item $Path;

net user Administrator "auNv4Pg5xpc="
echo "REGEDIT4" > c:temp.reg
echo "[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWinlogon]" >> c:temp.reg
echo "`"AutoAdminLogon`"=`"1`"">> c:temp.reg
echo "`"DefaultUserName`"=`"Administrator`""  >> c:temp.reg
echo "`"DefaultPassword`"=`"auNv4Pg5xpc=`"" >> c:temp.reg
cmd /c "reg import c:temp.reg"
del "c:temp.reg" 2>&1 > $null
restart-computer -force
</powershell>

自定义数据明文代码安装Chrome、Firefox并设置重启后自动登录、自动安装IIS,示例代码仅供参考:

其实就是在上面的代码里加了一句话

代码语言:javascript复制
Get-WindowsFeature -Name NET-*, Web-* | where {$_.Name -notmatch "Ftp|Web-Application-Proxy"} | Install-WindowsFeature

两种购买方式的操作细节我录了个视频

https://cloud.tencent.com/developer/video/34351

0 人点赞