-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMushLog.bat
More file actions
46 lines (38 loc) · 1.47 KB
/
Copy pathMushLog.bat
File metadata and controls
46 lines (38 loc) · 1.47 KB
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
@echo off
setlocal
REM Define paths and filenames
set "EXENAME=MushLog.exe"
set "EXEDIR=%~dp0"
set "ICONREL=_internal\resources\mushroom_icon.ico"
set "ICONFULL=%EXEDIR%%ICONREL%"
set "PSTEMP=%TEMP%\create_shortcut_temp.ps1"
REM Clean up any old version first
if exist "%PSTEMP%" del "%PSTEMP%"
REM Use echo. instead of echo (flush-safe) and write the PowerShell script line by line
call :WriteLine "$exePath = '%EXEDIR%%EXENAME%'" >> "%PSTEMP%"
call :WriteLine "$iconPath = '%ICONFULL%'" >> "%PSTEMP%"
call :WriteLine "$desktop = [Environment]::GetFolderPath('Desktop')" >> "%PSTEMP%"
call :WriteLine "$shortcutPath = Join-Path $desktop 'MushLog.lnk'" >> "%PSTEMP%"
call :WriteLine "$WScriptShell = New-Object -ComObject WScript.Shell" >> "%PSTEMP%"
call :WriteLine "$shortcut = $WScriptShell.CreateShortcut($shortcutPath)" >> "%PSTEMP%"
call :WriteLine "$shortcut.TargetPath = $exePath" >> "%PSTEMP%"
call :WriteLine "$shortcut.WorkingDirectory = '%EXEDIR%'" >> "%PSTEMP%"
call :WriteLine "$shortcut.IconLocation = $iconPath" >> "%PSTEMP%"
call :WriteLine "$shortcut.Save()" >> "%PSTEMP%"
call :WriteLine "Write-Host 'Shortcut created:' $shortcutPath -ForegroundColor Green" >> "%PSTEMP%"
REM Double check file exists
if not exist "%PSTEMP%" (
echo Failed to create the PowerShell script: %PSTEMP%
pause
exit /b 1
)
REM Run it
powershell -ExecutionPolicy Bypass -NoProfile -File "%PSTEMP%"
REM Clean up
del "%PSTEMP%" >nul 2>&1
endlocal
pause
exit /b 0
:WriteLine
echo %~1
exit /b