Solved

How do i get a vbscript to show up with a certain process name in task manager?

Posted on 2010-09-15
7
451 Views
Last Modified: 2012-05-10
I come from shell scripting and any time i run a shell script i can see the name of the script when I search for processes running on my linux box, but for a vbscript is shows up as wscript.exe. How can i start a vbscript name rather than it just showing up as wscript.exe?
0
Comment
Question by:Geeko80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 
LVL 13

Expert Comment

by:Daz_1234
ID: 33689619
Hi Geeko80,

You don't say what OS you are using, but assuming it is at least XP then the following command will show you all the vbscript processes running (run in Cmd.exe window):


wmic process get commandline | find /i "wscript.exe"

... or ...

wmic process get commandline | find /i "cscript.exe"

... or even ...

wmic process get commandline | find /i "script.exe"

... you get the idea :o)

Hope this helps,
Daz.
0
 
LVL 13

Expert Comment

by:Daz_1234
ID: 33689674


... Since you originally asked for VBScript, the code below will show a message box showing all WScript.exe and CScript.exe processes.

Regards,
Daz.
'# D.Collins - 09:55 16/09/2010
'# Search for WScript.exe and CScript.exe processes on the local machine

Option Explicit

Dim strProc

strProc = fGetCommandLines("WScript.exe")
strProc = strProc & fGetCommandLines("CScript.exe")

MsgBox strProc,, "WSH Processes:"



Function fGetCommandLines(sPattern)
    Dim oWMIService, colProcesses, strProcesses, oProcess, blTemp
    Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set colProcesses = oWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & sPattern & "'")

    strProcesses = ""
    For Each oProcess in colProcesses
        strProcesses = strProcesses & oProcess.CommandLine & vbCrlf
    Next
    If strProcesses = "" Then strProcesses = "No Processes with '" & sPattern & "' found."

    fGetCommandLines = strProcesses
End Function

Open in new window

0
 

Author Comment

by:Geeko80
ID: 33694097
Hello, Sorry I wasnt clear.

I am running Windows XP.

I meant to ask how I can get a vbscript to show up with a name of my choosing in task manager rather than just wscript.exe. Can that be coded?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:Daz_1234
ID: 33700743
You would probably have to write your own task manager application.

The only way I can think of to change the 'WScript.exe' showing in the built-in Task Manager would be to copy WScript.exe and rename it to something else, then call your vbscript with the copied .exe, for example:

1. Copy WScript.exe and rename the copy to Superscript.exe
2. Run:  Superscript.exe yourscript.vbs


Regards,
Daz.

tm.jpg
0
 
LVL 13

Accepted Solution

by:
Daz_1234 earned 500 total points
ID: 33702085
I've been having a little play with this ...

Save the script below as .vbs and run it.

It basically, on the fly, copies either cscript.exe or wscript.exe depending on what the script was called with, to %temp% and calls it with itself as a parameter.

Here's the logic flow, imagine the script is called 'folderrefresh.vbs' and you ran it with wscript.exe:

1. copy wscript.exe to %temp%\folderrefresh.vbs.exe
2. execute folderrefresh.vbs.exe folderrefresh.vbs
3. exit

The script will leave the exe in the %temp% as it can't cleanup after itself.

Regards,
Daz.


'# Put this If ... End If block at the start of your script
If InStr(1, WScript.FullName, "wscript.exe", 1) <> 0 Then
    CallSelf("wscript.exe")
    WScript.Quit
ElseIf InStr(1, WScript.FullName, "cscript.exe", 1) <> 0 Then
    CallSelf("cscript.exe")
    WScript.Quit
End If



MsgBox "Check Task Manager for '" & WScript.ScriptName & ".exe'"


'# Put this Sub at the end of your script (or anywhere you want).
Sub CallSelf(sEnv)
    Dim wshShell, fso, sTmp, sWindir, sNewExe
    Set wshShell = CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    sTmp = wshShell.ExpandEnvironmentStrings("%temp%")
    sWindir = wshShell.ExpandEnvironmentStrings("%WINDIR%")
    sNewExe = Replace(sTmp & "\" & WScript.ScriptName & ".exe", " ", "_")
    fso.CopyFile sWindir & "\System32\" & sEnv, sNewExe
    wshShell.Run sNewExe & " " & WScript.ScriptFullName, 1, False
End Sub

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34986409
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question