Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1219)

Side by Side Diff: chrome/installer/util/wmi.cc

Issue 2824773002: Rename ScopedComPtr::get() to ScopedComPtr::Get() (Closed)
Patch Set: Update to 5293966 Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | chrome/service/cloud_print/print_system_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/installer/util/wmi.h" 5 #include "chrome/installer/util/wmi.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/win/scoped_bstr.h" 10 #include "base/win/scoped_bstr.h"
(...skipping 13 matching lines...) Expand all
24 return false; 24 return false;
25 25
26 base::win::ScopedComPtr<IWbemServices> wmi_services_r; 26 base::win::ScopedComPtr<IWbemServices> wmi_services_r;
27 hr = wmi_locator->ConnectServer(base::win::ScopedBstr(L"ROOT\\CIMV2"), 27 hr = wmi_locator->ConnectServer(base::win::ScopedBstr(L"ROOT\\CIMV2"),
28 NULL, NULL, 0, NULL, 0, 0, 28 NULL, NULL, 0, NULL, 0, 0,
29 wmi_services_r.Receive()); 29 wmi_services_r.Receive());
30 if (FAILED(hr)) 30 if (FAILED(hr))
31 return false; 31 return false;
32 32
33 if (set_blanket) { 33 if (set_blanket) {
34 hr = ::CoSetProxyBlanket(wmi_services_r.get(), RPC_C_AUTHN_WINNT, 34 hr = ::CoSetProxyBlanket(wmi_services_r.Get(), RPC_C_AUTHN_WINNT,
35 RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, 35 RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL,
36 RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE); 36 RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE);
37 if (FAILED(hr)) 37 if (FAILED(hr))
38 return false; 38 return false;
39 } 39 }
40 40
41 *wmi_services = wmi_services_r.Detach(); 41 *wmi_services = wmi_services_r.Detach();
42 return true; 42 return true;
43 } 43 }
44 44
(...skipping 10 matching lines...) Expand all
55 hr = wmi_services->GetObject(b_class_name, 0, NULL, 55 hr = wmi_services->GetObject(b_class_name, 0, NULL,
56 class_object.Receive(), NULL); 56 class_object.Receive(), NULL);
57 if (FAILED(hr)) 57 if (FAILED(hr))
58 return false; 58 return false;
59 59
60 base::win::ScopedComPtr<IWbemClassObject> params_def; 60 base::win::ScopedComPtr<IWbemClassObject> params_def;
61 hr = class_object->GetMethod(b_method_name, 0, params_def.Receive(), NULL); 61 hr = class_object->GetMethod(b_method_name, 0, params_def.Receive(), NULL);
62 if (FAILED(hr)) 62 if (FAILED(hr))
63 return false; 63 return false;
64 64
65 if (NULL == params_def.get()) { 65 if (NULL == params_def.Get()) {
66 // You hit this special case if the WMI class is not a CIM class. MSDN 66 // You hit this special case if the WMI class is not a CIM class. MSDN
67 // sometimes tells you this. Welcome to WMI hell. 67 // sometimes tells you this. Welcome to WMI hell.
68 return false; 68 return false;
69 } 69 }
70 70
71 hr = params_def->SpawnInstance(0, class_instance); 71 hr = params_def->SpawnInstance(0, class_instance);
72 return(SUCCEEDED(hr)); 72 return(SUCCEEDED(hr));
73 } 73 }
74 74
75 bool SetParameter(IWbemClassObject* class_method, 75 bool SetParameter(IWbemClassObject* class_method,
(...skipping 11 matching lines...) Expand all
87 // the values in the returned out_params, are VT_I4, which is int32_t. 87 // the values in the returned out_params, are VT_I4, which is int32_t.
88 88
89 bool WMIProcess::Launch(const std::wstring& command_line, int* process_id) { 89 bool WMIProcess::Launch(const std::wstring& command_line, int* process_id) {
90 base::win::ScopedComPtr<IWbemServices> wmi_local; 90 base::win::ScopedComPtr<IWbemServices> wmi_local;
91 if (!WMI::CreateLocalConnection(true, wmi_local.Receive())) 91 if (!WMI::CreateLocalConnection(true, wmi_local.Receive()))
92 return false; 92 return false;
93 93
94 const wchar_t class_name[] = L"Win32_Process"; 94 const wchar_t class_name[] = L"Win32_Process";
95 const wchar_t method_name[] = L"Create"; 95 const wchar_t method_name[] = L"Create";
96 base::win::ScopedComPtr<IWbemClassObject> process_create; 96 base::win::ScopedComPtr<IWbemClassObject> process_create;
97 if (!WMI::CreateClassMethodObject(wmi_local.get(), class_name, method_name, 97 if (!WMI::CreateClassMethodObject(wmi_local.Get(), class_name, method_name,
98 process_create.Receive())) 98 process_create.Receive()))
99 return false; 99 return false;
100 100
101 ScopedVariant b_command_line(command_line.c_str()); 101 ScopedVariant b_command_line(command_line.c_str());
102 102
103 if (!SetParameter(process_create.get(), L"CommandLine", 103 if (!SetParameter(process_create.Get(), L"CommandLine",
104 b_command_line.AsInput())) 104 b_command_line.AsInput()))
105 return false; 105 return false;
106 106
107 base::win::ScopedComPtr<IWbemClassObject> out_params; 107 base::win::ScopedComPtr<IWbemClassObject> out_params;
108 HRESULT hr = wmi_local->ExecMethod( 108 HRESULT hr = wmi_local->ExecMethod(
109 base::win::ScopedBstr(class_name), base::win::ScopedBstr(method_name), 0, 109 base::win::ScopedBstr(class_name), base::win::ScopedBstr(method_name), 0,
110 NULL, process_create.get(), out_params.Receive(), NULL); 110 NULL, process_create.Get(), out_params.Receive(), NULL);
111 if (FAILED(hr)) 111 if (FAILED(hr))
112 return false; 112 return false;
113 113
114 // We're only expecting int32_t or uint32_t values, so no need for 114 // We're only expecting int32_t or uint32_t values, so no need for
115 // ScopedVariant. 115 // ScopedVariant.
116 VARIANT ret_value = {{{VT_EMPTY}}}; 116 VARIANT ret_value = {{{VT_EMPTY}}};
117 hr = out_params->Get(L"ReturnValue", 0, &ret_value, NULL, 0); 117 hr = out_params->Get(L"ReturnValue", 0, &ret_value, NULL, 0);
118 if (FAILED(hr) || 0 != V_I4(&ret_value)) 118 if (FAILED(hr) || 0 != V_I4(&ret_value))
119 return false; 119 return false;
120 120
(...skipping 13 matching lines...) Expand all
134 if (!WMI::CreateLocalConnection(true, services.Receive())) 134 if (!WMI::CreateLocalConnection(true, services.Receive()))
135 return base::string16(); 135 return base::string16();
136 136
137 base::win::ScopedBstr query_language(L"WQL"); 137 base::win::ScopedBstr query_language(L"WQL");
138 base::win::ScopedBstr query(L"SELECT * FROM Win32_ComputerSystem"); 138 base::win::ScopedBstr query(L"SELECT * FROM Win32_ComputerSystem");
139 base::win::ScopedComPtr<IEnumWbemClassObject> enumerator; 139 base::win::ScopedComPtr<IEnumWbemClassObject> enumerator;
140 HRESULT hr = services->ExecQuery( 140 HRESULT hr = services->ExecQuery(
141 query_language, query, 141 query_language, query,
142 WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, 142 WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL,
143 enumerator.Receive()); 143 enumerator.Receive());
144 if (FAILED(hr) || !enumerator.get()) 144 if (FAILED(hr) || !enumerator.Get())
145 return base::string16(); 145 return base::string16();
146 146
147 base::win::ScopedComPtr<IWbemClassObject> class_object; 147 base::win::ScopedComPtr<IWbemClassObject> class_object;
148 ULONG items_returned = 0; 148 ULONG items_returned = 0;
149 hr = enumerator->Next(WBEM_INFINITE, 1, class_object.Receive(), 149 hr = enumerator->Next(WBEM_INFINITE, 1, class_object.Receive(),
150 &items_returned); 150 &items_returned);
151 if (!items_returned) 151 if (!items_returned)
152 return base::string16(); 152 return base::string16();
153 153
154 base::win::ScopedVariant manufacturer; 154 base::win::ScopedVariant manufacturer;
155 class_object->Get(L"Manufacturer", 0, manufacturer.Receive(), 0, 0); 155 class_object->Get(L"Manufacturer", 0, manufacturer.Receive(), 0, 0);
156 base::win::ScopedVariant model; 156 base::win::ScopedVariant model;
157 class_object->Get(L"Model", 0, model.Receive(), 0, 0); 157 class_object->Get(L"Model", 0, model.Receive(), 0, 0);
158 158
159 base::string16 model_string; 159 base::string16 model_string;
160 if (manufacturer.type() == VT_BSTR) { 160 if (manufacturer.type() == VT_BSTR) {
161 model_string = V_BSTR(manufacturer.ptr()); 161 model_string = V_BSTR(manufacturer.ptr());
162 if (model.type() == VT_BSTR) 162 if (model.type() == VT_BSTR)
163 model_string += L" "; 163 model_string += L" ";
164 } 164 }
165 if (model.type() == VT_BSTR) 165 if (model.type() == VT_BSTR)
166 model_string += V_BSTR(model.ptr()); 166 model_string += V_BSTR(model.ptr());
167 167
168 return model_string; 168 return model_string;
169 } 169 }
170 170
171 } // namespace installer 171 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.cc ('k') | chrome/service/cloud_print/print_system_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698