-
Notifications
You must be signed in to change notification settings - Fork 3
/
W32Winget.cmd
59 lines (49 loc) · 2.35 KB
/
W32Winget.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
@echo off
REM Combined script for installing or uninstalling WinGet applications using Microsoft Intune Win32 apps
REM
REM Instructions:
REM 1. Replace 'YourAppID' with the actual AppID of the WinGet application you want to install or uninstall.
REM Example: SET WingetAppID=Microsoft.VisualStudioCode
REM 2. Run this script with 'install' or 'uninstall' as an argument. If no argument is provided, it defaults to 'install'.
REM Example: W32WingetApp.cmd install
REM Example: W32WingetApp.cmd uninstall
REM
REM Note: It's crucial to follow the correct format for the SET command to ensure the script functions properly.
REM The SET command should not include spaces around the equal sign to avoid creating variables with unintended names or values.
REM
REM
REM The WingetAppID is set at the top for easy access and modification.
SET WingetAppID=YourAppID
REM Set the path to the PowerShell script. Assumes the script is in the current directory.
REM Example: SET PowerShellScriptPath=C:\Scripts\Install_WingetApp.ps1
SET PowerShellScriptPath=.\Install_WingetApp.ps1
REM Check for command line argument (install or uninstall)
IF "%1"=="" GOTO Install
IF /I "%1"=="install" GOTO Install
IF /I "%1"=="uninstall" GOTO Uninstall
GOTO InvalidArgument
:Install
REM Execute the PowerShell script for installation.
%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "%PowerShellScriptPath%" -WingetAppID "%WingetAppID%"
REM Check for errors and exit with the error code if an error occurred.
IF %ERRORLEVEL% NEQ 0 (
echo Installation of %WingetAppID% failed with error code %ERRORLEVEL%.
exit /b %ERRORLEVEL%
)
REM Success message for installation.
echo Installation of %WingetAppID% completed successfully.
exit /b 0
:Uninstall
REM Execute the PowerShell script for uninstallation.
%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "%PowerShellScriptPath%" -WingetAppID "%WingetAppID%" -Uninstall
REM Check for errors and exit with the error code if an error occurred.
IF %ERRORLEVEL% NEQ 0 (
echo Uninstallation of %WingetAppID% failed with error code %ERRORLEVEL%.
exit /b %ERRORLEVEL%
)
REM Success message for uninstallation.
echo Uninstallation of %WingetAppID% completed successfully.
exit /b 0
:InvalidArgument
echo Invalid argument. Please use 'install' or 'uninstall'.
exit /b 1