Announcement

Collapse
No announcement yet.

I need to check for existence of a device before installation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I need to check for existence of a device before installation

    I want a Pre-Installation verification that our device is connected before continuing.
    If the following not true, pop up a message and exit: wmic path CIM_LogicalDevice where "Caption like 'ATS ESCOPE%'" get /value

    Can this be done?

  • #2
    I am not familiar with wmic - would you be able to provide a working command which would give out a similar output for something common, e.g. a network card, so I can run some tests?

    Ulrich

    Comment


    • #3
      I can write a powershell script to run the following command, if I can run the powershell before setup is allowed to continue.
      Basically, I want to make sure then own our device an have it connected before the setup is allowed to run.

      If device is true then continue, else popup message alerting them the setup cannot run and exit

      C:\Users\jeff>wmic path CIM_LogicalDevice where "Caption like 'ATS ESCOPE%'" get /value


      Availability=
      Caption=ATS eSCOPE ELITE4
      ClassGuid={88bae032-5a81-49f0-bc3d-a4ff138216d6}
      CompatibleID={"USB\MS_COMP_WINUSB","USB\Class_FF&a mp;SubClass_F0&Prot_00","USB\Class_FF&SubC lass_F0","USB\Class_FF"}
      ConfigManagerErrorCode=0
      ConfigManagerUserConfig=FALSE
      CreationClassName=Win32_PnPEntity
      Description=WinUsb Device
      DeviceID=USB\VID_1FC9&PID_81AD\ABCD123456789
      ErrorCleared=
      ErrorDescription=
      HardwareID={"USB\VID_1FC9&PID_81AD&REV_010 0","USB\VID_1FC9&PID_81AD"}
      InstallDate=
      LastErrorCode=
      Manufacturer=WinUsb Device
      Name=ATS eSCOPE ELITE4
      PNPClass=USBDevice
      PNPDeviceID=USB\VID_1FC9&PID_81AD\ABCD12345678 9
      PowerManagementCapabilities=
      PowerManagementSupported=
      Present=TRUE
      Service=WINUSB
      Status=OK
      StatusInfo=
      SystemCreationClassName=Win32_ComputerSystem
      SystemName=DESKTOP-T25050G

      If the device is not connected, this will be the response:

      c:\Users\jeff>wmic path CIM_LogicalDevice where "Caption like 'ATS ESCOPE%'" get /value
      No Instance(s) Available.

      Comment


      • #4
        Here are two solutions for you. Place this code into your project and see which works better for you:

        Code:
        local sProg = SessionVar.Expand("%SystemFolder%\\wbem\\WMIC.exe");
        local sArgs = "PATH CIM_LogicalDevice WHERE \"CAPTION LIKE 'ATS ESCOPE%'\" GET /VALUE";
        local sCmd =  sProg .. " " .. sArgs;
        
        SetupData.WriteToLogFile("Info\t" .. sArgs .. "\r\n", true);
        
        -- this will show a window on the screen while WMIC is working
        local sOutput = "";
        for line in io.popen(sCmd):lines() do
            sOutput = sOutput .. line;
        end
        Dialog.Message("WMIC (1)", sOutput);
        
        -- this will not show a window on the screen while WMIC is working
        local sTempFile = SessionVar.Expand("%TempFolder%\\wmic-output.txt")
        sArgs = "/OUTPUT:\"" .. sTempFile .. "\" " .. sArgs;
        SetupData.WriteToLogFile("Info\t" .. sArgs .. "\r\n", true);
        StatusDlg.Show();
        StatusDlg.SetTitle(SessionVar.Expand("%ProductName% Setup"));
        StatusDlg.SetMessage("Checking your system");
        StatusDlg.SetStatusText("This may take a moment...");
        StatusDlg.ShowCancelButton(false);
        StatusDlg.ShowProgressMeter(false);
        StatusDlg.SetAutoSize(true);
        File.Run(sProg, sArgs, "", SW_HIDE, true);
        StatusDlg.Hide();
        if File.DoesExist(sTempFile) then
            -- WMIC outputs Unicode, which is not directly supported, use my Encoding plugin to load file successfully
            sOutput = Encoding.ReadToString(sTempFile, "unicode", "windows-1252")
            Dialog.Message("WMIC (2)", sOutput);
            File.Delete(sTempFile);
        end
        In both cases, you would search the contents of sOutput for the necessary/expected string and decide what to do next. But this should give you some ideas.

        Ulrich
        Last edited by Ulrich; 04-23-2020, 04:31 PM.

        Comment

        Working...
        X