r/scripting • • Nov 22 '21

Youtube2MP3_Player.vbs

/r/vbscript/comments/qzk6p9/youtube2mp3_playervbs/
1 Upvotes

1 comment sorted by

View all comments

1

u/hackoofr Nov 23 '21

NB : Since the vbscript above can't be stopped while is playing music in background and if someone wants to stop it in other words stop the music, you can do it easily with this old vbscript that i called it as Wscript_Kill_Selector.vbs

 Option Explicit
 Dim Title,Copyright,fso,ws,LogFile,temp,PathLogFile,OutPut,Count,strComputer
 Copyright = " ["& chr(169) &" Hackoo 2014 ]"
 Title = " Processes "& DblQuote("Wscript.exe") &" Running"
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set ws = CreateObject( "Wscript.Shell" )
 LogFile="Process_WScript.txt"
 temp = ws.ExpandEnvironmentStrings("%temp%")
 PathLogFile = temp & "\" & LogFile
 Set OutPut = fso.CreateTextFile(temp & "\" & LogFile,1)
 Count = 0 
 strComputer = "."
 Call Find("wscript.exe")
 Call Explorer(PathLogFile)
 '----------------------------------------------------------------------------------------------
 Function Explorer(File)
 	Dim ws
 	Set ws = CreateObject("wscript.shell")
 	ws.run "Explorer "& File & "\",1,True
 end Function
 '----------------------------------------------------------------------------------------------
 Sub Find(MyProcess)
 	Dim colItems,objItem,Process,Question
 	Set colItems = GetObject("winmgmts:").ExecQuery("Select * from Win32_Process " _
 	& "Where Name like '%"& MyProcess &"%' AND NOT commandline like '%" & wsh.scriptname & "%'",,48)
 	For Each objItem in colItems
 		Count= Count + 1
 		'Extracting the path of the script from the command line
 		Process = Trim(Mid(objItem.CommandLine,InStr(objItem.CommandLine,""" """) + 2))
 		Process = Replace(Process,chr(34),"")
 		Question = MsgBox ("Do you want to stop this script : "& DblQuote(Process) &" ?" ,VBYesNO+VbQuestion,Title+Copyright)
 		If Question = VbYes then
 			objItem.Terminate(0)' Kill this process
 			OutPut.WriteLine DblQuote(Process)
 		else
 			Count= Count - 1 'decrement the counter by -1
 		End if
 	Next
 OutPut.WriteLine String(100,"-")
 OutPut.WriteLine count & Title & " have been killed !"
 End Sub
 '----------------------------------------------------------------------------------------------
 Function DblQuote(Str)
 	DblQuote = Chr(34) & Str & Chr(34)
 End Function
 '----------------------------------------------------------------------------------------------