Exemple #1
0
DWORD
MMSYS_InstallDevice(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pspDevInfoData)
{
    UINT Length;
    LPWSTR pBuffer;
    WCHAR szBuffer[MAX_PATH];
    HINF hInf;
    PVOID Context;
    BOOL Result;
    SC_HANDLE hSCManager, hService;
    WCHAR WaveName[20];
    HKEY hKey;
    DWORD BufferSize;
    ULONG Index;

    if (!IsEqualIID(&pspDevInfoData->ClassGuid, &GUID_DEVCLASS_SOUND) &&
        !IsEqualIID(&pspDevInfoData->ClassGuid, &GUID_DEVCLASS_MEDIA))
        return ERROR_DI_DO_DEFAULT;

    Length = GetWindowsDirectoryW(szBuffer, MAX_PATH);
    if (!Length || Length >= MAX_PATH - 14)
    {
        return ERROR_GEN_FAILURE;
    }

    pBuffer = PathAddBackslashW(szBuffer);
    if (!pBuffer)
    {
        return ERROR_GEN_FAILURE;
    }

    wcscpy(pBuffer, L"inf\\audio.inf");

    hInf = SetupOpenInfFileW(szBuffer,
                             NULL,
                            INF_STYLE_WIN4,
                            NULL);

    if (hInf == INVALID_HANDLE_VALUE)
    {
        return ERROR_GEN_FAILURE;
    }

    Context = SetupInitDefaultQueueCallback(NULL);
    if (Context == NULL)
    {
        SetupCloseInfFile(hInf);
        return ERROR_GEN_FAILURE;
    }

    Result = SetupInstallFromInfSectionW(NULL,
                                         hInf,
                                         L"AUDIO_Inst.NT",
                                         SPINST_ALL,
                                         NULL,
                                         NULL,
                                         SP_COPY_NEWER,
                                         SetupDefaultQueueCallbackW,
                                         Context,
                                         NULL,
                                         NULL);

    if (Result)
    {
        Result = SetupInstallServicesFromInfSectionW(hInf,
                                                     L"Audio_Inst.NT.Services",
                                                     0);
    }

    SetupTermDefaultQueueCallback(Context);
    SetupCloseInfFile(hInf);



    hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
    if (!hSCManager)
    {
        return ERROR_DI_DO_DEFAULT;
    }

    hService = OpenService(hSCManager, L"RosAudioSrv", SERVICE_ALL_ACCESS);
    if (hService)
    {
        /* Make RosAudioSrv start automatically */
        ChangeServiceConfig(hService, SERVICE_NO_CHANGE, SERVICE_AUTO_START, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

        StartService(hService, 0, NULL);
        CloseServiceHandle(hService);
    }
    CloseServiceHandle(hSCManager);

    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Drivers32", 0, GENERIC_READ | GENERIC_WRITE, &hKey) == ERROR_SUCCESS)
    {
        szBuffer[Length] = '\0';
        pBuffer = PathAddBackslashW(szBuffer);
        wcscpy(pBuffer, L"system32\\wdmaud.drv");

        for(Index = 1; Index <= 4; Index++)
        {
            swprintf(WaveName, L"wave%u", Index);
            if (RegQueryValueExW(hKey, WaveName, 0, NULL, NULL, &BufferSize) != ERROR_MORE_DATA)
            {
                /* Store new audio driver entry */
                RegSetValueExW(hKey, WaveName, 0, REG_SZ, (LPBYTE)szBuffer, (wcslen(szBuffer)+1) * sizeof(WCHAR));
                break;
            }
            else
            {
                WCHAR Buffer[MAX_PATH];
                BufferSize = sizeof(Buffer);

                if (RegQueryValueExW(hKey, WaveName, 0, NULL, (LPBYTE)Buffer, &BufferSize) == ERROR_SUCCESS)
                {
                    /* Make sure the buffer is zero terminated */
                    Buffer[MAX_PATH-1] = L'\0';

                    if (!wcsicmp(Buffer, szBuffer))
                    {
                        /* An entry already exists */
                        break;
                    }
                }
            }
        }
        RegCloseKey(hKey);
    }
    InstallSystemSoundScheme();

    return ERROR_DI_DO_DEFAULT;

}
Exemple #2
0
/**
 * Executes a sepcified .INF section to install/uninstall drivers and/or services.
 *
 * @return  Exit code (EXIT_OK, EXIT_FAIL)
 * @param   pszSection          Section to execute; usually it's "DefaultInstall".
 * @param   iMode               Execution mode to use (see MSDN).
 * @param   pszInf              Full qualified path of the .INF file to use.
 */
int ExecuteInfFile(const _TCHAR *pszSection, int iMode, const _TCHAR *pszInf)
{
    _tprintf(_T("Installing from INF-File: %ws (Section: %ws) ...\n"),
             pszInf, pszSection);

    UINT uErrorLine = 0;
    HINF hINF = SetupOpenInfFile(pszInf, NULL, INF_STYLE_WIN4, &uErrorLine);
    if (hINF != INVALID_HANDLE_VALUE)
    {
        PVOID pvQueue = SetupInitDefaultQueueCallback(NULL);

        BOOL fSuccess = SetupInstallFromInfSection(NULL,
                                                    hINF,
                                                    pszSection,
                                                    SPINST_ALL,
                                                    HKEY_LOCAL_MACHINE,
                                                    NULL,
                                                    SP_COPY_NEWER_OR_SAME | SP_COPY_NOSKIP,
                                                    vboxDrvInstExecuteInfFileCallback,
                                                    pvQueue,
                                                    NULL,
                                                    NULL
                                                    );
        if (fSuccess)
        {
            _tprintf (_T( "File installation stage successful\n"));

            fSuccess = SetupInstallServicesFromInfSection(hINF,
                                                          L"DefaultInstall.Services",
                                                          0 /* Flags */);
            if (fSuccess)
            {
                _tprintf (_T( "Service installation stage successful. Installation completed\n"));
            }
            else
            {
                DWORD dwErr = GetLastError();
                switch (dwErr)
                {
                    case ERROR_SUCCESS_REBOOT_REQUIRED:
                        _tprintf (_T( "A reboot is required to complete the installation\n"));
                        break;

                    case ERROR_SECTION_NOT_FOUND:
                        break;

                    default:
                        _tprintf (_T( "Error %ld while installing service\n"), dwErr);
                        break;
                }
            }
        }
        else
            _tprintf (_T( "Error %ld while installing files\n"), GetLastError());

        if (pvQueue)
            SetupTermDefaultQueueCallback(pvQueue);

        SetupCloseInfFile(hINF);
    }
    else
        _tprintf (_T( "Unable to open %ws: %ld (error line %u)\n"),
                  pszInf, GetLastError(), uErrorLine);

    return EXIT_OK;
}
Exemple #3
0
int 
PreInstallFromInf(
    IN HWND hWnd,
    IN LPTSTR Inf,
    IN LPTSTR InstallSection,
    IN LPTSTR ServiceSection
    )
{
    DWORD Err = NO_ERROR;
    HINF hInf = INVALID_HANDLE_VALUE;
    UINT ErrorLine;
    PVOID Context = NULL;

    hInf = SetupOpenInfFile(Inf,
                            NULL,
                            INF_STYLE_WIN4,
                            &ErrorLine);
    if (hInf == INVALID_HANDLE_VALUE) {
        Err = GetLastError();
        goto clean;
    }

    //
    // Install the service section
    //
    if (!SetupInstallServicesFromInfSection(hInf,
                                            ServiceSection,
                                            0)) {
        Err = GetLastError();
        goto clean;
    }

    Context = SetupInitDefaultQueueCallback(hWnd);

    if (!SetupInstallFromInfSection(hWnd,
                                    hInf,
                                    InstallSection,
                                    SPINST_REGISTRY | SPINST_FILES,
                                    NULL,
                                    NULL,
                                    0,
                                    SetupDefaultQueueCallback,
                                    Context,
                                    NULL,
                                    NULL)) {
        Err = GetLastError();
        goto clean;
    }

clean:
    if (Context != NULL) {
        SetupTermDefaultQueueCallback(Context);
    }
    if (hInf != INVALID_HANDLE_VALUE) {
        SetupCloseInfFile(hInf);
    }
    if (Err == NO_ERROR) {
        return 0;
    } else {
        return 1;
    }
}
Exemple #4
0
int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow)
{
    if (!InitializeOptions(lpCmdLine))
    {
        if (!OptionSilent)
        {
            MessageBox(NULL, "Please specify the correct parameters:\r\n" \
                       "/path <Full path to the INF>\r\n" \
                       "/path:relative <Relative path to the INF from the current directory>\r\n" \
                       "/ddinstall <DDInstall section name to be processed>\r\n" \
                       "/os <Expected OS version in the form of x.y where x is MajorVersion, y is Minor version, ie 5.0 for Windows 2000>\r\n" \
                       "/buildnumber <Expected OS build number, ie 2195 for Windows 2000>\r\n" \
                       "/sp <Expected OS service pack number>\r\n",
                       "Pre-Installer",
                       MB_OK);

        }

        return ERR_FAIL;
    }

    if ((OptionOsVersionCheck) || (OptionOsBuildNumberCheck) || (OptionOsServicePackCheck))
    {
        OSVERSIONINFO OsVersionInfo;
        OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

        if (GetVersionEx(&OsVersionInfo))
        {
            if (OptionOsVersionCheck)
            {
                CHAR Version[32];

                sprintf(Version, "%d.%d", OsVersionInfo.dwMajorVersion, OsVersionInfo.dwMinorVersion);

                if (_stricmp(Version, ExpectedOsVersion))
                {
                    if (!OptionSilent)
                    {
                        CHAR ErrorMsg[256];
                        sprintf(ErrorMsg, "OS version %s doesn't match the expected %s", Version, ExpectedOsVersion);

                        MessageBox(NULL, ErrorMsg, "Pre-Installer", MB_OK);
                    }

                    return ERR_FAIL;
                }
            }

            if (OptionOsBuildNumberCheck)
            {
                if (OsVersionInfo.dwBuildNumber != ExpectedOsBuildNumber)
                {
                    if (!OptionSilent)
                    {
                        CHAR ErrorMsg[256];
                        sprintf(ErrorMsg, "OS build number %d doesn't match the expected %d", OsVersionInfo.dwBuildNumber, ExpectedOsBuildNumber);

                        MessageBox(NULL, ErrorMsg, "Pre-Installer", MB_OK);
                    }

                    return ERR_FAIL;
                }
            }

            if (OptionOsServicePackCheck)
            {
                CHAR ServicePack[32];

                sprintf(ServicePack, "Service Pack %d", ExpectedOsServicePack);

                if (_stricmp(OsVersionInfo.szCSDVersion, ServicePack))
                {
                    if (!OptionSilent)
                    {
                        CHAR ErrorMsg[256];
                        sprintf(ErrorMsg, "OS %s doesn't match the expected %s", OsVersionInfo.szCSDVersion, ServicePack);

                        MessageBox(NULL, ErrorMsg, "Pre-Installer", MB_OK);
                    }

                    return ERR_FAIL;
                }
            }
        }
        else
        {
            return ERR_FAIL;
        }
    }

    HINF InfHandle = SetupOpenInfFile(InfPath, NULL, INF_STYLE_WIN4 , NULL);	// Get INF Handle

    if (InfHandle != INVALID_HANDLE_VALUE)
    {
        HSPFILEQ QueueHandle = SetupOpenFileQueue();

        if (QueueHandle != INVALID_HANDLE_VALUE)
        {
            SetupInstallFilesFromInfSection(InfHandle, NULL, QueueHandle, DDInstallSection, NULL, SP_COPY_FORCE_NEWER);
            //Copies the files

            PVOID Context = SetupInitDefaultQueueCallback(NULL);

            if (Context)
            {
                SetupCommitFileQueue(NULL, QueueHandle, FileCallback, Context);

                SetupTermDefaultQueueCallback(Context);
            }

            SetupCloseFileQueue(QueueHandle);
        }

        // Do not do the following as we do not want to install the drivers yet. When the device is turned on,
        // Windows PnP will take care of the rest of the installation process.
#if 0
        CHAR DDInstallServicesSection[MAX_PATH];

        strcpy(DDInstallServicesSection, DDInstallSection);
        strcat(DDInstallServicesSection, ".Services");

        SetupInstallServicesFromInfSection(InfHandle, DDInstallServicesSection, SPSVCINST_TAGTOFRONT);

        HKEY RegKey = SetupDiOpenClassRegKey((LPGUID)&CLSID_MEDIA, KEY_ALL_ACCESS);

        if (RegKey != INVALID_HANDLE_VALUE)
        {
            SetupInstallFromInfSection(NULL, InfHandle, DDInstallSection, SPINST_REGISTRY, RegKey, NULL, NULL,
                                       NULL, NULL, NULL, NULL);		// Does the AddReg, Del Reg Stuff

            RegCloseKey(RegKey);
        }
#endif // 0

        SetupCloseInfFile(InfHandle);
    }

    if (SetupCopyOEMInf(InfPath, NULL, SPOST_PATH, NULL, NULL ,0, NULL, NULL))
    {
        return SUCCESS;
    }
    else
    {
        DWORD err = GetLastError();

        return ERR_FAIL;
    }
}