-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathRDPShare.cpp
executable file
·109 lines (104 loc) · 3.13 KB
/
RDPShare.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* RDPShare: Windows Desktop Sharing remote control interface
*
* Copyright 2016 Simul Piscator
*
* RDPShare is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RDPShare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RDPShare. If not, see <http://www.gnu.org/licenses/>.
*/
#include "RDPShareServer.h"
#include "Sharer.h"
#include "Utils.h"
#include <sstream>
#include <Windows.h>
static const char* usage =
"Usage:\tRDPShare [idle] [http <port>] [rdp <port>] [screen {0..n}]\n"
"Defaults are: http 8080 rdp 3390 screen 0\n"
"A WDS session is started automatically, unless the \"idle\" option has been given.\n\n"
"Use a web browser to connect to the HTTP port for additional options.\n"
"In addition, the following requests are recognized when when sent to the HTTP port:\n"
" start: start WDS session\n"
" stop: stop WDS session\n"
" quit: exit server process\n"
" set_Resolution: set screen resolution\n"
" get_ConnectionString: get WDS connection string\n"
" get_RASessionID: get Remote Assistance session ID\n"
" get_SharedRect: get shared rect\n";
int
CALLBACK WinMain(HINSTANCE, HINSTANCE, char* inArgs, int)
{
std::string command = GetProgramName() + " " + inArgs;
unsigned short http = 8080, rdp = 3390, screen = 0;
bool help = false, idle = false;
std::istringstream iss(inArgs);
std::string token, error;
while( iss >> token && error.empty() )
{
if (token == "http" && iss >> http)
;
else if (token == "rdp" && iss >> rdp)
;
else if (token == "screen" && iss >> screen)
;
else if (token == "idle")
idle = true;
else if (token == "/?" || token.find("help") != std::string::npos)
help = true;
else
error = "unexpected input: \"" + token + "\"";
}
if(help)
{
::MessageBoxA(NULL, usage, command.c_str(), MB_OK);
return 0;
}
else if(!error.empty())
error = "Error: " + error + "\n\n" + usage;
int result = error.empty() ? 0 : -1;
HRESULT oleInitializeResult = ::OleInitialize(nullptr);
if( result == 0 && SUCCEEDED(oleInitializeResult)) try
{
Sharer sharer;
sharer.SetPort(rdp);
RDPShareServer server(INADDR_ANY, http, screen, &sharer);
if(!idle)
server.Start();
result = server.Run();
}
catch (HR_SucceedOrDie hr)
{
result = hr;
}
catch(WSA_SucceedOrDie)
{
result = ::WSAGetLastError();
}
catch(BOOL_SucceedOrDie)
{
result = ::GetLastError();
}
catch(const std::string& s)
{
result = -1;
error = s;
}
if (result)
{
if(error.empty())
error = GetErrorText(result);
::MessageBoxA(NULL, error.c_str(), command.c_str(), MB_OK | MB_ICONERROR);
}
if (SUCCEEDED(oleInitializeResult))
::OleUninitialize();
return result;
}