all possible to have it read from a list of computers instead of hard coding?
Please assist. So what I am looking for is to pull the current domain and user
name, then search for the current user and once found from a server.txt file, it
would then kill that users winword.exe application.
Current VB Script
---------------------
option explicit
'
' Kill all
processes by the name of strProcessName running under the current user
'
dim strComputer,strProcessName, strOwner, strUserName
dim objWMI,
objNetwork, colProcesses, dummy, objProcess
strComputer = "."
strProcessName = "winword.exe"
set objWMI =
GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set
objNetwork = CreateObject("WScript.Network")
set colProcesses =
objWMI.ExecQuery("Select * from Win32_Process Where Name = '"&
strProcessName & "'")
strUserName = objNetwork.UserName
for
each objProcess in colProcesses
dummy = objProcess.GetOwner(strOwner)
if (strOwner = strUserName) then
objProcess.Terminate()
end if
next
set objWMI = nothing
set objNetwork = nothing
set objProcess
Yes you can read from a file or an array.
Start here:http://technet.microsoft.com/library/ee176977.aspx
I have tried, but for some odd reason, it will not work for reading from the text file. Here is what I have;
dim strComputer,strProcessName, strOwner, strUserName
dim objWMI, objNetwork, colProcesses, dummy, objProcess
arrComputers = Array("radfa0211v10317", radfa0211v10318", radfa0211v10319", radfa0211v10320", radfa0211v10321", radfa0211v10322", radfa0211v10323", radfa0211v10324", radfa0211v10325", radfb9211V69561")
for i = 0 to UBound(arrComputers)-1
strProcessName = "winword.exe"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
if i mod 2 = 0 Then
strComputer = arrComputers(i)
set colProcesses = objWMI.ExecQuery("Select * from Win32_Process Where Name = '"& strProcessName & "'")
strUserName = objNetwork.UserName
for each objProcess in colProcesses
dummy = objProcess.GetOwner(strOwner)
if (strOwner = strUserName) then
objProcess.Terminate()
end if
next
set objWMI = nothing
set objNetwork = nothing
set objProcess = nothing
Here is a short example that demonstrates how to read text from a file in a VBScript script:
Bill,
Could you assist in creating this for me if at all possible?
Thanks!!!
Hi,
Sorry, but I just don't have the resources to write scripts on demand for free.
If you're not familiar with VBScript, I recommend the primer in the Windows 2000 Scripting Guide.
Rather than VBScript, I would recommend PowerShell. You can do more in less code with PowerShell and there are plenty of learning resources to help you get started (for example, the Learn link right at the top of this forum).
Bill
I want to try to get a powershell script to list the current process by the current user. Please assist.
Than
Then kill a process for the current user
Hi Imossolle,
You can't get the process for the current user in both Powershell V2 and V 3.
but YES
in PowerShell V 4.0 it is possible becouse it has a new switch parameter, IncludeUserName.
otherwise , You have Get-process and Stop-Process to use in Powershell V2 and V 3.
http://technet.microsoft.com/en-us/library/hh857339.aspx => new features in PowerShell V 4.0
yes it will work
get-process winword|stop-process
Get-process will show all process running in your Computer but you won't able to see the user name in PS V3 or V 2. but in PS V 4 you can.
Tarique I have a VB Script, for current user, but it is not working properly. do you see something wrong with it?
option explicit
'
' Kill all processes by the name of strProcessName running under the current user
'
dim arrComputers,strProcessName, strOwner, strUserName
dim objWMI, objNetwork, colProcesses, dummy, objProcess
strComputer = "."
strProcessName = "winword.exe"
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set objNetwork = CreateObject("WScript.Network")
set colProcesses = objWMI.ExecQuery("Select * from Win32_Process Where Name = '"& strProcessName & "'")
strUserName = objNetwork.UserName
for each objProcess in colProcesses
dummy = objProcess.GetOwner(strOwner)
if (strOwner = strUserName) then
objProcess.Terminate()
end if
next
Sorry , I don't know VB script ......... I am really sorry.....
So if I wanted to kill only my current winword process only for me, with v 3.0, it will
Ah yes - it is very frustrating because Admins do not know Windows Insides at all. Even most programmers to day do not truly understand how Windows works.
The method is as old as NT. Get the users sessio0n and get Explorer. You can then list all process whose parent is the Explorere you have found. NOt just filter on the process you want to kill.
Method #2:
Get all copies of WinWord.Exe then check the owner of the parent process.
Current user is easy on a WorkStation. It is much more ambiguous on a Terminal Server.
On a workstation the console user is:
gwmi win32_computersystem | select username -computer somepc
option explicit ' ' Kill all processes by the name of strProcessName running under the current user ' dim strComputer,strProcessName, strOwner, strUserName dim objWMI, objNetwork, colProcesses, dummy, objProcess strComputer = WScript.Arguments(0) 'strComputer = WScript.Arguments WScript.Echo "Running Against Remote Computer Named: " & strComputer Dim oShell Dim UserName Set oShell = Wscript.CreateObject("Wscript.Shell") UserName = oShell.ExpandEnvironmentStrings("%USERNAME%") WScript.Echo "Looking for Microsoft Word for the following loged in user: " & UserName strProcessName = "WINWORD.EXE" set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objNetwork = CreateObject("WScript.Network") set colProcesses = objWMI.ExecQuery("Select * from Win32_Process Where Name = '"& strProcessName & "'") strUserName = objNetwork.UserName for each objProcess in colProcesses dummy = objProcess.GetOwner(strOwner) if (strOwner = strUserName) then objProcess.Terminate() end if next set objWMI = nothing set objNetwork = nothing set objProcess = nothing
The following will get the current users process within powershell without requiring elevation. The '-includeusername' parameter of Get-Process requires elevation.
&tasklist/FI"USERNAME eq $Env:UserDomain\$env:Username"
- Edited by Joshua Custance 15 hours 32 minutes ago
The following will get the current users process within powershell without requiring elevation. The '-includeusername' parameter of Get-Process requires elevation.
&tasklist/FI"USERNAME eq $Env:UserDomain\$env:Username"
- Edited by Joshua Custance Sunday, February 08, 2015 7:59 PM