그래,이 클래스는 온라인에서 "아무것도"실행되지 않는 두 번째 데스크톱을 "만듭니다"(즉, explorer.exe가 호출되지 않는 등) 것을 발견했습니다.win api 및 C# - 데스크톱
그러나이 새로 만든 데스크톱은 종료를 거부하고 원래 데스크톱으로 돌아갑니다. 나는 무슨 일이 벌어지고 있는지 전혀 모른다. 그래서 누군가가 자신의 컴퓨터에서 그것을 시도 할 수 있다면, 그것은 매우 도움이 될 것입니다.
참고 : 모든 win API 헤더가 선언되고 작동한다고 가정합니다.
클래스가 "잠금"현재 dekstop :
namespace Locker
{
class CLocker
{
public static int DesktopHandle; // Hold desktop handle.
public static int oldDesktopHandle;
public static int DesktopInputID; // Hold desktop input id.
public static int DesktopThreadID; // Hold desktop thread id.
static string DesktopName = "DL.Locker.Desktop"; // Hold the name of new created desktop.
static FileStream TaskMan; // Hold the file stream object to control task manager.
static string FastSwitching = string.Empty; // Hold the original value of fast switching i.e. welcome screen
static string ShutdownWithoutLogin = string.Empty; // Hold the original value of showinh the shutdown button on welcome screen.
/// <summary>
/// Enabled used to enable or disable the locker
/// </summary>
public static bool Enabled
{
set
{
SetProcessPriorityHigh(); // Set the process priority to high.
if (value) // Enable or disable the locker?
{
CreateNewDesktop(); // Creating new desktop.
StartProcess(Application.ExecutablePath); // Starting the locker form, to allow the user to enter login info.
}
else
{
DestroyDesktop(); // Destroy the desktop.
ExitProcess(0); // Exit the current process, if desktop attached with no process, default desktop will be activated.
}
}
}
public static bool NeedBootStrapping()
{
Console.WriteLine((GetDesktopName() != DesktopName).ToString());
return (GetDesktopName() != DesktopName);
}
static string GetDesktopName()
{
int DLength = 0, DHandle = GetThreadDesktop(GetCurrentThreadId());
StringBuilder DName = new StringBuilder();
GetUserObjectInformation(DHandle, UOI_NAME, DName, 0, ref DLength);
if (DLength != 0) GetUserObjectInformation(DHandle, UOI_NAME, DName, DLength, ref DLength);
Console.WriteLine(DName.ToString());
return (DName.ToString());
}
static void CreateNewDesktop()
{
DesktopThreadID = GetThreadDesktop(GetCurrentThreadId());
DesktopInputID = OpenInputDesktop(0, false, DESKTOP_SWITCHDESKTOP);
DesktopHandle = CreateDesktop(DesktopName, "", 0, 0, GENERIC_ALL, 0);
if (DesktopHandle != 0)
{
SetThreadDesktop(DesktopHandle);
SwitchDesktop(DesktopHandle);
}
}
public static void DestroyDesktop()
{
SwitchDesktop(DesktopInputID);
DesktopInputID = 0;
SetThreadDesktop(DesktopInputID);
DesktopThreadID = 0;
CloseDesktop(DesktopHandle);
DesktopHandle = 0;
}
static void StartProcess(string Path)
{
MessageBox.Show("Hello from startProcess");
DestroyDesktop();
}
static void SetProcessPriorityHigh()
{
SetThreadPriority(GetCurrentThread(), THREAD_BASE_PRIORITY_MAX);
SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
}
}
}
그리고 main() 함수 :
static void Main()
{
if (CLocker.NeedBootStrapping())
CLocker.Enabled = true; // Check if we need boot strapping or not, if true then a new desktop will created.
else // Run application as usual.
{
MessageBox.Show("Hello, this is your new desktop");
CLocker.Enabled = false;
}
}
업데이트 :이 코드는 컴파일되지 않습니다. "현재 상황에 존재하지 않는다"는 단어 밑에 약 40 개의 빨간색 구불 구불 한 선이 생깁니다.
그것은 당신의 기계를 망쳤다. 그래서 지금 우리 중 한 명이 그것을 시도하고 우리 기계를 망치기를 원한다. –
내 컴퓨터를 망칠 필요가 없습니다. 그것은 새로운 바탕 화면을 만들지 만, dosnt는 자동으로 오래된 것을 돌려 놓습니다. Youc ctrl/alt/del it, 작업 관리자로 이동하여 explorer.exe를 실행하십시오. – masfenix
코드를 찾았지만 이해하지 못했지만 실제로 사용하고 싶습니까? 어쩌면 데스크톱이 어떻게 작동하는지 더 잘 알 수 있습니다. –