Open farzinmonsef opened 6 years ago
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; using System.Runtime.InteropServices;
namespace CloseApp { class Program { [DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
/// <summary>
/// Find window by Caption only. Note you must pass IntPtr.Zero as the first parameter.
/// </summary>
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
const UInt32 WM_CLOSE = 0x0010;
static void Main1(string[] args)
{
//IntPtr windowPtr = FindWindowByCaption(IntPtr.Zero, "Untitled - Notepad");
//if (windowPtr == IntPtr.Zero)
//{
string AppName = "MicrosoftEdge";// "notepad";
var prc = Process.GetProcessesByName(AppName);// "MicrosoftEdge");
if (prc.Length == 0)
{
Console.WriteLine("Window not found");
Console.WriteLine("Press Any Key to End=>");
Console.ReadKey();
return;
}
SendMessage(((IntPtr)prc[0].MainWindowHandle), WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
Console.WriteLine("Press Any Key to End =>");
Console.ReadKey();
}
static void Main(string[] args)
{
foreach (Process p in Process.GetProcessesByName("MicrosoftEdge"))
{
p.Kill();
//p.CloseMainWindow();
}
}
static void Main2(string[] args)
{
var prc = Process.GetProcessesByName("notepad");
if (prc.Length > 0)
{
SetForegroundWindow(prc[0].MainWindowHandle);
}
}
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
@echo OFF rem @echo. rem @echo Date is %Date% SET DayOfWeek=%Date:~0,3% SET Day=%Date:~7,2% SET Month=%Date:~4,2% SET Year=%Date:~10,4% SET Today=%Date:~10,4%-%Date:~4,2%-%Date:~7,2% rem @echo Year is %Year%, Month is %Month%, Day is %Day%, DayOfWeek is %DayOfWeek% @echo Today is %Today%
C:\Work\Bak\CloseApp
"C:\Program Files (x86)\Tanium\Tanium Client\Tools\IR\7za" a -tzip "c:\work\bak\Edg%Today%.zip" "C:\Users\U612702\AppData\Local\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\AC\MicrosoftEdge\User\Default\DataStore\Data\nouser1\120712-0049*.*" -r
C:\Work\Bak\Dummy.htm @echo.
Killing Browser Edge Internet Explorer Process
For Backup or else