+- +-

+-User

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+-Stats

Members
Total Members: 131
Latest: meriehileard
New This Month: 1
New This Week: 0
New Today: 0
Stats
Total Posts: 320
Total Topics: 161
Most Online Today: 6
Most Online Ever: 159
(June 29, 2021, 10:20:55 pm)
Users Online
Members: 0
Guests: 6
Total: 6

Author Topic: To Create a hidden desktop  (Read 295 times)

Alex.

  • Guest
To Create a hidden desktop
« on: March 15, 2017, 11:10:31 pm »
project that requires the creation of new desks and I thought of sharing a piece of code I hope they are useful

Code: [Select]
#include "Windows.h"
#pragma comment(lib, "Rpcrt4")


#define  RAND_DESK_NAME  0x000040

template <class TCHAR>
class MakeNewDesktop
{
public:

MakeNewDesktop();
bool generateUUID(LPVOID buffer, DWORD sz);
bool setDeskName(TCHAR *name);
void SwitchToNew();
void SwitchToDefault() const;
private:
bool Create();

public:

private:
TCHAR DeskName[40];
int randName;
bool b_ok;
UUID bUuid;
RPC_WSTR rstrUUID;
HDESK hDeskNew;
HDESK hDeskOld;

protected:
};


template <class TCHAR>
MakeNewDesktop<TCHAR>::MakeNewDesktop() : randName(0), rstrUUID(nullptr), hDeskNew(nullptr),
hDeskOld(nullptr), b_ok(false)
{
}


template <class TCHAR>
bool MakeNewDesktop<TCHAR>::generateUUID(LPVOID buffer, DWORD sz)
{
// vamos a Generar El Indentificador  Universal unico
if (UuidCreate(&bUuid) == RPC_S_OK) b_ok = true;
else return false;

if (b_ok != false && UuidToStringW(&bUuid, &rstrUUID) == RPC_S_OK)
{
// copiamos el numero de caracteres que requiere el buffer
lstrcpynW(LPWSTR(buffer), LPCWSTR(rstrUUID), sz);
return true;
}

return false;
}

template <class TCHAR>
bool MakeNewDesktop<TCHAR>::setDeskName(TCHAR* name)
{
if (name == NULL || ua_lstrlenW(name) > 40) return false;
else  lstrcpynW(DeskName, name, lstrlenW(name) + 1);
return true;
}

template <class TCHAR>
bool MakeNewDesktop<TCHAR>::Create()
{

b_ok = false;
if (randName != false || DeskName == FALSE)
generateUUID(DeskName, 40);

if (DeskName != NULL && hDeskNew == NULL)
{
hDeskOld = GetThreadDesktop(GetCurrentThreadId()); // obtenemos el manejdor de el escritorio actual
hDeskNew = CreateDesktopW(DeskName, NULL, NULL, 0, GENERIC_ALL, NULL); // creamos el nuevo
if (hDeskOld != NULL && hDeskNew != NULL)
{
WCHAR  explore[MAX_PATH];
ExpandEnvironmentStringsW(L"%windir%\\explorer.exe", explore, MAX_PATH - 1);
STARTUPINFOW startup_info = { 0 };
PROCESS_INFORMATION process_info = { 0 };

if (SetThreadDesktop(hDeskNew))
{
startup_info.cb = sizeof(startup_info);
startup_info.lpDesktop = DeskName;
CreateProcessW(explore, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startup_info, &process_info);
SetThreadDesktop(hDeskOld);
}
}

b_ok = true;
}

return  b_ok;
}

template <class TCHAR>
void MakeNewDesktop<TCHAR>::SwitchToNew()
{

if ((Create() != NULL))
{
SetThreadDesktop(hDeskNew);
SwitchDesktop(hDeskNew);

}

}

template <class TCHAR>
void MakeNewDesktop<TCHAR>::SwitchToDefault() const
{
SwitchDesktop(hDeskOld);
CloseHandle(hDeskNew);
}

typedef  MakeNewDesktop<wchar_t> MakeDeskW;
#endif // CREATEDESKTOP_H

Code: [Select]
MakeDeskW newDesk;
newDesk.setDeskName(L"Selene-PC");
newDesk.SwitchToNew();
Sleep(9000);
newDesk.SwitchToDefault();

 

+-Recent Topics

Power Blast Keto Reviews by meriehileard
September 12, 2021, 07:38:32 pm

Independent Call Girls in Chandigarh by dilpreetkaur
June 21, 2021, 01:02:52 pm

Hi zwclose7. How to create process by using NT apis? by zwclose7
June 01, 2021, 03:09:52 pm

Poison of the Day by zwclose7
March 16, 2020, 06:45:08 pm

IRC by AzeS
February 17, 2020, 08:18:01 am

Native API tutorial by hMihaiDavid
January 08, 2019, 02:11:02 am

The properties of GP nerve agent by xchg
October 19, 2018, 07:40:57 pm

A new route of synthesis for G-series agents by Basquyatti
October 15, 2018, 06:12:57 am

Synthesis of Methylisobutylcarbinylsarin (GH) by APC process by Basquyatti
October 14, 2018, 07:55:33 am

Synthesis conventional of Sarin by Basquyatti
October 02, 2018, 07:57:32 am