Page 1 of 1

Get Funky ASCII ART with Colors and Playing music in the background for introduction animation

Posted: 14 Sep 2022 02:00
by Hackoo
I made this Hybrid Script [Batch/Powershell] with the help from other sources on the Net that can make some animation introduction with ASCII ART with Colors, but some users who test it on their computer say to me that the music doesn't play ?? I don't know why, perhpas security issues ?
My OS is Windows 10 (64bits) French Edition : GetFunky_ASCII_ART_Colors.bat

Code: Select all

<# : batch script section , Don't Delete This Line.
@rem # The previous line does nothing in Batch, but begins a multiline comment block in PowerShell. This allows a single script to be executed by both interpreters.
@echo off
Title Get Funky ASCII ART with Colors and Playing music in the background by Hackoo 2022
setlocal
cd "%~dp0"
Color 0B & echo(
Echo( This ASCII ART with playing music in the background is interpreted with powershell command ....
Powershell -executionpolicy bypass -Command "Invoke-Expression $([System.IO.File]::ReadAllText('%~f0'))"
EndLocal
@rem # Here you can put other Commands in batch
cls & Echo( Those are another examples of commands with Batch like ping and ipconfig /all and so on ....
Timeout /T 1 /NoBreak>nul
Ping www.google.com
echo( & Ipconfig /all & pause
goto:eof 
#>
# here write your powershell commands...
###################################################################################################################
# https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/listening-to-music-in-the-background
###################################################################################################################
function Start-Music
{
  $code = {
    $player = New-Object -ComObject 'MediaPlayer.MediaPlayer'
    $player.Open('http://www.leeholmes.com/projects/ps_html5/background.mp3')
    $player
  }

  $script:ps = [PowerShell]::Create()
  $script:player = @($ps.AddScript($code).Invoke())[0]
}

function Stop-Music
{
  if ($script:player -ne $null)
  {
    $script:player.Stop()
    Remove-Variable -Name player -Scope script
  }
  if ($script:ps -ne $null)
  {
    $script:ps.Runspace.Close()
    $script:ps.Dispose()
    Remove-Variable -Name ps -Scope script
  }
}
###############################################
# https://stackoverflow.com/a/35022366/3080770
###############################################
function Get-Funky{
    param([string]$Text)

    # Use a random colour for each character
    $Text.ToCharArray() | ForEach-Object{
        switch -Regex ($_){
            # Ignore new line characters
            "`r"{
                break
            }
            # Start a new line
            "`n"{
                Write-Host " ";break
            }
            # Use random colours for displaying this non-space character
            "[^ ]"{
                # Splat the colours to write-host
                $writeHostOptions = @{
                    ForegroundColor = ([system.enum]::GetValues([system.consolecolor])) | get-random
                    # BackgroundColor = ([system.enum]::GetValues([system.consolecolor])) | get-random
                    NoNewLine = $true
                }
                Write-Host $_ @writeHostOptions
                break
            }
            " "{Write-Host " " -NoNewline}

        } 
    }
}

Start-Music

$text = @"
  ___          __                                 _    _               
 |_ _| _ __   / _|  ___   _ __  _ __ ___    __ _ | |_ (_)  ___   _ __  
  | | | '_ \ | |_  / _ \ | '__|| '_ ` _ \  / _` || __|| | / _ \ | '_ \ 
  | | | | | ||  _|| (_) || |   | | | | | || (_| || |_ | || (_) || | | |
 |___||_| |_||_|   \___/ |_|   |_| |_| |_| \__,_| \__||_| \___/ |_| |_|
                                                                       
             ,----------------,              ,---------,
        ,-----------------------,          ,"        ,"|
      ,"                      ,"|        ,"        ,"  |
     +-----------------------+  |      ,"        ,"    |
     |  .-----------------.  |  |     +---------+      |
     |  |                 |  |  |     | -==----'|      |
     |  |  I LOVE DOS!    |  |  |     |         |      |
     |  |  Bad command or |  |  |/----|`---=    |      |
     |  |  C:\>_          |  |  |   ,/|==== ooo |      ;
     |  |                 |  |  |  // |(((( [33]|    ,"
     |  `-----------------'  |," .;'| |((((     |  ,"
     +-----------------------+  ;;  | |         |,"
        /_)______________(_/  //'   | +---------+
   ___________________________/___  `,
  /  oooooooooooooooo  .o.  oooo /,   \,"-----------
 / ==ooooooooooooooo==.o.  ooo= //   ,`\--{)B     ,"
/_==__==========__==_ooo__ooo=_/'   /___________,"
`-----------------------------'


            ###################-:,.......,,,,-:-,,,,,..,,,,,--,,.......,:;################## 
            ##################:-......,--,,.-;+@#######;,,,,,,,,--,......-:################# 
            ################:-......,-,,,,,-#######H##HH#,,,,,,,,,,-,......-:############### 
            ###############:-.....,-,,,,,-:*@H#########HHH,,,,,,,,,,,-,.....,:############## 
            ##############:,....,,,,,,,,:+@@#H######HHH###;,,,,,,,,,,,,-,....,:############# 
            #############:,....,,...,,,,--+#@*;::-----,:##+,,,,,,,,,,,,,--.....:############ 
            ############:.....-.........,:##++++:::::---+#+,,,,,,,,,,,,----.....:########### 
            ###########:,....-.,........,*#@+++;::::----;#+,,,,,,,,,,,,---,-....,:########## 
            ##########:,....,.........,,,*#+*@*@@*-;*+;::#-,,,,--,,.,,,---.,-....,:######### 
            ######### -....-........,,,,.+#+****@@;-+*++:@,,,,,-----,,,---,,,-....-:######## 
            #########:....,,,.....,,,,,,-*+***+*@@;----::*,,,,,-----------,-,-,....:######## 
            ########;-....-,,..,,,,,,,,,:*+:@*****+;:-:::+,,,,,,---------------....--####### 
            ########:,...,,,,,,,,,,,,,,..+@;@**@*+;::;::;-,...,,,,------------,,....:####### 
            ########:....-,,,,,,,,,,,.... -@*****+;:-::;-......,,,-----------,.-....-####### 
            #######:-...,,,,,,,,,,,...   ..-@**@####*:;-......,,,,,,-------,,,.,....--###### 
            #######:,...,,,,,,,,,,,,,,,,,..,****+;;:::;.....,,,,,,,,,-----,,,,,,,...,:###### 
            #######:,...-,,,,,,,,,,,,,,....,*****+;:::;;,,.,,,,,,,,,-,,,,,,,,,,,-....:###### 
            #######:....-..,,,,,,,.........,*+**+;::::-#H-............,,,,,,,,..-....:###### 
            #######:....-..,,,,,,.......,:.+;;++++;::;-;##H+:-........,,,,,,--,,-....:###### 
            #######:,...-..,,,,,,...,-;+;:,*;*+++*+;;;.:###H##H@+:-....,,,,,-----....:###### 
            #######:,...,..,,,,,.,,:@####-::**++;@**: .:###;;#######@;,,,,,,----,...,:###### 
            #######:-....,.,,,,-:+#######.:.*+++:@@-. ,-:+H+:###########,,,,,---....-:###### 
            ########:....-.,,;*@#########.:.****+;....+;+:,-:;##########H.,,,---....-####### 
            ########:,...,,,-############,,,-;++:,...;#-,:;:,,###########-,...-,....:####### 
            ########+-....-,+#############@+;::;+;++*###;:,,:,@####H#####-,..,-....--####### 
            #########:,...,,##############H*;- -+++;;*H#@**;,--##########,...,.....:######## 
            ######### -....,H#############H@+-.:++;;;+@+-----,,##H#######...,,....-:######## 
            ##########:,....:##############@+-.::;;;;*H##+*:,,,#H#######*..,,....,:######### 
            ###########:,....:#############*;-,,::;;+@###@*;:,,#########:..,.....:########## 
            ############:,....-H###########*:;:;;;+*@#H###+:+,,-H#######+,,.....-:########## 
            #############:,....,@##########@;::;+****@H####;+-,:#HH#####+,.....--########### 
            ##############:,.....:H#########+;++***++*H#######H#H#HH##H:......--############ 
            ###############:-.....,+H#######@;+++;:::;@####H###+HHHH#;.......-:############# 
            ################:-,.....,;#####H@:+;:-::;;*H####*#**##*:........-:############## 
            ##################:-.......-+###*;+::;;*#H#######*#+;,.........-:############### 
            ###################+:-........,-:;:;+++++*@H##H#+-,..........,:################# 
            #####################+:-,...........,,,,,,,,,...............-:################## 
			
"@

Get-Funky $text
#####################################################################################################################
# https://adamtheautomator.com/powershell-pause/#Thread_Sleep
#####################################################################################################################
cmd /C 'echo/ & echo( You can stop and skip the introduction animation and go directly to execute batch commands by typing any key ... & Timeout /T 50>nul'
Stop-Music
What should i modify to this script to let the music play correctly ?
Thank you !

Re: Get Funky ASCII ART with Colors and Playing music in the background for introduction animation

Posted: 14 Sep 2022 09:49
by aGerman
I tried ...

Code: Select all

Powershell -version 2 -executionpolicy bypass -Command ...
...in order to figure out if the code is backward compatible. Since this is the case I also guess security settings could be the culprit. You should ask the users what kind of error message they get.

Steffen

Re: Get Funky ASCII ART with Colors and Playing music in the background for introduction animation

Posted: 14 Sep 2022 11:29
by miskox
Works for me. Rick Astley...

Code: Select all

 INFO.BAT version 1.6
--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Version 10.0.19044.1288]
Product name           :  Windows 10 Home, 64 bit
Performance indicators :  Processor Cores: 2      Visible RAM: 7830700 kilobytes

Date/Time format       :  (dd/mm/yy)  sre. 14. 09. 2022  19:29:23,71
__APPDIR__             :  C:\Windows\SysWOW64\
ComSpec                :  C:\Windows\system32\cmd.exe
PathExt                :  .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
Extensions             :  system: Enabled   user: Disabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  sl-SI       Code Pages: OEM  852    ANSI 1250
DIR  format            :  12. 09. 2022  21:19     1.946.157.056 pagefile.sys
Permissions            :  Elevated Admin=No, Admin group=Yes

                          Missing from the PATH environment: C:\Windows\SysWOW64\wbem
                          Missing from the PATH environment: C:\Windows\SysWOW64\WindowsPowerShell\v1.0
                          Missing from the tool collection:  debug


Saso

Re: Get Funky ASCII ART with Colors and Playing music in the background for introduction animation

Posted: 23 Sep 2022 22:32
by batmanbatmanbatmen
Troubleshoot is difficult. Check the stupid issue first. Make sure, speak ok, mediaplayer install, administrator authority, version, patch, antivirus, .....
Anyway, I want to say your coding is good and interesting. However, for me, I will only use dos cmd only to avoid powershell or any uncontrol issue. Draw ASCII art with color, play music, all can be done by dos cmd only. No need powershell. :wink: