Code below will run an application and PowerShell will also
close it after a few seconds.
$process_id = Invoke-CimMethod Win32_Process -MethodName "Create" -Arguments @{
CommandLine = 'cmd /c "C:\dev\remind.bat"'} | Select-Object processid | ft -HideTableHeaders | Out-String
Sample contents of remind.bat:
@echo off
echo "Shutdown the server. Do it now."
Notepad
==================
Notepad is on the batch file so the command window will stay
on the top of any running applications.
Sample output of the above code:
Code below will run calculator and close after a few seconds
specified on the code:
Invoke-CimMethod Win32_Process -MethodName "Create" -Arguments @{
CommandLine = 'calc.exe'} | Select-Object processid | ft -HideTableHeaders | Out-String
stop-process -force $get_process_id
Whatever scenario the above code will fit is up to the
creativity.
Cheers..till next time!
Heaven's Dew Fall Prayer app for Android :
https://play.google.com/store/apps/details?id=com.myrosaryapp
Comments
Post a Comment