예제 #1
0
int __cdecl _tmain(int argc, _TCHAR *argv[])
{
	HDEVINFO h = NULL;
	SP_DEVINFO_DATA dev_info_data;
	ULONG status = 0, problem = 0;
	BOOL bDevice = FALSE;

	if (IsWow64()) {
		logPrint("Your are runing 32bit VirtualMonitor on 64bit windows\n");
		logPrint("Please Download 64bit version of VirtualMonitor\n");
		return -1;
	}
	if (argc < 2 || !strcmp(argv[1], "-h")) {
		usage(argv);
		goto out;
	}

	GetWinVersion();
	if (!isSupport) {
		logPrint("Unsupported Windows system\n");
		goto out;
	}
	if (isVista || isWin7) {
		if (!IsUserAnAdmin()) {
			logPrint("Access Denied. Administrator permissions are needed to use the selected options.");
			logPrint("Use an administrator command prompt to complete these tasks.");
			goto out;
		}
	}

	if (!strcmp(argv[1], "-i")) {
		FixInfFile(INF);
	}
	h = GetDevInfoFromDeviceId(&dev_info_data, DRIVER_NAME);
	if (!strcmp(argv[1], "-i")) {
		if (h) {
			logPrint("Driver already installed\n");
			goto out;
		}
		if (!logInit()) {
			goto out;
		}
		logPrint("Installing driver, It may take few minutes. please wait\n");
		RegClean();
		InstallInf(INF);
		if (isVista || isWin7) {
			DisableMirror();
		}
		h = GetDevInfoFromDeviceId(&dev_info_data, DRIVER_NAME);
		if (!h) {
			logError("GetDevInfo Failed After Driver Installed\n");
		}
		GetDevStatus(h, &dev_info_data, &status, &problem);
		bDevice = DetectVirtualMonitor(FALSE);
		logInfo("Driver Status: %x, problem: %x\n", status, problem);
		if (!bDevice) {
			DetectVirtualMonitor(TRUE);
			logPrint("Driver installed Status: %x, problem: %x\n", status, problem);
			logPrint("Please reboot your system\n");
		} else {
			logPrint("Driver installed successful\n");
		}
		if (isVista || isWin7) {
			logPrint("Please reboot your system\n");
		}
	} else if (!strcmp(argv[1], "-u")) {
		if (!h) {
			logPrint("Driver not found\n");
		} else {
			if (!logInit()) {
				goto out;
			}
			UnInstallDriver(h, &dev_info_data);
			if (isVista || isWin7) {
				CleanOemInf();
			}
			RegClean();
			logPrint("Driver Uninstalled sucessful, Please Reboot System\n");
		}
	} else {
		usage(argv);
		goto out;
	}
out:
	if (g_logf)
		fclose(g_logf);
	if (h) {
			DestroyDevInfo(h);
	}
	exit(0);
}
예제 #2
0
파일: Common.cpp 프로젝트: KimTaehee/vdesk
HDEVINFO GetDevInfoFromDeviceId(SP_DEVINFO_DATA *dev_info_data, CHAR *device_id)
{
    HDEVINFO dev_info;
    SP_DEVINFO_DATA data;
    UINT i;
    BOOL found;
    CHAR *buffer;
    UINT buffer_size = 8092;
    DWORD required_size;
    DWORD data_type;

    dev_info = SetupDiGetClassDevsEx(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT, NULL, NULL, NULL);
    if (dev_info == NULL)
    {
        return NULL;
    }

#if 0
    SP_DEVINFO_LIST_DETAIL_DATA detail_data;
    memset(&detail_data, 0, sizeof(detail_data));
    detail_data.cbSize = sizeof(detail_data);
    if (SetupDiGetDeviceInfoListDetail(dev_info, &detail_data) == FALSE)
    {
        DestroyDevInfo(dev_info);
        return NULL;
    }
#endif

    memset(&data, 0, sizeof(data));
    data.cbSize = sizeof(data);
    found = FALSE;
    buffer = (LPTSTR)LocalAlloc(LPTR, buffer_size);
    if (!buffer) {
        printf("Alloc: %x\n", GetLastError());
        goto out;
    }

    for (i = 0; SetupDiEnumDeviceInfo(dev_info, i, &data); i++) {
        while (!SetupDiGetDeviceRegistryProperty(dev_info,
                &data,
                SPDRP_HARDWAREID,
                &data_type,
                (PBYTE)buffer,
                buffer_size,
                &required_size)) {
            if (ERROR_INSUFFICIENT_BUFFER == GetLastError()) {
                // Change the buffer size.
                if (buffer) {
                    LocalFree(buffer);
                }
                // Double the size to avoid problems on
                // W2k MBCS systems per KB 888609.
                buffer_size *= 2;
                buffer = (LPTSTR)LocalAlloc(LPTR, buffer_size);
                if (!buffer) {
                    printf("LocalAlloc: %x\n", GetLastError());
                    goto out;
                }
            } else {
                // EnumNext
                break;
            }
        }

        if (stricmp(buffer, device_id) == 0) {
            found = TRUE;
        }

        if (found) {
            goto out;
        }

        memset(&data, 0, sizeof(data));
        data.cbSize = sizeof(data);
    }
out:
    if (buffer)
        LocalFree(buffer);
    if (found == FALSE) {
        DestroyDevInfo(dev_info);
        return NULL;
    } else {
        memcpy(dev_info_data, &data, sizeof(data));
        return dev_info;
    }
}