Page 1 of 1

Program runs in IDE, not in exe

Posted: Sun May 26, 2024 9:12 am
by morosh
Hello:
The following program runs correctly in IDE and detect the usb-to serial com port, but not if compiled as standalone exe (always no com detected):

Code: Select all

Global comport.s, dumy1.s, dumy.s, prog.l
dpix = DesktopResolutionX()
dpiy = DesktopResolutionY()

ExamineDesktops()
wid=0.5*DesktopWidth(0)/dpix
hei=DesktopHeight(0)/dpiy-65
Debug #PB_Compiler_Version
  
OpenWindow(0,40,0,wid,hei,"Test1",#PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)

dumy = "path win32_pnpentity where " + #DQUOTE$ + "PNPClass='Ports'" + #DQUOTE$ + " get Caption"
prog = RunProgram("wmic.exe", dumy, "", #PB_Program_Open|#PB_Program_Read|#PB_Program_Hide)
If prog
  While ProgramRunning(prog)
    If AvailableProgramOutput(prog)
      dumy1 = ReadProgramString(prog)
      Debug dumy1
      Debug FindString(dumy1,"Prolific USB-to-Serial Comm Port",1)
      If FindString(dumy1,"Prolific USB-to-Serial Comm Port")
        dumy1=ReplaceString(dumy1,"Prolific USB-to-Serial Comm Port (COM","")
        dumy1=ReplaceString(dumy1,")","")
        dumy1=Trim(dumy1)
        comport=dumy1
        Break
      EndIf
    EndIf
  Wend
  Debug dumy1
  CloseProgram(prog)
EndIf

If comport <> ""
  MessageRequester("info","com"+comport+" detected")
Else
  MessageRequester("info","no com detected")
EndIf

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
    
    
you should have a usb to serial connected

Any tips?
Thanks in advance

using W10 - PB6.11b2-x86 asm

Re: Program runs in IDE, not in exe

Posted: Sun May 26, 2024 1:10 pm
by infratec
Maybe you need:

Code: Select all

dumy = "/C wmic path win32_pnpentity where " + #DQUOTE$ + "PNPClass='Ports'" + #DQUOTE$ + " get Caption"
prog = RunProgram("cmd", dumy, "", #PB_Program_Open|#PB_Program_Read|#PB_Program_Hide)

Re: Program runs in IDE, not in exe

Posted: Sun May 26, 2024 2:10 pm
by morosh
Unfortunately, this didn't works
Finally, I specified the full path of wmic, and it works:
RunProgram("C:\Windows\SysWOW64\wbem\wmic.exe", dumy, "", #PB_Program_Open|#PB_Program_Read|#PB_Program_Hide)
It seems that "C:\Windows\SysWOW64\wbem\" is included in the search path from inside PB, and not in a standalone exe.

Thank you