⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regax.cpp

📁 Windows设备驱动自动注册代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// regax.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "regax.h"
#include "RegKey.h"

#include <stdio.h> 
#include <tchar.h> // Make all functions UNICODE safe.
#include <windows.h> 
#include <newdev.h> // for the API UpdateDriverForPlugAndPlayDevices().
#include <setupapi.h> // for SetupDiXxx functions.
//CAutoInstall g_AutoInstall;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define  MPG4C32_DLL        "SAA7134.sys"//"MPG4c32.dll"
#define  MPG4DS32_AX        "Mpg4ds32.ax"
#define  NEW_MPG4VKI_INF    "SAA7134.inf"//"New_Mpg4vki.inf"

/////////////////////////////////////////////////////////////////////////////
// CRegaxApp

BEGIN_MESSAGE_MAP(CRegaxApp, CWinApp)
	//{{AFX_MSG_MAP(CRegaxApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRegaxApp construction

CRegaxApp::CRegaxApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CRegaxApp object

CRegaxApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CRegaxApp initialization

BOOL CRegaxApp::InitInstance()
{
	CString   sysDir,curdir,winDir,infDir,srcStr,srcTemp,desTemp,runfile,szTemp;
	//
	OSVERSIONINFO  infoOsVersion ;
	BOOL bIsWin98 = FALSE ;
	//
	infoOsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ;
	::GetVersionEx(&infoOsVersion) ;
	bIsWin98 = (infoOsVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) ;

	//Get Source Path 
	GetModuleFileName( NULL, srcStr.GetBuffer(MAX_PATH), MAX_PATH );
	srcStr.ReleaseBuffer();
	srcStr  =  srcStr.Left( srcStr.ReverseFind('\\') + 1 );
	//Get SysPath
    :: GetSystemDirectory (sysDir.GetBuffer(MAX_PATH), MAX_PATH); 
	strcat(sysDir.GetBuffer(MAX_PATH),"\\");
	//Get WinPath
    :: GetWindowsDirectory (winDir.GetBuffer(MAX_PATH), MAX_PATH); 
	strcat(winDir.GetBuffer(MAX_PATH),"\\");
	//Get inf path
	strcpy(infDir.GetBuffer(MAX_PATH),winDir);
	strcat(infDir.GetBuffer(MAX_PATH),"inf");
	strcat(infDir.GetBuffer(MAX_PATH),"\\");
//
	//Copy dll file 
	strcpy(srcTemp.GetBuffer(MAX_PATH),srcStr);
	strcat(srcTemp.GetBuffer(MAX_PATH),MPG4C32_DLL);
	strcpy(desTemp.GetBuffer(MAX_PATH),sysDir);
	strcat(desTemp.GetBuffer(MAX_PATH), "drivers\\");
	strcat(desTemp.GetBuffer(MAX_PATH),MPG4C32_DLL);
	//
	::CopyFile(srcTemp,desTemp,FALSE);
	srcTemp.Empty();
	desTemp.Empty();
	//Copy inf file
    strcpy(srcTemp.GetBuffer(MAX_PATH),srcStr);
	strcat(srcTemp.GetBuffer(MAX_PATH),NEW_MPG4VKI_INF);
	strcpy(desTemp.GetBuffer(MAX_PATH),infDir);
	strcat(desTemp.GetBuffer(MAX_PATH),NEW_MPG4VKI_INF);
	//
	strcpy(strinffile, srcTemp);
	//strcpy(strHardwareID, "PCI\\VEN_1131&DEV_7134&SUBSYS_00001131&REV_01");
	strcpy(strHardwareID, "PCI\\VEN_1131&DEV_7134&SUBSYS_FFFFFFFF&REV_01");

    ::CopyFile(srcTemp,desTemp,FALSE);
	
	//Copy ax file
	/*
	strcpy(srcTemp.GetBuffer(MAX_PATH),srcStr);
	strcat(srcTemp.GetBuffer(MAX_PATH),MPG4DS32_AX);
	strcpy(desTemp.GetBuffer(MAX_PATH),sysDir);
	strcat(desTemp.GetBuffer(MAX_PATH),MPG4DS32_AX);
	
	//
    ::CopyFile(srcTemp,desTemp,FALSE);
    //register ax
	ShellExecute(NULL,"regsvr32.exe",desTemp,NULL, NULL,SW_SHOWNORMAL);
	*/
	//install mpg4
	CRegKey regKey;
//	long reg = regKey.RegOpen( HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Enum" );
//	if ( reg )
	{
//		reg = regKey.RegWrite( "77777777", "777" );
	}
	
	if(bIsWin98)
	{
		strcpy(runfile.GetBuffer(MAX_PATH),winDir);
		strcat(runfile.GetBuffer(MAX_PATH),"rundll32.exe");
		//
		strcpy(szTemp.GetBuffer(MAX_PATH),sysDir);
		strcat(szTemp.GetBuffer(MAX_PATH),"setupapi,InstallHinfSection DefaultInstall 132 ");
		strcat(szTemp.GetBuffer(MAX_PATH),srcStr);
		strcat(szTemp.GetBuffer(MAX_PATH),NEW_MPG4VKI_INF);
		//
		ShellExecute(NULL,"open",runfile,szTemp, NULL,SW_SHOWNORMAL);
	}
	else
	{
		strcpy(runfile.GetBuffer(MAX_PATH),sysDir);
		strcat(runfile.GetBuffer(MAX_PATH),"rundll32.exe");
		//
		strcpy(szTemp.GetBuffer(MAX_PATH),sysDir);
		strcat(szTemp.GetBuffer(MAX_PATH),"setupapi,InstallHinfSection DefaultInstall 132 ");
		strcat(szTemp.GetBuffer(MAX_PATH),srcStr);
		strcat(szTemp.GetBuffer(MAX_PATH),NEW_MPG4VKI_INF);
		//
		HINSTANCE she = 0; 
	//	she = ShellExecute(NULL,"open",runfile,szTemp, NULL,SW_SHOWNORMAL);
	//	ERROR_FILE_NOT_FOUND 
	}

	_TCHAR *argv[3];
	argv[1] = strinffile;
	argv[2] = strHardwareID;
	_TCHAR **envp = NULL;
	process( 3, argv, envp );

	
	return TRUE;
}
/////////////////////////////////////////////////////







//////////////////////////////////////////////////////
/*++

Copyright (c) 1999-2000  Microsoft Corporation

Module Name:

    Install.c

Abstract:

    Console app for the installation of Device Drivers in Windows 2000.

Environment:

    user mode only

Notes:

  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  PURPOSE.

  Copyright (c) 1999-2000 Microsoft Corporation.  All Rights Reserved.


Revision History:

  9/22/99: Created Keith S. Garner, with input from Eliyas and others.

--*/

#define MAX_CLASS_NAME_LEN 32 // Stolen from <cfgmgr32.h>


int CRegaxApp::DisplayError(TCHAR * ErrorName)
/*++
Routine Description:

    This Routine will display the LastError in human readable 
    form when possible.

    If the return value is a 32-bit number, and falls in the range:
        ERROR_NO_ASSOCIATED_CLASS   0xE0000200 
    To
        ERROR_CANT_REMOVE_DEVINST   0xE0000232 
    The values defined in setupapi.h can help to determine the error.
    Start by searching for the text string ERROR_NO_ASSOCIATED_CLASS.
  
Arguments:
    
    ErrorName: Human readable description of the last Function called.

Return Value:
    
    Allways returns FALSE.
      
--*/
{
    DWORD Err = GetLastError();
    LPVOID lpMessageBuffer = NULL;
    
    if (FormatMessage( 
        FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
        NULL, 
        Err,  
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMessageBuffer,  
        0,  
        NULL ))
        _tprintf(TEXT("%s FAILURE: %s\n"),ErrorName,(TCHAR *)lpMessageBuffer);
    else 
        _tprintf(TEXT("%s FAILURE: (0x%08x)\n"),ErrorName,Err);
    
    if (lpMessageBuffer) LocalFree( lpMessageBuffer ); // Free system buffer 
    
    SetLastError(Err);    
    return FALSE;
}

BOOL CRegaxApp::FindExistingDevice(IN LPTSTR HardwareId)
/*++

Routine Description:

    This routine finds an existing devnode if present.

Arguments:

    HardwareIdList - Supplies a string containing a hardware ID to 
    be associated with the device.

Return Value:

    The function returns TRUE if it is successful. 

    Otherwise it returns FALSE and the logged error can be retrieved 
    with a call to GetLastError. 

    The most common error will be ERROR_NO_MORE_ITEMS, which means the 
    function could not find a devnode with the HardwareID.

--*/
{
    HDEVINFO DeviceInfoSet;
    SP_DEVINFO_DATA DeviceInfoData;
    DWORD i,err;
    BOOL Found;
    
    //
    // Create a Device Information Set with all present devices.
    //
    DeviceInfoSet = SetupDiGetClassDevs(NULL, // All Classes
        0,
        0, 
        DIGCF_ALLCLASSES | DIGCF_PRESENT ); // All devices present on system
    if (DeviceInfoSet == INVALID_HANDLE_VALUE)
    {
        return DisplayError(TEXT("GetClassDevs(All Present Devices)"));        
    }
    
    _tprintf(TEXT("Search for Device ID: [%s]\n"),HardwareId);
    
    //
    //  Enumerate through all Devices.
    //
    Found = FALSE;
    DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
    for (i=0;SetupDiEnumDeviceInfo(DeviceInfoSet,i,&DeviceInfoData);i++)
    {
        DWORD DataT;
        LPTSTR p,buffer = NULL;
        DWORD buffersize = 0;
        
        //
        // We won't know the size of the HardwareID buffer until we call
        // this function. So call it with a null to begin with, and then 
        // use the required buffer size to Alloc the nessicary space.
        // Keep calling we have success or an unknown failure.
        //
        while (!SetupDiGetDeviceRegistryProperty(
            DeviceInfoSet,
            &DeviceInfoData,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -