Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application fails creating a windows station with CreateWindowStation

Tags:

c++

windows

I can't create a new Window Station to run my application

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    wprintf(L"SetProcessWindowStation() before: %x\n", GetProcessWindowStation());
    HWINSTA winSta = CreateWindowStation(_T("hiddenWinSta"), 0, 0, NULL);
     if (winSta == NULL)
     {
        wprintf(L"CreateWindowStation() failed, error %d!\n", GetLastError());
     }else
        wprintf(L"CreateWindowStation() is OK!\n");
    SetProcessWindowStation(winSta);
    OpenDesktop(L"default", 0, FALSE, READ_CONTROL | WRITE_DAC | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS);
    wprintf(L"SetProcessWindowStation() after: %x\n", GetProcessWindowStation());
    system("pause");
    return 0;
}

and can I make a screenshot of new windows station not is winsta0 and desktop default? please help me :(


output

SetProcessWindowStation() before: 30
CreateWindowStation() failed, error 5!
SetProcessWindowStation() after: 30
Press any key to continue . . .
like image 923
Hiếp me Avatar asked Dec 07 '25 13:12

Hiếp me


1 Answers

Error 5 is ERROR_ACCESS_DENIED

From CreateWindowStation

lpwinsta [in, optional]

The name of the window station to be created. Window station names are case-insensitive and cannot contain backslash characters \. Only members of the Administrators group are allowed to specify a name. If lpwinsta is NULL or an empty string, the system forms a window station name using the logon session identifier for the calling process. To get this name, call the GetUserObjectInformation function.

So either start your program as administator or don't specify a name.

like image 199
typ1232 Avatar answered Dec 09 '25 02:12

typ1232



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!