"Bryan McCauley" <bryan_m...@reyrey.com> wrote in message
news:023e01c34afa$495e44a0$a301...@phx.gbl...
> I know I must be missing it in the documentation, but I
> can't find it. Is there are way for a VBS script to
> determine its process ID?
>
> There may be multiple wscript.exe running, so I can't
> just look for wscript.exe in the process table. If I was
> running XP, I am running NT, I could use the CommandLine
> Parameter.
A list of alternatives:
Launch the subject script from a generic script using WshShell.Exec or the
WMI process object to get an immediate return. E.g.:
' WshShell.Exec method
set oShell= createObject("wscript.shell")
set oExec= oShell.exec(sCmdLine)
nProcessId= oExec.processId
' WMI per ByRef variable return (version 1)
set oProcess= getobject("winmgmts:!Win32_Process")
nErrRtn= oProcess.create(sCmdLine,sActiveDir,, nProcessId)
' WMI per ByRef variable return (version 2)
sCptrName= "." ' for a local computer
set oWMI= getObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& sCptrName & "\root\cimv2")<br />
set oProcess= oWMI.get("Win32_Process")
nErrRtn= oProcess.create(sCmdLine,sActiveDir,, nProcessId)
Since you already seem to be getting a list of running processes, consider
copying and renaming wscript.exe to something like "specialprocess1.exe".
Then run it as "specialprocess1.exe scriptpathname.vbs". This will enable
you to find it in the list of running processes.
Get a third party utility such as TList.exe, that will give you both the
PIDs and filenames for all wscript processes. (Sorry, don't have the url
handy -- just Google search it. BTW, I haven't used this utility, but am
just passing along prior recommendations.)
Joe Earnest
Sorry, I overlooked that you were running NT. As you note, some of these
alternatives may not be available to you.
Joe Earnest
>.
>
"Bryan McCauley" <bryan_m...@reyrey.com> wrote in message
news:599801c35760$345ccdc0$a001...@phx.gbl...
> Thanks for the input, what I finaly ended up doing was
> executing CMD.EXE via WshShell.Exec which returned an
> WshScriptExec object. One of the Properties of the
> WshScriptExec object is the ProccesID of the command. I
> took that PID and went through WMI until I found the
> matching PID. Once I had the correct WMI object I read
> the ParentProcessID property, which gave me the
> information I was looking for. Finally I terminated the
> CMD.exe via the WshScriptExe.Terminate method.
That's a vaery nice workaround (if somewaht laborious) ;-). Thanks for
posting back. If you don't mind posting the excerpted code someone else
(like me) might find it useful to tuck away for future reference.
Regards,
Joe Earnest