Advertisement
Guest User

Skype Run

a guest
Sep 2nd, 2011
1,651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. /*
  2. @echo off && cls
  3. set WinDirNet=%WinDir%\Microsoft.NET\Framework
  4. IF EXIST "%WinDirNet%\v4.0.30319\csc.exe" set csc="%WinDirNet%\v4.0.30319\csc.exe"
  5. IF EXIST "%WinDirNet%\v3.5\csc.exe" set csc="%WinDirNet%\v3.5\csc.exe"
  6. IF EXIST "%WinDirNet%\v2.0.50727\csc.exe" set csc="%WinDirNet%\v2.0.50727\csc.exe"
  7. %csc% /nologo /out:"%~0.exe" %0
  8. "%~0.exe"
  9. del "%~0.exe"
  10. exit
  11. */
  12.  
  13. using System;
  14. using Microsoft.Win32;
  15. using System.Diagnostics;
  16. using System.Runtime.InteropServices;
  17. using System.Threading;
  18.  
  19. namespace SkypeRun
  20. {
  21.    
  22.     class Program
  23.     {
  24.         const string RegPath = @"Software\Skype\Phone";
  25.         const string WindowClassName = "THomeForm";
  26.  
  27.         #region Import
  28.         [DllImport("user32.dll", SetLastError = true)]
  29.         static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  30.        
  31.         [DllImport("user32.dll", CharSet=CharSet.Auto)]
  32.         public static extern bool IsWindowVisible(IntPtr hWnd);
  33.  
  34.         [DllImport("user32.dll")]
  35.         static extern int SendMessage(
  36.             IntPtr hWnd,    // handle to destination window
  37.             uint Msg,   // message
  38.             long wParam,    // first message parameter
  39.             long lParam // second message parameter
  40.             );
  41.  
  42.         const uint WM_CLOSE = 0x0010;
  43.         #endregion
  44.        
  45.         public static void Main(string[] args)
  46.         {
  47.             string path = GetSkypePath();
  48.             Process proc = Process.Start(path);
  49.             IntPtr wnd = new IntPtr(0);
  50.            
  51.             for(int i = 0; i<3000; i++)
  52.             {
  53.                 wnd = FindWindow(WindowClassName, "Skype Home");
  54.                 if ( wnd.Equals(IntPtr.Zero) )
  55.                 {
  56.                     wnd = FindWindow(WindowClassName, "Главная страница Skype");
  57.                 }
  58.                 if ( !wnd.Equals(IntPtr.Zero) && IsWindowVisible(wnd) )
  59.                 {
  60.                     SendMessage(wnd, WM_CLOSE, 0, 0 );
  61.                     return;
  62.                 }
  63.                 Thread.Sleep(10);
  64.             }
  65.         }
  66.        
  67.         static string GetSkypePath()
  68.         {
  69.             string path = "";
  70.             object res;
  71.            
  72.             RegistryKey key = Registry.CurrentUser.OpenSubKey(RegPath, false);
  73.             if (key != null && (res = key.GetValue("SkypePath")) is string )
  74.             {
  75.                 path = res as string;
  76.             }
  77.             return path;
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement