by cristianrg at 2012-09-13 08:33:59
que pregunte al usuario por el nombre de una aplicación del sistema, busque si esta aplicación se esta ejecutando actualmente, y si lo esta, pregunte al usuario si desea parar la aplicación.by DonJ at 2012-09-13 08:38:18
Ejemplo de las impresiones en pantalla del script:
Script para búsqueda de aplicaciones en ejecución Ingrese el nombre de la aplicación :
La aplicación “XXXX†se esta ejecutando en el sistema
¿Desea parar la aplicación? (S/N)
La aplicación “XXXX†ha sido detenida!
I’m sorry, most of us here aren’t fluent in Spanish. Can you try re-posting in English, please?by willsteele at 2012-09-13 08:42:48
Para el autor. Lo siento, la mayorÃa de nosotros no dominan el español. ¿Se puede tratar de volver a publicar en Inglés, por favor? Por favor, trate de usar http://translate.google.com.by willsteele at 2012-09-13 08:53:27
Google translate (http://translate.google.com) gave me this:
prompt the user for the name of a system application, look if this application is currently running, and if so, ask the user to stop the application.
Example of screen printing script:
Script for running applications search Enter the name of the application:
The "XXXX" is running on your system
Want to stop the application? (S / N)
The "XXXX" has been arrested!
Usted tendrá que añadir más lógica para detener una instancia del programa. de lo contrario, este script se detenga todas las instancias de un programa en ejecución. Salà de la WhatIf parámetros para que pueda mostrar lo que sucederÃa si lo utiliza.by DonJ at 2012-09-13 09:12:12
Translation: You will need to add more logic to stop one instance of the program. otherwise, this script will stop all instances of a running program. I left the -WhatIf parameter so it can show you what would happen if you used it.$aplicación = Read-Host -Prompt "Introduzca el nombre de la aplicación"
if(Get-Process -Name $aplicación)
{
"La aplicación"$aplicación
" se esta ejecutando en el sistema"
$desea = Read-Host -Prompt "¿Desea parar la aplicación? (S/N)"
if($desea -eq ‘S’)
{
Stop-Process -Name $aplicación -WhatIf
}
elseif($desea -eq ‘N’)
{
Write-Output "La aplicación"$aplicación
" no fue detenida"
}
}
$app = Read-Host ‘Enter the name of the application’
$procs = Get-Process | Where { $.Name -like "$app" }
if ($procs.count -gt 0) {
Write-Host "$app is running on your system."
$choice = $host.UI.PromptForChoice(‘Want to stop the application?’,‘Choose:’,[system.management.automation.host.choicedescription[]]@(‘&Yes’,‘&No’,2)
if ($choice -eq 0) { Stop-Process $procs }
}
by turbomcp at 2012-09-13 14:59:48pretty coolby poshoholic at 2012-09-13 20:05:22
i learned spanish and something new in powershell at the same time:)
i tried running the above code, seems it was missing a ) after 2)
but even after that showed error$app = Read-Host 'Enter the name of the application'
$procs = Get-Process | Where { $.Name -like "$app" }
if ($procs.count -gt 0) {
Write-Host "$app is running on your system."
$choice = $host.UI.PromptForChoice('Want to stop the application?','Choose]]@('&Yes','&No',2))
if ($choice -eq 0) { Stop-Process $procs }
}
after the prompt for app got this:
Cannot find an overload for "PromptForChoice" and the argument count: "3".
At line:5 char:137
+ … escription]@(‘&Yes’,‘&No’,2))
+ ~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (, MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
You put the missing bracket in the wrong place. Put it before the ",2", not after it, like this:by turbomcp at 2012-09-14 04:18:02$app = Read-Host 'Enter the name of the application'
$procs = Get-Process | Where { $.Name -like "$app" }
if ($procs.count -gt 0) {
Write-Host "$app is running on your system."
$choice = $host.UI.PromptForChoice('Want to stop the application?','Choose]]@('&Yes','&No'),2)
if ($choice -eq 0) { Stop-Process $procs }
}
by turbomcp at 2012-09-14 04:20:07$app = Read-Host 'Enter the name of the application'
$procs = Get-Process | Where { $.Name -like "$app" }
if ($procs.count -gt 0) {
Write-Host "$app is running on your system."
$choice = $host.UI.PromptForChoice('Want to stop the application?','Choose]]@('&Yes','&No'),2)
if ($choice -eq 0) { Stop-Process $procs }
}
when i do that i get this:
Exception calling "PromptForChoice" with "4" argument(s): "Specified argument was out of the range of valid values.
Parameter name: defaultChoice"
At line:5 char:137
+ … escription]@(‘&Yes’,‘&No’),2)
+ ~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (, MethodInvocationException
+ FullyQualifiedErrorId : ArgumentOutOfRangeException
i changed it to 0by poshoholic at 2012-09-14 05:19:02
and it was good to go
Sorry, I did that without running it. I should have just run the script first.
The last integer value is the 0-based index of the button that you want to use as a default. That’s why 2 doesn’t work. 0 will make Yes be the default, and 1 will make No be the default.