Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Task Kill not running

Status
Not open for further replies.

Nu2Java

Technical User
Jun 5, 2012
166
US
I have a simple script here where I am just matching two inputbox values. I am playing a buzzer sound with windows media player if they do not match and then I am attempting to kill the player after it plays and then return to my script. I have tried putting the task kill in several spots but with no luck. If I kill it manually, my script comes back as it should. Any thoughts?

Code:
Dim PartA, PartB
set WshShell = CreateObject("WScript.Shell")

Scan = True

Do While Scan
PartA = UCase(InputBox("Scan Part Number Barcode on REEL: "))

PartB = UCase(InputBox("Scan Part Number Barcode on BIN: "))

If PartA = PartB Then
WshShell.Run "%comspec% /c echo " & Chr(7), 0, False
Wscript.Sleep 300

Else
Scan = False
music = "C:\Scripts\DoorBuzzer.mp3"
WshShell.Run "wmplayer """ & music & """",0,True
Wscript.Sleep 2500
WshShell.Run "taskkill /f /im wmplayer.exe", 0, True
Scan = True
End If

Loop
 
I had a similar requirement and used NirCMD's mediaplay command to save the overhead of opening then closing media player.

Hope this helps...
 
Hi [peace]
Try this code and modifiy it for your purpose [2thumbsup]

Code:
Option Explicit
Dim MySound1,MySound2,WshShell,scan
Dim PartA, PartB
set WshShell = CreateObject("WScript.Shell")
Do
	PartA = UCase(InputBox("Scan Part Number Barcode on REEL: ","Scan Part Number Barcode on REEL"))
	If PartA = "" Then Wscript.Quit
	PartB = UCase(InputBox("Scan Part Number Barcode on BIN: ","Scan Part Number Barcode on BIN"))
	If PartB = "" Then Wscript.Quit
	If PartA = PartB Then
		WshShell.Run "%comspec% /c echo " & Chr(7), 0, False
		Pause 1
	Else
		MySound1 = "[URL unfurl="true"]http://soundjay.com/mechanical/bomb-falling-and-exploding-01.mp3"[/URL]
		MySound2 = "[URL unfurl="true"]http://soundbible.com/mp3/Evil_laugh_Male_9-Himan-1598312646.mp3"[/URL]
		Call Kill("wmplayer.exe") 'We ensure to kill the Wmplayer.exe before
		Call WmPlaySound(MySound1)
		Pause 10
		Call Kill("wmplayer.exe")
		Call WmPlaySound(MySound2)
		Pause 6
		Call Kill("wmplayer.exe")
	End If
Loop 
'*********************************************************************************************
	Sub WmPlaySound(MySound)
		Dim WshShell
		Set WshShell = CreateObject("WScript.Shell")
		WshShell.Run "wmplayer  "& DblQuote(MySound) &"",0,False
		Set WshShell = Nothing
	End Sub
'**********************************************************************************************
'Function to add double quotes in a variable
	Function DblQuote(Str)
		DblQuote = Chr(34) & Str & Chr(34)
	End Function
'**********************************************************************************************
	Sub Kill(Process)
		Dim Ws,Command,Execution
		Set Ws = CreateObject("WScript.Shell")
		Command = "cmd /c Taskkill /F /IM "&Process&""
		Execution = Ws.Run(Command,0,True)
	End Sub
'**********************************************************************************************
	Sub Pause(NSeconds)
		Wscript.Sleep(NSeconds*1000)
	End Sub  
'**********************************************************************************************
 
Crackoo... Thanks for the code. This works GREAT!! Exactly what I needed.

Rick998... Thanks for your reply. I will have a look at the nirCMD's as I have not heard of that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top