Stop and then start a process in powershell -
i stop/kill process , start again after done doing have do.
this have.
clear-host $processes = get-process devenv $processes.count if($processes.count -gt 1) { $i = 0 write-host "there multiple processes devenv." foreach($process in $processes) { $i++ $i.tostring() + '. ' + $process.mainwindowtitle } $in = read-host "give number of process kill: " write-host write-host "killing , restarting: " + $processes[$in-1].mainwindowtitle $processes[$in-1].kill() $processes[$in-1].waitforexit() $processes[$in-1].start() } else { write-host "something else" }
but start needs parameter thought process. i'm not sure know give it.
the $processes[$in-1].start()
not work. need capture processinfo killing , start same app again. can process binary , commandline information using win32_process wmi class.
for example,
clear-host $processes = get-process notepad $processes.count if($processes.count -gt 1) { $i = 0 write-host "there multiple processes notepad." foreach($process in $processes) { $i++ $i.tostring() + '. ' + $process.mainwindowtitle } $in = read-host "give number of process kill: " write-host write-host "killing , restarting: " + $processes[$in-1].mainwindowtitle #get process details $procid = $processes[$in-1].id $cmdline = (get-wmiobject win32_process -filter "handle=$procid").commandline $processes[$in-1].kill() $processes[$in-1].waitforexit() }
in above example, using wmi commandline information process selected. if notepad process open text file, commandline process "c:\windows\system32\notepad.exe" c:\users\ravikanth_chaganti\desktop\debug.log
now, need is: invoke commandline somehow (this part not there in example wrote). blunt way is:
start-process -filepath $cmdline.split(' ')[0] -argumentlist $cmdline.split(' ')[1]
but, in case, there may not argument list.
hope gives idea. other powershell experts may have different & efficient approach. quick hack.
Comments
Post a Comment