VBS Help - I know I know

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

VBS Help - I know I know

#1 Post by SIMMS7400 » 18 Apr 2017 13:29

Hi Folks -

Having trouble getting VBS help so figured I'd ask here since I'm sure some of you have used/currently work with it.

I have need to write a VBS script that does the following:

1. Kills a cmd process with a specific title
2. Start a cmd SILENTLY with a specific title


I have bits and pieces of this code but unable to peice it together:

Kills with specific title:

Code: Select all

Option Explicit
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "CMD /C taskkill /f /fi ""WINDOWTITLE eq  GJA_PROCESS"" & exit"


Starts with specific title:

Code: Select all

Set objShell = CreateObject("Wscript.Shell") 
 objShell.Run _
 ("%comspec% /C title GJA_PROCESS|C:\Users\user\Documents\zz.cmd"), _
 1, TRUE
 


Need to start silently though....

Which is this:

Code: Select all

Set WshShell = CreateObject("WScript.Shell")   
 WshShell.Run chr(34) & "C:\Users\user\Documents\zz.cmd" & Chr(34), 0 
 Set WshShell = Nothing


Thanks!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: VBS Help - I know I know

#2 Post by aGerman » 18 Apr 2017 15:55

The wanted behavior is still not clear to me. Try ...

Code: Select all

objShell.Run "%comspec% /c ""taskkill /f /fi ""WINDOWTITLE eq  GJA_PROCESS""""", 0
...and...

Code: Select all

objShell.Run "%comspec% /c ""title GJA_PROCESS|C:\Users\user\Documents\zz.cmd""", 0

Steffen

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: VBS Help - I know I know

#3 Post by ShadowThief » 18 Apr 2017 16:11

This is screaming XY Problem, especially based on your previous threads. What are you trying to accomplish?

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: VBS Help - I know I know

#4 Post by SIMMS7400 » 18 Apr 2017 17:59

Hi Both -

Thank you for your replies.

I've been able to meet my needs combing both into 1 line:

Code: Select all

Set objShell = CreateObject("WScript.Shell")
objShell.Run "CMD /C taskkill /f /fi ""WINDOWTITLE eq Administrator:  GJA_PROCESS"" & C:\Hyperion_Batch\zz.cmd GJA_PROCESS",0
Set objShell = Nothing


Thank you!

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: VBS Help - I know I know

#5 Post by SIMMS7400 » 18 Apr 2017 18:34

Last question, is there a way to include variable in this?

Code: Select all

Set objShell = CreateObject("WScript.Shell")
objShell.Run "CMD /C taskkill /f /fi ""WINDOWTITLE eq Administrator:  GJA_PROCESS"" & C:\Hyperion_Batch\Scripts\Batch\zz.cmd GJA_PROCESS",0
Set objShell = Nothing


I want to do something like :

Code: Select all

Dim VAR1
VAR1 = GJA_PROCESS

Set objShell = CreateObject("WScript.Shell")
objShell.Run "CMD /C taskkill /f /fi ""WINDOWTITLE eq Administrator:  VAR1"" & C:\Hyperion_Batch\Scripts\Batch\zz.cmd VAR1",0
Set objShell = Nothing


But having difficulty.

Thanks!

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: VBS Help - I know I know

#6 Post by ShadowThief » 18 Apr 2017 18:46

You may have to do regular string concatenation, which is going to look something like (and I'm just sort of winging it here, so this is untested):

Code: Select all

objShell.Run "CMD /C taskkill /f /fi ""WINDOWTITLE eq Administrator:  " & VAR1 & """ & C:\Hyperion_Batch\Scripts\Batch\zz.cmd " & VAR1,0

Post Reply