| OLD | NEW |
| 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 | 9 |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/win/scoped_bstr.h" | 10 #include "base/win/scoped_bstr.h" |
| 11 #include "base/win/scoped_comptr.h" | 11 #include "base/win/scoped_comptr.h" |
| 12 #include "base/win/scoped_variant.h" | 12 #include "base/win/scoped_variant.h" |
| 13 | 13 |
| 14 #pragma comment(lib, "wbemuuid.lib") | 14 #pragma comment(lib, "wbemuuid.lib") |
| 15 | 15 |
| 16 using base::win::ScopedVariant; | 16 using base::win::ScopedVariant; |
| 17 | 17 |
| 18 namespace installer { | 18 namespace installer { |
| 19 | 19 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 const std::wstring& parameter_name, VARIANT* parameter) { | 78 const std::wstring& parameter_name, VARIANT* parameter) { |
| 79 HRESULT hr = class_method->Put(parameter_name.c_str(), 0, parameter, 0); | 79 HRESULT hr = class_method->Put(parameter_name.c_str(), 0, parameter, 0); |
| 80 return SUCCEEDED(hr); | 80 return SUCCEEDED(hr); |
| 81 } | 81 } |
| 82 | 82 |
| 83 | 83 |
| 84 // The code in Launch() basically calls the Create Method of the Win32_Process | 84 // The code in Launch() basically calls the Create Method of the Win32_Process |
| 85 // CIM class is documented here: | 85 // CIM class is documented here: |
| 86 // http://msdn2.microsoft.com/en-us/library/aa389388(VS.85).aspx | 86 // http://msdn2.microsoft.com/en-us/library/aa389388(VS.85).aspx |
| 87 // NOTE: The documentation for the Create method suggests that the ProcessId | 87 // NOTE: The documentation for the Create method suggests that the ProcessId |
| 88 // parameter and return value are of type uint32, but when we call the method | 88 // parameter and return value are of type uint32_t, but when we call the method |
| 89 // the values in the returned out_params, are VT_I4, which is int32. | 89 // the values in the returned out_params, are VT_I4, which is int32_t. |
| 90 | 90 |
| 91 bool WMIProcess::Launch(const std::wstring& command_line, int* process_id) { | 91 bool WMIProcess::Launch(const std::wstring& command_line, int* process_id) { |
| 92 base::win::ScopedComPtr<IWbemServices> wmi_local; | 92 base::win::ScopedComPtr<IWbemServices> wmi_local; |
| 93 if (!WMI::CreateLocalConnection(true, wmi_local.Receive())) | 93 if (!WMI::CreateLocalConnection(true, wmi_local.Receive())) |
| 94 return false; | 94 return false; |
| 95 | 95 |
| 96 const wchar_t class_name[] = L"Win32_Process"; | 96 const wchar_t class_name[] = L"Win32_Process"; |
| 97 const wchar_t method_name[] = L"Create"; | 97 const wchar_t method_name[] = L"Create"; |
| 98 base::win::ScopedComPtr<IWbemClassObject> process_create; | 98 base::win::ScopedComPtr<IWbemClassObject> process_create; |
| 99 if (!WMI::CreateClassMethodObject(wmi_local.get(), class_name, method_name, | 99 if (!WMI::CreateClassMethodObject(wmi_local.get(), class_name, method_name, |
| 100 process_create.Receive())) | 100 process_create.Receive())) |
| 101 return false; | 101 return false; |
| 102 | 102 |
| 103 ScopedVariant b_command_line(command_line.c_str()); | 103 ScopedVariant b_command_line(command_line.c_str()); |
| 104 | 104 |
| 105 if (!SetParameter(process_create.get(), L"CommandLine", | 105 if (!SetParameter(process_create.get(), L"CommandLine", |
| 106 b_command_line.AsInput())) | 106 b_command_line.AsInput())) |
| 107 return false; | 107 return false; |
| 108 | 108 |
| 109 base::win::ScopedComPtr<IWbemClassObject> out_params; | 109 base::win::ScopedComPtr<IWbemClassObject> out_params; |
| 110 HRESULT hr = wmi_local->ExecMethod( | 110 HRESULT hr = wmi_local->ExecMethod( |
| 111 base::win::ScopedBstr(class_name), base::win::ScopedBstr(method_name), 0, | 111 base::win::ScopedBstr(class_name), base::win::ScopedBstr(method_name), 0, |
| 112 NULL, process_create.get(), out_params.Receive(), NULL); | 112 NULL, process_create.get(), out_params.Receive(), NULL); |
| 113 if (FAILED(hr)) | 113 if (FAILED(hr)) |
| 114 return false; | 114 return false; |
| 115 | 115 |
| 116 // We're only expecting int32 or uint32 values, so no need for ScopedVariant. | 116 // We're only expecting int32_t or uint32_t values, so no need for |
| 117 // ScopedVariant. |
| 117 VARIANT ret_value = {{{VT_EMPTY}}}; | 118 VARIANT ret_value = {{{VT_EMPTY}}}; |
| 118 hr = out_params->Get(L"ReturnValue", 0, &ret_value, NULL, 0); | 119 hr = out_params->Get(L"ReturnValue", 0, &ret_value, NULL, 0); |
| 119 if (FAILED(hr) || 0 != V_I4(&ret_value)) | 120 if (FAILED(hr) || 0 != V_I4(&ret_value)) |
| 120 return false; | 121 return false; |
| 121 | 122 |
| 122 VARIANT pid = {{{VT_EMPTY}}}; | 123 VARIANT pid = {{{VT_EMPTY}}}; |
| 123 hr = out_params->Get(L"ProcessId", 0, &pid, NULL, 0); | 124 hr = out_params->Get(L"ProcessId", 0, &pid, NULL, 0); |
| 124 if (FAILED(hr) || 0 == V_I4(&pid)) | 125 if (FAILED(hr) || 0 == V_I4(&pid)) |
| 125 return false; | 126 return false; |
| 126 | 127 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 if (model.type() == VT_BSTR) | 164 if (model.type() == VT_BSTR) |
| 164 model_string += L" "; | 165 model_string += L" "; |
| 165 } | 166 } |
| 166 if (model.type() == VT_BSTR) | 167 if (model.type() == VT_BSTR) |
| 167 model_string += V_BSTR(model.ptr()); | 168 model_string += V_BSTR(model.ptr()); |
| 168 | 169 |
| 169 return model_string; | 170 return model_string; |
| 170 } | 171 } |
| 171 | 172 |
| 172 } // namespace installer | 173 } // namespace installer |
| OLD | NEW |