bool LinnStrumentSerialWindows::detect()
{
    if (!hasFirmwareFile()) return false;

    linnstrumentDevice = String::empty;

	DISPATCH_OBJ(wmiSvc);
	DISPATCH_OBJ(colDevices);
	dhInitialize(TRUE);
	dhToggleExceptions(TRUE);
	dhGetObject(L"winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2", NULL, &wmiSvc);
	// only use entities that are COM ports with the vendor and product ID of LinnStrument
	dhGetValue(L"%o", &colDevices, wmiSvc, L".ExecQuery(%S)", L"SELECT * from Win32_PnPEntity WHERE Name LIKE \"%(COM%\" AND PnPDeviceID LIKE \"%VID_F055&PID_0070%\"");
	FOR_EACH(objDevice, colDevices, NULL)
	{
		char* name = NULL;
		char* pnpid = NULL;
		char* match;
		dhGetValue(L"%s", &name, objDevice, L".Name");
		dhGetValue(L"%s", &pnpid, objDevice, L".PnPDeviceID");
		if (name != NULL && pnpid != NULL && (match = strstr(name, "(COM")) != NULL)
		{
			char* comname = strtok(match, "()");
			linnstrumentDevice = String(comname);
			printf("Found LinnStrument %s - %s\n", comname, pnpid);
		}
		dhFreeString(name);
		dhFreeString(pnpid);
	}
/* **************************************************************************
 * EmailOutlook:
 *   Demonstrates sending an email using Outlook. Note that the user will be
 * prompted as a security measure.
 *
 ============================================================================ */
HRESULT EmailOutlook(LPCTSTR szTo, LPCTSTR szSubject, LPCTSTR szBody)
{
	DISPATCH_OBJ(olApp);
	DISPATCH_OBJ(olMsg);
	HRESULT hr;

	if (SUCCEEDED(hr = dhCreateObject(L"Outlook.Application", NULL, &olApp) ) &&
	    SUCCEEDED(hr = dhGetValue(L"%o", &olMsg, olApp, L".CreateItem(%d)", 0) ) ) /* olMailItem */
	{
		dhPutValue(olMsg, L".Subject = %T", szSubject);
		dhPutValue(olMsg, L".To = %T", szTo);
		dhPutValue(olMsg, L".Body = %T", szBody);

		/* To add an attachment:
		 * dhCallMethod(olMsg, L".Attachments.Add(%T)", "FilePath.ext");
		 */

		/* Display and attempt to send email */
		dhCallMethod(olMsg, L".Display");
		hr = dhCallMethod(olMsg, L".Send");
	}

	SAFE_RELEASE(olMsg);
	SAFE_RELEASE(olApp);

	return hr;
}
/*
 * listComPorts.c -- list COM ports
 *
 * http://github.com/todbot/usbSearch/
 *
 * 2012, Tod E. Kurt, http://todbot.com/blog/
 *
 *
 * Uses DispHealper : http://disphelper.sourceforge.net/
 *
 * Notable VIDs & PIDs combos:
 * VID 0403 - FTDI
 *
 * VID 0403 / PID 6001 - Arduino Diecimila
 *
 */
void GetAdapterList(uv_work_t* req) {
    AdapterListBaton* data = static_cast<AdapterListBaton*>(req->data);

    {
        DISPATCH_OBJ(wmiSvc);
        DISPATCH_OBJ(colDevices);

        dhInitialize(TRUE);
        dhToggleExceptions(FALSE);

        dhGetObject(L"winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2", NULL, &wmiSvc);
        dhGetValue(L"%o", &colDevices, wmiSvc, L".ExecQuery(%S)", L"Select * from Win32_PnPEntity");

        FOR_EACH(objDevice, colDevices, NULL) {
            char* name = NULL;
            char* pnpid = NULL;
            char* manu = NULL;
            char* match;

            dhGetValue(L"%s", &name,  objDevice, L".Name");
            dhGetValue(L"%s", &pnpid, objDevice, L".PnPDeviceID");

            if( name != NULL && ((match = strstr( name, "(COM" )) != NULL) ) { // look for "(COM23)"
                // 'Manufacturuer' can be null, so only get it if we need it
                dhGetValue(L"%s", &manu, objDevice,  L".Manufacturer");

                if(strcmp("SEGGER", manu) == 0)
                {
                    char* comname = strtok( match, "()");
                    AdapterListResultItem* resultItem = new AdapterListResultItem();
                    resultItem->comName = comname;
                    resultItem->manufacturer = manu;
                    resultItem->pnpId = pnpid;
                    data->results.push_back(resultItem);
                }

                dhFreeString(manu);
              }

            dhFreeString(name);
            dhFreeString(pnpid);
        } NEXT(objDevice);

        SAFE_RELEASE(colDevices);
        SAFE_RELEASE(wmiSvc);

        dhUninitialize(TRUE);
    }
/* **************************************************************************
 * EmailCDO:
 *   Demonstrates sending an email using CDO for Windows 2000. Requires
 * Windows 2000/XP+.
 * See http://www.microsoft.com/technet/community/scriptcenter/entscr/scrent16.mspx
 *
 ============================================================================ */
HRESULT EmailCDO(LPCTSTR szServer, LPCTSTR szFrom, LPCTSTR szTo, LPCTSTR szSubject, LPCTSTR szBody)
{
	DISPATCH_OBJ(cdoMsg);
	HRESULT hr;

	if (FAILED(hr = dhCreateObject(L"CDO.Message", NULL, &cdoMsg))) return hr;

	dhPutValue(cdoMsg, L".Configuration.Fields(%S) = %d", L"http://schemas.microsoft.com/cdo/configuration/sendusing", 2); /* cdoSendUsingPort */
	dhPutValue(cdoMsg, L".Configuration.Fields(%S) = %T", L"http://schemas.microsoft.com/cdo/configuration/smtpserver", szServer);
	dhCallMethod(cdoMsg, L".Configuration.Fields.Update");

	dhPutValue(cdoMsg, L".MimeFormatted = %b", TRUE);

	dhPutValue(cdoMsg, L".Sender = %T", szFrom);
	dhPutValue(cdoMsg, L".To = %T", szTo);
	dhPutValue(cdoMsg, L".Subject = %T", szSubject);
	dhPutValue(cdoMsg, L".TextBody = %T", szBody);   /* Use .HTMLBody if needed. */

	/* To add an attachment:
	 * dhCallMethod(cdoMsg, L".AddAttachment(%T)", TEXT("file://C:\\my file.zip"));
	 */

	hr = dhCallMethod(cdoMsg, L".Send");

	SAFE_RELEASE(cdoMsg);

	return hr;
}
Exemple #5
0
int listComPorts(void)
{
    if(verbose)
        printf("Searching for COM ports...\n");

    DISPATCH_OBJ(wmiSvc);
    DISPATCH_OBJ(colDevices);

    dhInitialize(TRUE);
    dhToggleExceptions(TRUE);
 
    dhGetObject(L"winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2",
    //dhGetObject(L"winmgmts:\\\\.\\root\\cimv2",
                NULL, &wmiSvc);
    dhGetValue(L"%o", &colDevices, wmiSvc, 
               L".ExecQuery(%S)",  
               L"Select * from Win32_PnPEntity");


    int port_count = 0;

    FOR_EACH(objDevice, colDevices, NULL) {
        
        char* name = NULL;
        char* pnpid = NULL;
        char* manu = NULL;
        char* match;

        dhGetValue(L"%s", &name,  objDevice, L".Name");
        dhGetValue(L"%s", &pnpid, objDevice, L".PnPDeviceID");
                                                
        if( name != NULL && ((match = strstr( name, "(COM" )) != NULL) ) { // look for "(COM23)"
            // 'Manufacturuer' can be null, so only get it if we need it
            dhGetValue(L"%s", &manu, objDevice,  L".Manufacturer");
            port_count++;
            char* comname = strtok( match, "()");
            printf("%s - %s - %s\n",comname, manu, pnpid);
            dhFreeString(manu);
        }
        
        dhFreeString(name);
        dhFreeString(pnpid);
        
    } NEXT(objDevice);
std::string __stdcall GetComputerString(int length)
{

 	DISPATCH_OBJ(wmiSvc);
	DISPATCH_OBJ(colMedia);
    DISPATCH_OBJ(colCPU);


    std::string uniqueIdentifier = "";
    CDispPtr ColProcesador;

	dhInitialize(TRUE);
	dhToggleExceptions(TRUE);




	dhGetObject(L"winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2", NULL, &wmiSvc);
	dhGetValue(L"%o", &colMedia, wmiSvc, L".ExecQuery(%S)",  L"SELECT * FROM Win32_PhysicalMedia");
    dhGetValue(L"%o", &colCPU, wmiSvc, L".ExecQuery(%S)",  L"SELECT * FROM Win32_Processor");



	FOR_EACH(wmiCPUItem, colCPU, NULL)
	{
        char *pszCPUCaption = NULL;



        dhGetValue(L"%s", &pszCPUCaption, wmiCPUItem, L".Caption");
        if (pszCPUCaption)
        {
            uniqueIdentifier = uniqueIdentifier + string(pszCPUCaption);
        }

        dhFreeString(pszCPUCaption);

	} NEXT(wmiCPUItem);
/* **************************************************************************
 * EmailEudora:
 *   Demonstrates sending an email using Eudora. Automation must be enabled in
 * Eudora's options. See http://www.scripting.com/specials/eudoraAutomation.html
 *
 ============================================================================ */
HRESULT EmailEudora(LPCTSTR szTo, LPCTSTR szSubject, LPCTSTR szBody)
{
	DISPATCH_OBJ(euApp);
	HRESULT hr;

	if (SUCCEEDED(hr = dhCreateObject(L"Eudora.EuApplication.1", NULL, &euApp)))
	{
		/* Note: Empty arguments are CC, BCC and Attachments respectively. */
		hr = dhCallMethod(euApp, L".QueueMessage(%T,%T,%T,%T,%T,%T)",
					 szTo, szSubject, TEXT(""), TEXT(""), TEXT(""), szBody);

		dhCallMethod(euApp, L"SendQueuedMessages");
		dhCallMethod(euApp, L"CloseEudora");

		SAFE_RELEASE(euApp);
	}

	return hr;
}
int listComPorts(void)
{

    if(verbose)
        printf("Searching for COM ports...\n");

    DISPATCH_OBJ(wmiSvc);
    DISPATCH_OBJ(colDevices);

    dhInitialize(TRUE);
    dhToggleExceptions(TRUE);

    dhGetObject(L"winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2",
                //dhGetObject(L"winmgmts:\\\\.\\root\\cimv2",
                NULL, &wmiSvc);
    dhGetValue(L"%o", &colDevices, wmiSvc,
               L".ExecQuery(%S)",
               L"Select * from Win32_PnPEntity");


    int port_count = 0;
    int error = 1;
    int found = 0;
    dhToggleExceptions(FALSE);

    FOR_EACH(objDevice, colDevices, NULL) {

        char* name = NULL;
        char* pnpid = NULL;
        char* manu = NULL;
        char* match;

        dhGetValue(L"%s", &name,  objDevice, L".Name");
        dhGetValue(L"%s", &pnpid, objDevice, L".PnPDeviceID");

        if(verbose>1) printf("'%s'.\n", name);
        if( name != NULL && ((match = strstr( name, "(COM" )) != NULL) ) { // look for "(COM23)"
            char* comname = strtok( match, "()");
            // 'Manufacturuer' can be null, so only get it if we need it
            dhGetValue(L"%s", &manu, objDevice,  L".Manufacturer");
            port_count++;

            if (VIDstr != NULL) { //Are we searching for a VID
                if( pnpid != NULL && ((match = strstr( pnpid, VIDstr )) != NULL) ) {// If searching for VID
                    printf("%s\n",comname);
                    error = 0;
                }
            } else if (papilio) {
                if( pnpid != NULL && ((match = strstr( pnpid, "VID_0403+PID_6010" )) != NULL) ) {// If searching for Papilio FPGA serial
                    printf("%s\n",comname);
                    found = 1;
                    error = 0;
                }
                else {
                    if (!found) {
                        //printf("No Papilio port detected.");
                        error = 1;
                    }
                }
            } else if (papilioduo) {
                if( pnpid != NULL && ((match = strstr( pnpid, "VID_0403+PID_7BC0" )) != NULL) ) {// If searching for Papilio DUO FPGA serial
                    printf("%s\n",comname);
                    found = 1;
                    error = 0;
                }
                else {
                    if (!found) {
                        //printf("No Papilio port detected.");
                        error = 1;
                    }
                }
            } else if (arduino) {
                if( pnpid != NULL && ((match = strstr( pnpid, "VID_1D50&PID_60A5&MI_00" )) != NULL) ) {// If searching for Papilio FPGA serial
                    printf("%s\n",comname);
                    found = 1;
                    error = 0;
                }
                else {
                    if (!found) {
                        //printf("No Arduino port detected.");
                        error = 1;
                    }
                }
            } else if (bootloader) {
                if( pnpid != NULL && ((match = strstr( pnpid, "VID_1D50&PID_60A4" )) != NULL) ) {// If searching for Papilio FPGA serial
                    printf("%s\n",comname);
                    found = 1;
                    error = 0;
                }
                else {
                    if (!found) {
                        //printf("No Arduino port detected.");
                        error = 1;
                    }
                }
            } else {
                if(verbose)
                    printf("%s - %s - %s - %s\n",comname, name, manu, pnpid);
                else
                    printf("%s - %s \n",comname, name);
                error = 0;
            }
            dhFreeString(manu);
        }

        dhFreeString(name);
        dhFreeString(pnpid);

    }