ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

Idea: Task Manager "Lite"

(1/2) > >>

AzureToad:
For various reasons, we dont want to give access to TASKMGR.EXE on server sessions, but there are times when we do want them to be able to end a process that's frozen.

I'd like to present the user a prompt where they could key a username and/or a process name, showing results similar to what's found when TASKLIST is run. The user could then select a process and choose to kill it.

Task manager offers too many opportunities for the user to gain access to the desktop of the server or to run programs we'd rather they not have.

I considered using PowerShell to prompt the user, run tasklist with output to CSV format, then taking that to display to the user and using taskkill.Exe to end the selected program. Unfortunately, I've never written a script even REMOTELY similar to this!

wraith808:
Save to a .ps1 file and run


--- Code: PowerShell ---#Process Killer - allows the user to kill their own processes  #1. Initalize list of processes to exclude$processesToExclude = @(    'conhost', 'dwm', 'explorer', 'rundll32', 'taskhost' ) #2. Get the processes and add the list of processes and owners to the ownerList.$ownerList = @{}$procs = Get-WmiObject -Class Win32_ProcessForEach($proc in $procs){$ownerList[$proc.Handle] = $proc.GetOwner().user} #3. Create the master process list from the information retrieved above$masterProcessList = Get-Process | select processname,Description,Id,@{l="Owner";e={$ownerList[$_.id.tostring()]}} #4. Filter out the processes for the current user$processList = @()ForEach($currentProcess in $masterProcessList){    If($currentProcess.Owner -eq $env:USERNAME)    {        $processList += $currentProcess    }} #5. Show interface with list of processes minus the ones we want to exclude$processList | Where{$_.ProcessName -notin $processesToExclude} | Out-GridView -Title 'Process Killer - Select the process that you want to kill. Select multiple with the Ctrl or Shift key.' -PassThru | ForEach{Stop-Process -id $_.Id}

4wd:
Save to a .ps1 file and run-wraith808 (May 16, 2020, 09:38 PM)
--- End quote ---

Ha!  Spent 90 mins trying to get the output from Get-WmiObject into a ListView ... and gave up :-[

I was going for something using a GUI, still haven't quite worked out getting arrays into a ListView yet.
Idea: Task Manager "Lite"

wraith808:
I cheated.  I'd had to do something like this a while ago, so had the code sitting around.  Just needed to clean it up!

AzureToad:
Save to a .ps1 file and run
--- End quote ---
Holy smoke! This is fabulous - does what I was looking for and... the code... so dang compact!
Very nice, thank you!

I cheated worked smarter, not harder
--- End quote ---
FTFY

Not only got a tool I can use, but got an education as well!
Turned out to be a pretty good Monday.  :P

Enjoy the credit. Credit and half?   :Thmbsup:

Navigation

[0] Message Index

[#] Next page

Go to full version