2017-12-18 1 views
1

내가 실행하고 내의 WinForm 응용 프로그램에서 OSK 크기를 조정하려고하지만 난이 오류를 얻고으로 비주얼 스튜디오를 실행 한 후 고도가 필요합니다요청한 작업도 관리자

The requested operation requires elevation.

내가 관리자로 비주얼 스튜디오를 실행하고 있습니다.

System.Diagnostics.Process process = new System.Diagnostics.Process(); 
process.StartInfo.UseShellExecute = false; 
process.StartInfo.RedirectStandardOutput = true; 
process.StartInfo.RedirectStandardError = true; 
process.StartInfo.CreateNoWindow = true; 
process.StartInfo.FileName = "c:\\windows\\system32\\osk.exe"; 
process.StartInfo.Arguments = ""; 
process.StartInfo.WorkingDirectory = "c:\\"; 

process.Start(); // **ERROR HERE** 
process.WaitForInputIdle(); 
SetWindowPos(process.MainWindowHandle, 
this.Handle, // Parent Window 
this.Left, // Keypad Position X 
this.Top + 20, // Keypad Position Y 
panelButtons.Width, // Keypad Width 
panelButtons.Height, // Keypad Height 
SWP_SHOWWINDOW | SWP_NOZORDER); // Show Window and Place on Top 
SetForegroundWindow(process.MainWindowHandle); 

그러나

,

System.Diagnostics.Process.Start("osk.exe"); 

작품 잘하지만 늘 나에게 당신이 원하는 일을에서 당신을 금지합니다 키보드

+0

"릴리스"모드로 실행 해 보셨습니까? 즉, 귀하의 프로그램을 실행 exe? 관리자로 exe를 실행하려면'startInfo.Verb = "runas";' – Sunil

답변

0

process.StartInfo.UseShellExecute = false 크기를 조정할 수 있습니다. osk.exe은 한 번에 하나의 인스턴스 만 실행할 수 있으므로 약간 특별합니다. 따라서 os가 시작을 처리하도록해야합니다 (UseShellExecute이 참이어야합니다).

(...) Works just fine but it wont let me resize the keyboard

그냥 process.MainWindowHandleIntPtr.Zero가 아님을 확인하십시오. 프로세스가 process.WaitForInputIdle()으로 프로세스 인스턴스에 요청할 수 없습니다. proc가 os에 의해 실행 되었기 때문일 수 있습니다. 핸들을 폴링 한 다음 코드를 실행할 수 있습니다. 이 같은 :

System.Diagnostics.Process process = new System.Diagnostics.Process(); 
// process.StartInfo.UseShellExecute = false; 
// process.StartInfo.RedirectStandardOutput = true; 
// process.StartInfo.RedirectStandardError = true; 
process.StartInfo.CreateNoWindow = true; 
process.StartInfo.FileName = "c:\\windows\\system32\\osk.exe"; 
process.StartInfo.Arguments = ""; 
process.StartInfo.WorkingDirectory = "c:\\"; 

process.Start(); // **ERROR WAS HERE** 
//process.WaitForInputIdle(); 

//Wait for handle to become available 
while(process.MainWindowHandle == IntPtr.Zero) 
    Task.Delay(10).Wait(); 

SetWindowPos(process.MainWindowHandle, 
this.Handle, // Parent Window 
this.Left, // Keypad Position X 
this.Top + 20, // Keypad Position Y 
panelButtons.Width, // Keypad Width 
panelButtons.Height, // Keypad Height 
SWP_SHOWWINDOW | SWP_NOZORDER); // Show Window and Place on Top 
SetForegroundWindow(process.MainWindowHandle); 

때문에 참고 : Wait() (또는 Thread.Sleep)의 사용; WinForms에서 매우 제한적이어야하며, ui 스레드가 응답하지 않게 만듭니다. await Task.Delay(10)을 사용하려면 Task.Run(async() => ...을 여기에 대신 사용해야하지만 이는 다른 이야기이며 코드를 약간 복잡하게 만듭니다.

관련 문제