Home > Net >  C # monitoring paste board, pop-up window
C # monitoring paste board, pop-up window

Time:09-20

Client to monitor the change of the clipboard, if it is a 11 phone number, then you pop (the browser and the client will do) mobile number birthday and age (this information in the database server),

Idea is as follows (not necessarily appropriate) : create a Windows service, monitor the clipboard, if there is a new cell phone number, call the webservice access database, access to mobile phone's birthday and age, the pop-up page,
Question 1, the final step how pop-up Windows service page?
Question 2, is there any other methods, such as direct use winform + webservice, but usually have no form, only the pop-up clipboard has a new mobile phone number, how to do,
Pleaded with expert advice, thank you very much!

CodePudding user response:

The simplest is, build a winform procedure, then the service call this program

//start the program may take parameters
String exeArgus="";

The absolute path to the//
String exePathName="D: \ 1111. Exe";

The Process myprocess=new Process ();
ProcessStartInfo startInfo=new ProcessStartInfo (exePathName exeArgus);
Myprocess. StartInfo=StartInfo;
Myprocess. StartInfo. UseShellExecute=false;
Myprocess. Start ();

CodePudding user response:

Google, validated the
 
using System;
using System.Collections.Generic;
using System.Linq;
Using System. The Runtime. InteropServices;
Using System. Security. The Principal;
using System.Text;
Using System. The Threading. The Tasks;

The namespace ConsoleWithWindowsService
{
The class Interop
{
Public static void CreateProcess (string app, string path)
{
Bool result;
IntPtr hToken=WindowsIdentity. GetCurrent (.) Token.
IntPtr hDupedToken=IntPtr. Zero;

PROCESS_INFORMATION PI=new PROCESS_INFORMATION ();
SECURITY_ATTRIBUTES sa=new SECURITY_ATTRIBUTES ();
Sa. Length=Marshal. SizeOf (sa);

STARTUPINFO si=new STARTUPINFO ();
Si. Cb=Marshal. SizeOf (si);

Int dwSessionID=WTSGetActiveConsoleSessionId ();
Result=WTSQueryUserToken (dwSessionID out hToken);

if (! The result)
{
ShowMessageBox (" WTSQueryUserToken failed AlertService ", "Message");
}

Result=DuplicateTokenEx (
HToken,
GENERIC_ALL_ACCESS,
Ref sa,
(int) SECURITY_IMPERSONATION_LEVEL SecurityIdentification,
(int) TOKEN_TYPE TokenPrimary,
Ref hDupedToken
);

if (! The result)
{
ShowMessageBox (" DuplicateTokenEx failed AlertService ", "Message");
}

IntPtr lpEnvironment=IntPtr. Zero;
Result=CreateEnvironmentBlock (out lpEnvironment hDupedToken, false);

if (! The result)
{
ShowMessageBox (" CreateEnvironmentBlock failed AlertService ", "Message");
}

Result=CreateProcessAsUser (
HDupedToken,
App,
String. The Empty,
Ref ref sa, sa,
False, 0, IntPtr. Zero,
Null, ref si, ref PI);

if (! The result)
{
Int the error=Marshal. GetLastWin32Error ();
String message=the string. Format (" CreateProcessAsUser Error: {0} ", the Error).
ShowMessageBox (the message, "AlertService message");
}

If (PI hProcess!=IntPtr. Zero)
The CloseHandle (PI. HProcess);
If (PI hThread!=IntPtr. Zero)
The CloseHandle (PI. HThread);
If (hDupedToken!=IntPtr. Zero)
The CloseHandle (hDupedToken);
}

[StructLayout (LayoutKind. Sequential)]
Public struct STARTUPINFO
{
Public Int32 cb.
Public string lpReserved;
Public string lpDesktop;
Public string lpTitle;
Public Int32 dwX.
Public Int32 dwY;
Public Int32 dwXSize;
Public Int32 dwXCountChars;
Public Int32 dwYCountChars;
Public Int32 dwFillAttribute;
Public Int32 dwFlags;
Public Int16 wShowWindow;
Public Int16 cbReserved2;
Public IntPtr lpReserved2;
Public IntPtr hStdInput;
Public IntPtr hStdOutput;
Public IntPtr hStdError;
}

[StructLayout (LayoutKind. Sequential)]
Public struct PROCESS_INFORMATION
{
Public IntPtr hProcess;
Public IntPtr hThread;
Public Int32 dwProcessID;
Public Int32 dwThreadID;
}

[StructLayout (LayoutKind. Sequential)]
Public struct SECURITY_ATTRIBUTES
{
Public Int32 Length;
Public IntPtr lpSecurityDescriptor;
Public bool bInheritHandle;
}

Public enum SECURITY_IMPERSONATION_LEVEL
{
SecurityAnonymous,
SecurityIdentification,
SecurityImpersonation,
SecurityDelegation
}

Public enum TOKEN_TYPE
{
TokenPrimary=1,
TokenImpersonation
}

Public const int GENERIC_ALL_ACCESS=0 x10000000;

[DllImport (" kernel32. DLL, "SetLastError=true,
CharSet=CharSet. Auto, CallingConvention=CallingConvention StdCall)]
Public static extern bool CloseHandle (IntPtr handle);

[DllImport (" advapi32. DLL, "SetLastError=true,
CharSet=CharSet. Ansi, CallingConvention=CallingConvention StdCall)]
Public static extern bool CreateProcessAsUser (
IntPtr hToken,
String lpApplicationName,
String lpCommandLine,
Ref SECURITY_ATTRIBUTES lpProcessAttributes,
Ref SECURITY_ATTRIBUTES lpThreadAttributes,
Bool bInheritHandle,
Int32 dwCreationFlags,
IntPtr lpEnvrionment,
String lpCurrentDirectory,
Ref STARTUPINFO lpStartupInfo,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related