终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

198 satır
6.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.ComponentModel;
  10. using System.IO;
  11. namespace BPASmartClient.Helper
  12. {
  13. public class SystemUtils
  14. {
  15. public static bool isShowNumBoard = false;
  16. [DllImport("kernel32.dll", SetLastError = true)]
  17. public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
  18. [DllImport("kernel32.dll", SetLastError = true)]
  19. public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
  20. public static void ShowScreenKeyboard()
  21. {
  22. //获得当前登录的Windows用户标示
  23. System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
  24. System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
  25. //判断当前登录用户是否为管理员
  26. if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
  27. {
  28. try
  29. {
  30. Process[] pros = Process.GetProcessesByName("TabTip");
  31. string path = "C:/Program Files/Common Files/microsoft shared/ink/TabTip.exe";
  32. if (File.Exists(path)) Process.Start(path);
  33. else
  34. {
  35. Process[] pro = Process.GetProcessesByName("osk");//判断软键盘是否进程是否已经存在,如果不存在进行调用
  36. if (pro != null && pro.Length > 0) return;//说明已经存在,不再进行调用
  37. IntPtr ptr = new IntPtr();
  38. bool isWow64FsRedirectionDisabled = Wow64DisableWow64FsRedirection(ref ptr);
  39. if (isWow64FsRedirectionDisabled)
  40. {
  41. Process.Start(@"C:\WINDOWS\system32\osk.exe");
  42. bool isWow64FsRedirectionReverted = Wow64RevertWow64FsRedirection(ptr);
  43. }
  44. }
  45. }
  46. catch (Exception)
  47. {
  48. throw;
  49. }
  50. }
  51. else
  52. {
  53. //创建启动对象
  54. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
  55. startInfo.FileName = "";//Application.ExecutablePath;//设置运行文件
  56. startInfo.Arguments = "";// String.Join(" ", args); //设置启动参数
  57. startInfo.Verb = "runas"; //设置启动动作,确保以管理员身份运行
  58. System.Diagnostics.Process.Start(startInfo); //如果不是管理员,则启动UAC
  59. //退出应用程序
  60. }
  61. }
  62. }
  63. }
  64. //[DllImport("kernel32.dll", SetLastError = true)]
  65. //private static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
  66. //[DllImport("kernel32.dll", SetLastError = true)]
  67. //public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
  68. //private const UInt32 WM_SYSCOMMAND = 0x112;
  69. //private const UInt32 SC_RESTORE = 0xf120;
  70. //[DllImport("user32.dll", CharSet = CharSet.Auto)]
  71. //static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
  72. //private const string OnScreenKeyboadApplication = "osk.exe";
  73. ///// <summary>
  74. ///// 启用系统软键盘
  75. ///// </summary>
  76. //public static void OpenKeyBoardFun()
  77. //{
  78. // try
  79. // {
  80. // //判断软键盘是否进程是否已经存在,如果不存在进行调用
  81. // Process[] pro = Process.GetProcessesByName("osk");
  82. // //如果键盘已打开,则进行关闭操作
  83. // if (pro != null && pro.Length > 0)
  84. // {
  85. // CloseKeyBoardFun();
  86. // return;
  87. // }
  88. // // Get the name of the On screen keyboard
  89. // string processName = System.IO.Path.GetFileNameWithoutExtension(OnScreenKeyboadApplication);
  90. // // Check whether the application is not running
  91. // var query = from process in Process.GetProcesses()
  92. // where process.ProcessName == processName
  93. // select process;
  94. // var keyboardProcess = query.FirstOrDefault();
  95. // // launch it if it doesn't exist
  96. // if (keyboardProcess == null)
  97. // {
  98. // IntPtr ptr = new IntPtr(); ;
  99. // bool sucessfullyDisabledWow64Redirect = false;
  100. // // Disable x64 directory virtualization if we're on x64,
  101. // // otherwise keyboard launch will fail.
  102. // if (System.Environment.Is64BitOperatingSystem)
  103. // {
  104. // sucessfullyDisabledWow64Redirect = Wow64DisableWow64FsRedirection(ref ptr);
  105. // }
  106. // // osk.exe is in windows/system folder. So we can directky call it without path
  107. // using (Process osk = new Process())
  108. // {
  109. // osk.StartInfo.FileName = OnScreenKeyboadApplication;
  110. // osk.Start();
  111. // //osk.WaitForInputIdle(2000);
  112. // }
  113. // // Re-enable directory virtualisation if it was disabled.
  114. // if (System.Environment.Is64BitOperatingSystem)
  115. // if (sucessfullyDisabledWow64Redirect)
  116. // Wow64RevertWow64FsRedirection(ptr);
  117. // }
  118. // else
  119. // {
  120. // // Bring keyboard to the front if it's already running
  121. // var windowHandle = keyboardProcess.MainWindowHandle;
  122. // SendMessage(windowHandle, WM_SYSCOMMAND, new IntPtr(SC_RESTORE), new IntPtr(0));
  123. // }
  124. // }
  125. // catch (Exception ex)
  126. // {
  127. // //LogUtil.WriteLog(MethodBase.GetCurrentMethod().Name, LogUtil.ERROE, ex.Message);
  128. // //LogUtil.WriteLog(MethodBase.GetCurrentMethod().Name, LogUtil.ERROE, ex.StackTrace);
  129. // }
  130. //}
  131. ///// <summary>
  132. ///// 关闭系统软键盘
  133. ///// </summary>
  134. //public static void CloseKeyBoardFun()
  135. //{
  136. // try
  137. // {
  138. // Process[] pros = Process.GetProcessesByName("osk");
  139. // foreach (Process p in pros)
  140. // {
  141. // p.Kill();
  142. // }
  143. // }
  144. // catch (Exception ex)
  145. // {
  146. // //LogUtil.WriteLog(MethodBase.GetCurrentMethod().Name, LogUtil.ERROE, ex.Message);
  147. // //LogUtil.WriteLog(MethodBase.GetCurrentMethod().Name, LogUtil.ERROE, ex.StackTrace);
  148. // }
  149. //}