question82
Technical User
Hi,
Im writing a script.
This script terminate all process "notepat.exe" in logged owner.
But script must terminate one if hi run.
-----------------------------------------
strComputer = "."
Dim strUserName
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colTel1 = objWMIService.ExecQuery("Select * From Win32_ComputerSystem")
For Each objItem in colTel1
strUserName = objItem.UserName
Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcessByName = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Notepad.exe'")
For Each objProcess in colProcessByName
colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)
If strUserDomain & "\" & strNameOfUser = strUserName Then
objProcess.Terminate()
end if
end if
Next
Im writing a script.
This script terminate all process "notepat.exe" in logged owner.
But script must terminate one if hi run.
-----------------------------------------
strComputer = "."
Dim strUserName
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colTel1 = objWMIService.ExecQuery("Select * From Win32_ComputerSystem")
For Each objItem in colTel1
strUserName = objItem.UserName
Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcessByName = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Notepad.exe'")
For Each objProcess in colProcessByName
colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)
If strUserDomain & "\" & strNameOfUser = strUserName Then
objProcess.Terminate()
end if
end if
Next