예제 #1
0
파일: Enumerator.cpp 프로젝트: DRIZO/xcsoar
gcc_pure
static bool
CompareRegistryValue(const RegistryKey &registry,
                     const TCHAR *name, const TCHAR *value)
{
  TCHAR real_value[64];
  return registry.GetValue(name, real_value, 64) &&
    StringIsEqualIgnoreCase(value, real_value);
}
예제 #2
0
    Service::Service( std::wstring const& serviceName, std::wstring const& displayName, SERVICE_STATUS const& status, SC_HANDLE scmHandle ) 
        : serviceName(serviceName)
        , displayName(displayName)
        , svchostDamaged(false)
    {
        // Set the state
        switch (status.dwCurrentState)
        {
        case SERVICE_STOPPED:
            this->state = L"S";
            break;
        case SERVICE_START_PENDING:
            this->state = L"R?";
            break;
        case SERVICE_STOP_PENDING:
            this->state = L"S?";
            break;
        case SERVICE_RUNNING:
            this->state = L"R";
            break;
        case SERVICE_CONTINUE_PENDING:
            this->state = L"C?";
            break;
        case SERVICE_PAUSE_PENDING:
            this->state = L"P?";
            break;
        case SERVICE_PAUSED:
            this->state = L"P";
            break;
        default:
            this->state = L"?";
            break;
        }

        serviceHandle = OpenServiceW(scmHandle, this->serviceName.c_str(), SERVICE_QUERY_CONFIG);
        if (serviceHandle == NULL)
        {
            Win32Exception::ThrowFromLastError();
        }
        std::aligned_storage<8192 /* (8K bytes maximum size) */, std::alignment_of<QUERY_SERVICE_CONFIGW>::value>::type
            queryServiceConfigBuffer;
        DWORD bytesNeeded = 0; // not needed
        if (QueryServiceConfig(serviceHandle, reinterpret_cast<LPQUERY_SERVICE_CONFIGW>(&queryServiceConfigBuffer), 8192, &bytesNeeded) == false)
        {
            Win32Exception::ThrowFromLastError();
        }
        QUERY_SERVICE_CONFIGW *queryServiceConfig = reinterpret_cast<QUERY_SERVICE_CONFIGW*>(&queryServiceConfigBuffer);

        // Set the start type
        this->start = queryServiceConfig->dwStartType;

        // Set the file
        this->filepath = queryServiceConfig->lpBinaryPathName;
        if (filepath.empty())
        {
            if (queryServiceConfig->dwServiceType == SERVICE_KERNEL_DRIVER || queryServiceConfig->dwServiceType == SERVICE_FILE_SYSTEM_DRIVER)
            {
                filepath = Path::Append(Path::GetWindowsPath(), L"System32\\Drivers\\" + serviceName + L".sys");
            }
            else
            {
                filepath = Path::Append(Path::GetWindowsPath(), L"System32\\" + serviceName + L".exe");
            }
        }
        Path::ResolveFromCommandLine(this->filepath);

        static std::wstring svchostPath(Path::Append(Path::GetWindowsPath(), L"System32\\Svchost.exe"));
        // Set the svchost group, dll path, and damaged status if applicable
        if (boost::iequals(filepath, svchostPath))
        {
            // Get the svchost group
            this->svchostGroup = queryServiceConfig->lpBinaryPathName;
            this->svchostGroup.erase(this->svchostGroup.begin(), boost::ifind_first(this->svchostGroup, L"-k").end());            
            boost::trim(this->svchostGroup);
            
            std::wstring serviceKeyName = L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\" + this->serviceName;
            // Get the dll path
            RegistryKey serviceParameters = RegistryKey::Open(
                 serviceKeyName + L"\\Parameters", KEY_QUERY_VALUE);
            if (serviceParameters.Invalid())
            {
                serviceParameters = RegistryKey::Open(serviceKeyName, KEY_QUERY_VALUE);
            }
            if (serviceParameters.Invalid())
            {
                Win32Exception::ThrowFromNtError(::GetLastError());
            }
            RegistryValue serviceDllValue = serviceParameters.GetValue(L"ServiceDll");
            this->svchostDll = serviceDllValue.GetStringStrict();
            Path::ResolveFromCommandLine(this->svchostDll);

            // Check to see if it's damaged
            RegistryKey svchostGroupKey = RegistryKey::Open(L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Svchost", KEY_QUERY_VALUE);
            RegistryValue svchostGroupRegistration = svchostGroupKey.GetValue(this->svchostGroup);
            std::vector<std::wstring> svchostGroupRegistrationStrings = svchostGroupRegistration.GetMultiStringArray();
            auto groupRef = std::find_if(svchostGroupRegistrationStrings.begin(), svchostGroupRegistrationStrings.end(),
                [&] (std::wstring const& a) -> bool { return boost::iequals(a, serviceName, std::locale()); } );
            svchostDamaged = groupRef == svchostGroupRegistrationStrings.end();
        }
    }
예제 #3
0
	//*************************************************************************
	// Method:		Navigate
	// Description: Navigates to the specified URL in the specified frame
	//
	// Parameters:
	//	url - the url to navigate to
	//	targetFrame - the frame to use for displaying the page
	//
	// Return Value: None
	//*************************************************************************
	void HTMLBrowser::Navigate (String * url, String * targetFrame)
	{
		bool ieInstalled = true;

		try
		{
			Object * o = System::Reflection::Missing::Value;

			this->targetFrame = targetFrame;
			if ((File::Exists(url)) ||
				(url->ToLower()->StartsWith(S"about:")) ||
				(url->ToLower()->StartsWith(S"file:")))
			{
				try
				{
					browser->Navigate(url, &o, &o, &o, &o);
				}
				catch (...)
				{
				}
			}
			else
			{
				String * externalStr = S"external*";
				if (url->ToLower()->StartsWith(externalStr))
				{
					// Request to make any link external, remove tag
					url = url->Substring(externalStr->Length);
				}

				String * iePath = 0;
				RegistryKey * iePathKey = Registry::LocalMachine->OpenSubKey(S"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\iexplore.exe");
				if (iePathKey != 0)
					iePath = dynamic_cast <String*> (iePathKey->GetValue(0));

				System::Diagnostics::Process * p = new System::Diagnostics::Process();
				if (iePath != 0)
				{
					p->StartInfo->FileName = iePath;
					p->StartInfo->WorkingDirectory = Path::GetDirectoryName(iePath);

					if (!File::Exists(iePath))
					{
						ieInstalled = false;
						throw new Exception();
					}
				}
				else
				{
					ieInstalled = false;
					p->StartInfo->FileName = "iexplore.exe";
				}

				p->StartInfo->Arguments = url;
				p->StartInfo->ErrorDialog = true;
				p->StartInfo->UseShellExecute = false;
				p->Start();
			}
		}
		catch(Exception *)
		{
			String * msg = String::Concat(S"Could not launch Internet Explorer to display this link.\nIf you have another browser installed, please navigate to the page ", url, S" in that browser.");
			
			// if we couldn't get the IE reg key, and got an exception, IE probably wasn't installed so tell the user
			if (!ieInstalled)
				UserNotification::ErrorNotify (msg);
				
			// else some other error happened, but don't do anything about it
		}
	}