|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.ComponentModel;
- using System.IO;
-
-
- namespace BPASmartClient.Helper
- {
- public class SystemUtils
- {
- public static bool isShowNumBoard = false;
- [DllImport("kernel32.dll", SetLastError = true)]
- public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
- [DllImport("kernel32.dll", SetLastError = true)]
- public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
-
-
- public static void ShowScreenKeyboard()
- {
-
- //获得当前登录的Windows用户标示
- System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
- System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
- //判断当前登录用户是否为管理员
- if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
- {
- try
- {
- Process[] pros = Process.GetProcessesByName("TabTip");
- string path = "C:/Program Files/Common Files/microsoft shared/ink/TabTip.exe";
- if (File.Exists(path)) Process.Start(path);
- else
- {
- Process[] pro = Process.GetProcessesByName("osk");//判断软键盘是否进程是否已经存在,如果不存在进行调用
- if (pro != null && pro.Length > 0) return;//说明已经存在,不再进行调用
- IntPtr ptr = new IntPtr();
- bool isWow64FsRedirectionDisabled = Wow64DisableWow64FsRedirection(ref ptr);
- if (isWow64FsRedirectionDisabled)
- {
- Process.Start(@"C:\WINDOWS\system32\osk.exe");
- bool isWow64FsRedirectionReverted = Wow64RevertWow64FsRedirection(ptr);
- }
- }
- }
- catch (Exception)
- {
-
- throw;
- }
-
-
- }
- else
- {
- //创建启动对象
- System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
-
- startInfo.FileName = "";//Application.ExecutablePath;//设置运行文件
-
- startInfo.Arguments = "";// String.Join(" ", args); //设置启动参数
-
- startInfo.Verb = "runas"; //设置启动动作,确保以管理员身份运行
-
- System.Diagnostics.Process.Start(startInfo); //如果不是管理员,则启动UAC
- //退出应用程序
-
- }
- }
-
-
-
-
-
-
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
- //[DllImport("kernel32.dll", SetLastError = true)]
- //private static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
- //[DllImport("kernel32.dll", SetLastError = true)]
- //public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
- //private const UInt32 WM_SYSCOMMAND = 0x112;
- //private const UInt32 SC_RESTORE = 0xf120;
- //[DllImport("user32.dll", CharSet = CharSet.Auto)]
- //static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
- //private const string OnScreenKeyboadApplication = "osk.exe";
-
-
- ///// <summary>
- ///// 启用系统软键盘
- ///// </summary>
- //public static void OpenKeyBoardFun()
- //{
- // try
- // {
- // //判断软键盘是否进程是否已经存在,如果不存在进行调用
- // Process[] pro = Process.GetProcessesByName("osk");
- // //如果键盘已打开,则进行关闭操作
- // if (pro != null && pro.Length > 0)
- // {
- // CloseKeyBoardFun();
- // return;
- // }
-
- // // Get the name of the On screen keyboard
- // string processName = System.IO.Path.GetFileNameWithoutExtension(OnScreenKeyboadApplication);
-
- // // Check whether the application is not running
- // var query = from process in Process.GetProcesses()
- // where process.ProcessName == processName
- // select process;
-
- // var keyboardProcess = query.FirstOrDefault();
-
- // // launch it if it doesn't exist
- // if (keyboardProcess == null)
- // {
- // IntPtr ptr = new IntPtr(); ;
- // bool sucessfullyDisabledWow64Redirect = false;
-
- // // Disable x64 directory virtualization if we're on x64,
- // // otherwise keyboard launch will fail.
- // if (System.Environment.Is64BitOperatingSystem)
- // {
- // sucessfullyDisabledWow64Redirect = Wow64DisableWow64FsRedirection(ref ptr);
- // }
-
- // // osk.exe is in windows/system folder. So we can directky call it without path
- // using (Process osk = new Process())
- // {
- // osk.StartInfo.FileName = OnScreenKeyboadApplication;
- // osk.Start();
- // //osk.WaitForInputIdle(2000);
- // }
-
- // // Re-enable directory virtualisation if it was disabled.
- // if (System.Environment.Is64BitOperatingSystem)
- // if (sucessfullyDisabledWow64Redirect)
- // Wow64RevertWow64FsRedirection(ptr);
- // }
- // else
- // {
- // // Bring keyboard to the front if it's already running
- // var windowHandle = keyboardProcess.MainWindowHandle;
- // SendMessage(windowHandle, WM_SYSCOMMAND, new IntPtr(SC_RESTORE), new IntPtr(0));
- // }
-
- // }
- // catch (Exception ex)
- // {
- // //LogUtil.WriteLog(MethodBase.GetCurrentMethod().Name, LogUtil.ERROE, ex.Message);
- // //LogUtil.WriteLog(MethodBase.GetCurrentMethod().Name, LogUtil.ERROE, ex.StackTrace);
- // }
-
- //}
-
-
- ///// <summary>
- ///// 关闭系统软键盘
- ///// </summary>
- //public static void CloseKeyBoardFun()
- //{
- // try
- // {
- // Process[] pros = Process.GetProcessesByName("osk");
- // foreach (Process p in pros)
- // {
- // p.Kill();
- // }
- // }
- // catch (Exception ex)
- // {
- // //LogUtil.WriteLog(MethodBase.GetCurrentMethod().Name, LogUtil.ERROE, ex.Message);
- // //LogUtil.WriteLog(MethodBase.GetCurrentMethod().Name, LogUtil.ERROE, ex.StackTrace);
- // }
-
- //}
-
-
-
|