Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- @echo off && cls
- set WinDirNet=%WinDir%\Microsoft.NET\Framework
- IF EXIST "%WinDirNet%\v4.0.30319\csc.exe" set csc="%WinDirNet%\v4.0.30319\csc.exe"
- IF EXIST "%WinDirNet%\v3.5\csc.exe" set csc="%WinDirNet%\v3.5\csc.exe"
- IF EXIST "%WinDirNet%\v2.0.50727\csc.exe" set csc="%WinDirNet%\v2.0.50727\csc.exe"
- %csc% /nologo /out:"%~0.exe" %0
- "%~0.exe"
- del "%~0.exe"
- exit
- */
- using System;
- using Microsoft.Win32;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- using System.Threading;
- namespace SkypeRun
- {
- class Program
- {
- const string RegPath = @"Software\Skype\Phone";
- const string WindowClassName = "THomeForm";
- #region Import
- [DllImport("user32.dll", SetLastError = true)]
- static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- public static extern bool IsWindowVisible(IntPtr hWnd);
- [DllImport("user32.dll")]
- static extern int SendMessage(
- IntPtr hWnd, // handle to destination window
- uint Msg, // message
- long wParam, // first message parameter
- long lParam // second message parameter
- );
- const uint WM_CLOSE = 0x0010;
- #endregion
- public static void Main(string[] args)
- {
- string path = GetSkypePath();
- Process proc = Process.Start(path);
- IntPtr wnd = new IntPtr(0);
- for(int i = 0; i<3000; i++)
- {
- wnd = FindWindow(WindowClassName, "Skype Home");
- if ( wnd.Equals(IntPtr.Zero) )
- {
- wnd = FindWindow(WindowClassName, "Главная страница Skype");
- }
- if ( !wnd.Equals(IntPtr.Zero) && IsWindowVisible(wnd) )
- {
- SendMessage(wnd, WM_CLOSE, 0, 0 );
- return;
- }
- Thread.Sleep(10);
- }
- }
- static string GetSkypePath()
- {
- string path = "";
- object res;
- RegistryKey key = Registry.CurrentUser.OpenSubKey(RegPath, false);
- if (key != null && (res = key.GetValue("SkypePath")) is string )
- {
- path = res as string;
- }
- return path;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement