Announcement

Collapse
No announcement yet.

How to list out the program names which are connecting to Internet

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

  • How to list out the program names which are connecting to Internet

    Hi

    Pierre's code for getTcptable in
    https://forum.powerbasic.com/forum/u...271#post778271

    is very good, but need to be upgraded to identify which program actually establish or trying to connect to an external IP

    To identify these programs, I need to know what the names of calling programs and their paths. How to get these program names?

    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "Win32api.inc"
    #INCLUDE "ipHlpApi.inc"
    
    DECLARE FUNCTION GetNameInfo LIB "ws2_32.dll" ALIAS "getnameinfo" _
    (BYREF sa AS SOCKADDR, BYVAL salen AS LONG, BYREF HOST AS ASCIIZ, BYVAL hostlen AS DWORD, _
     BYREF serv AS ASCIIZ, BYVAL servlen AS DWORD, BYVAL flags AS LONG) AS LONG
    
    $AppName = "GetTcpTable"
    '_____________________________________________________________________________
    
    FUNCTION PortToString(BYVAL WordVar AS WORD) AS STRING
     LOCAL pWordVar AS BYTE POINTER
    
     pWordVar = VARPTR(WordVar)
     SWAP @pWordVar[0], @pWordVar[1]
     FUNCTION = FORMAT$(WordVar)
    
    END FUNCTION
    '______________________________________________________________________________
    
    FUNCTION DwIpMirror(BYVAL dwIP AS DWORD) AS DWORD
     LOCAL pDwIP AS BYTE POINTER
    
     pDwIP = VARPTR(dwIP)
     SWAP @pDwIP[0], @pDwIP[3]
     SWAP @pDwIP[1], @pDwIP[2]
     FUNCTION = dwIP
    
    END FUNCTION
    '______________________________________________________________________________
    
    FUNCTION DwIpToString(BYVAL DwIp AS DWORD) AS STRING
     LOCAL pByte AS BYTE POINTER
    
     pByte    = VARPTR(dwIP)
     FUNCTION = FORMAT$(@pByte[3]) & "." & FORMAT$(@pByte[2]) & "." & _
                FORMAT$(@pByte[1]) & "." & FORMAT$(@pByte[0])
    
    END FUNCTION
    '______________________________________________________________________________
    
    FUNCTION dwIpToHostName(dwIP AS DWORD) AS STRING
     LOCAL zHost         AS ASCIIZ * %MAX_HOSTNAME_LEN
     LOCAL SockAddressIn AS SOCKADDR_IN
    
     SockAddressIn.sin_family           = %AF_INET
     SockAddressIn.sin_addr.S_un.S_addr = dwIp
    
     IF GetNameInfo(SockAddressIn, SIZEOF(SockAddressIn), zHost, %MAX_HOSTNAME_LEN, _
                    BYVAL 0, BYVAL 0, %NI_NAMEREQD) = %ERROR_SUCCESS THEN
       FUNCTION = zHost
     ELSE
       FUNCTION = "HostName error" & STR$(WSAGetLastError())
     END IF
    
    END FUNCTION
    '_____________________________________________________________________________
    
    FUNCTION PortStateToText(PortState AS LONG) AS STRING
    
     SELECT CASE PortState
       CASE %MIB_TCP_STATE_CLOSED     : FUNCTION = "CLOSED"
       CASE %MIB_TCP_STATE_LISTEN     : FUNCTION = "LISTEN"
       CASE %MIB_TCP_STATE_SYN_SENT   : FUNCTION = "SYN_SENT"
       CASE %MIB_TCP_STATE_SYN_RCVD   : FUNCTION = "SYN_RCVD"
       CASE %MIB_TCP_STATE_ESTAB      : FUNCTION = "ESTABLISHED"
       CASE %MIB_TCP_STATE_FIN_WAIT1  : FUNCTION = "FIN_WAIT1"
       CASE %MIB_TCP_STATE_FIN_WAIT2  : FUNCTION = "FIN_WAIT2"
       CASE %MIB_TCP_STATE_CLOSE_WAIT : FUNCTION = "CLOSE_WAIT"
       CASE %MIB_TCP_STATE_CLOSING    : FUNCTION = "CLOSING"
       CASE %MIB_TCP_STATE_LAST_ACK   : FUNCTION = "LAST_ACK"
       CASE %MIB_TCP_STATE_TIME_WAIT  : FUNCTION = "TIME_WAIT"
       CASE %MIB_TCP_STATE_DELETE_TCB : FUNCTION = "DELETED_TCB"
       CASE ELSE                      : FUNCTION = "STATE_UNKNOWN" & STR$(PortState)
     END SELECT
    
    END FUNCTION
    '_____________________________________________________________________________
    
    FUNCTION PBMAIN () AS LONG
     LOCAL pTcpTableData AS MIB_TCPTABLE POINTER
     LOCAL WsaInfo       AS WSADATA
     LOCAL TcpTableData  AS STRING
     LOCAL sLog          AS STRING
     LOCAL BufferSize    AS LONG
     LOCAL index         AS LONG
     LOCAL dwEnum        AS DWORD
    
     IF WSAStartup(MAKWRD(2, 2), WsaInfo) THEN
       MessageBox(%HWND_DESKTOP, "WSAStartup could not start", $AppName, %MB_OK OR %MB_TOPMOST)
     ELSE
       GetTcpTable(BYVAL 0, BufferSize, 0) 'Get data needed buffer size
       TcpTableData  = NUL$(BufferSize)
       pTcpTableData = STRPTR(TcpTableData)
       GetTcpTable(BYVAL pTcpTableData, BufferSize, %TRUE) '%TRUE for sorted
       FOR index = 0 TO @pTcpTableData.dwNumEntries - 1 'Loop into each entries
         IF @pTcpTableData.table(index).dwLocalAddr * @pTcpTableData.table(index).dwRemoteAddr THEN 'Log if both are non null, curious could comment the line
           sLog &= FORMAT$(dwEnum, "00") & ") " & _
                   dwIpToHostName(@pTcpTableData.table(index).dwLocalAddr)            & "   " & _
                   DwIpToString(DwIpMirror(@pTcpTableData.table(index).dwLocalAddr))  & " : " & _
                   PortToString(@pTcpTableData.table(index).dwLocalPort)              & SPACE$(15) & $TAB & _
                   DwIpToString(DwIpMirror(@pTcpTableData.table(index).dwRemoteAddr)) & " : " & _
                   PortToString(@pTcpTableData.table(index).dwRemotePort)             & SPACE$(3) & $TAB & _
                   PortStateToText(@pTcpTableData.table(index).State)                 & $CRLF
           INCR dwEnum
         END IF
       NEXT
       WSACleanup()
       MessageBox(%HWND_DESKTOP, (sLog), $AppName, %MB_OK OR %MB_TOPMOST)
     END IF
    
    END FUNCTION

  • #2
    Tim,
    Instead of GetTcpTable, use GetTcpTable2 / MIB_TCPTABLE2 to get .dwOwningPid then QueryFullProcessImageName(dwOwningPid, ...) to get the filename.

    Comment


    • #3
      Thank you Pierre,
      I'm not sure how to go about doing this as I'm just beginning to program in WinApi

      Comment


      • #4
        Here is something to play with...

        Click image for larger version  Name:	GetTcpTable2.png Views:	0 Size:	56.6 KB ID:	781998

        Code:
        #COMPILE EXE '#Win# 'Using José's includes
        #DIM ALL
        #INCLUDE "Win32api.inc"
        #INCLUDE "ipHlpApi.inc"
        #INCLUDE "WinSock2.inc"
        #INCLUDE "CommCtrl.inc"
        #IF %PB_REVISION < &H1000
        #INCLUDE "ListViewCtrl.inc"
        '#RESOURCE ".pbr" 'Add a resource for better look
        #ELSE
        #RESOURCE MANIFEST, 1, "xptheme.XML"
        #ENDIF
        
        DECLARE FUNCTION GetNameInfo LIB "ws2_32.dll" ALIAS "getnameinfo" _
        (BYREF sa AS SOCKADDR, BYVAL salen AS LONG, BYREF HOST AS ASCIIZ, BYVAL hostlen AS DWORD, _
         BYREF serv AS ASCIIZ, BYVAL servlen AS DWORD, BYVAL flags AS LONG) AS LONG
        
        $AppName   = "GetTcpTable2"
        %Listview  = 101
        
        GLOBAL hDlg      AS DWORD
        GLOBAL hListView AS DWORD
        '______________________________________________________________________________
        
        FUNCTION WinError$(BYVAL ErrorCode AS DWORD) AS STRING
         LOCAL pzError  AS ASCIIZ POINTER 'Max is 64K
         LOCAL ErrorLen AS DWORD
        
         ErrorLen = FormatMessage(%FORMAT_MESSAGE_FROM_SYSTEM OR %FORMAT_MESSAGE_ALLOCATE_BUFFER, _
                                  BYVAL %NULL, ErrorCode, %NULL, BYVAL VARPTR(pzError), %NULL, BYVAL %NULL)
         IF ErrorLen THEN
           REPLACE $CRLF WITH $SPC IN @pzError
           FUNCTION = "Error" & STR$(ErrorCode) & " (0x" & HEX$(ErrorCode) & ") : " & @pzError
           LocalFree(pzError)
         ELSE
           FUNCTION = "Unknown error" & STR$(ErrorCode) & " (0x" & HEX$(ErrorCode) & ")"
         END IF
        
        END FUNCTION
        '_____________________________________________________________________________
        
        FUNCTION PortToString(BYVAL WordVar AS WORD) AS STRING
         LOCAL pWordVar AS BYTE POINTER
        
         pWordVar= VARPTR(WordVar)
         SWAP @pWordVar[0], @pWordVar[1]
         FUNCTION = FORMAT$(WordVar)
        
        END FUNCTION
        '______________________________________________________________________________
        
        FUNCTION DwIpMirror(BYVAL dwIP AS DWORD) AS DWORD
         LOCAL pDwIP AS BYTE POINTER
        
         pDwIP = VARPTR(dwIP)
         SWAP @pDwIP[0], @pDwIP[3]
         SWAP @pDwIP[1], @pDwIP[2]
         FUNCTION = dwIP
        
        END FUNCTION
        '______________________________________________________________________________
        
        FUNCTION DwIpToString(BYVAL DwIp AS DWORD) AS STRING
         LOCAL pByte AS BYTE POINTER
        
         pByte    = VARPTR(dwIP)
         FUNCTION = FORMAT$(@pByte[3]) & "." & FORMAT$(@pByte[2]) & "." & _
                    FORMAT$(@pByte[1]) & "." & FORMAT$(@pByte[0])
        
        END FUNCTION
        '______________________________________________________________________________
        
        FUNCTION dwIpToHostName(dwIP AS DWORD) AS STRING
         LOCAL zHost         AS ASCIIZ * %MAX_HOSTNAME_LEN
         LOCAL SockAddressIn AS SOCKADDR_IN
         LOCAL WsaError      AS LONG
        
         SockAddressIn.sin_family = %AF_INET
         #IF %PB_REVISION < &H1000
         SockAddressIn.sin_addr.s_addr = dwIp
         #ELSE
         SockAddressIn.sin_addr.S_un.S_addr = dwIp
         #ENDIF
        
         IF GetNameInfo(SockAddressIn, SIZEOF(SockAddressIn), zHost, %MAX_HOSTNAME_LEN, _
                        BYVAL 0, BYVAL 0, %NI_NAMEREQD) = %ERROR_SUCCESS THEN
           FUNCTION = zHost
         ELSE
           WsaError = WSAGetLastError()
           FUNCTION = "HostName error" & STR$(WsaError) & ", " & WinError$(WsaError)
         END IF
        
        END FUNCTION
        '_____________________________________________________________________________
        
        FUNCTION PortStateToText(PortState AS LONG) AS STRING
        
         SELECT CASE PortState
           CASE %MIB_TCP_STATE_CLOSED     : FUNCTION = "Closed"
           CASE %MIB_TCP_STATE_LISTEN     : FUNCTION = "Listen"
           CASE %MIB_TCP_STATE_SYN_SENT   : FUNCTION = "Syn_sent"
           CASE %MIB_TCP_STATE_SYN_RCVD   : FUNCTION = "Syn_rcvd"
           CASE %MIB_TCP_STATE_ESTAB      : FUNCTION = "Established"
           CASE %MIB_TCP_STATE_FIN_WAIT1  : FUNCTION = "Fin_wait1"
           CASE %MIB_TCP_STATE_FIN_WAIT2  : FUNCTION = "Fin_wait2"
           CASE %MIB_TCP_STATE_CLOSE_WAIT : FUNCTION = "Close_wait"
           CASE %MIB_TCP_STATE_CLOSING    : FUNCTION = "Closing"
           CASE %MIB_TCP_STATE_LAST_ACK   : FUNCTION = "Last_ack"
           CASE %MIB_TCP_STATE_TIME_WAIT  : FUNCTION = "Time_wait"
           CASE %MIB_TCP_STATE_DELETE_TCB : FUNCTION = "Deleted_tcb"
           CASE ELSE                      : FUNCTION = "State_unknown 0x" & HEX$(PortState)
         END SELECT
        
        END FUNCTION
        '_____________________________________________________________________________
        
        FUNCTION PortOffLoadStateToText(dwOffloadState AS LONG) AS STRING
        
         SELECT CASE dwOffloadState
           CASE %TcpConnectionOffloadStateInHost     : FUNCTION = "InHost"
           CASE %TcpConnectionOffloadStateOffloading : FUNCTION = "Offloading"
           CASE %TcpConnectionOffloadStateOffloaded  : FUNCTION = "Offloaded"
           CASE %TcpConnectionOffloadStateUploading  : FUNCTION = "Uploading"
           CASE %TcpConnectionOffloadStateMax        : FUNCTION = "StateMax"
           CASE ELSE                                 : FUNCTION = "OFFLOAD_STATE_UNKNOWN 0x" & HEX$(dwOffloadState)
         END SELECT
        
        END FUNCTION
        '______________________________________________________________________________
        
        FUNCTION PathNameFromPid(pid AS DWORD)AS STRING
         LOCAL  zFilename     AS ASCIIZ * %MAX_PATH
         LOCAL  zFilenameSize AS DWORD
         LOCAL  hProcess      AS DWORD
        
         hProcess = OpenProcess(%PROCESS_QUERY_LIMITED_INFORMATION, %FALSE, pid)
         IF hProcess THEN
           zFilenameSize = SIZEOF(zFilename)
           QueryFullProcessImageName(hProcess, 0, zFilename, zFilenameSize)  'Get filename
           CloseHandle(hProcess)
           FUNCTION = zFilename
         ELSE
           IF pid THEN FUNCTION = "N/A (Try to run code as admin)"
         END IF
        
        END FUNCTION
        '______________________________________________________________________________
        
        CALLBACK FUNCTION MainProc()
        
         SELECT CASE CBMSG
        
           CASE %WM_SIZE
             SetWindowPos(hListview, %NULL, 2, 2, LOWRD(CBLPARAM) - 4, HIWRD(CBLPARAM) - 4, %SWP_NOZORDER) 'Resize listview
        
         END SELECT
        
        END FUNCTION
        '______________________________________________________________________________
        
        FUNCTION PBMAIN()
         LOCAL ListViewColumn AS LVCOLUMN
         LOCAL ListViewItem   AS LVITEM
         LOCAL zBuffer        AS ASCIIZ * %MAX_PATH
         LOCAL InsertionPoint AS LONG
         LOCAL ColCount       AS LONG
         LOCAL RowCount       AS LONG
         LOCAL Col            AS LONG
         LOCAL Row            AS LONG
        
         '---------------------------------------------------------------------------- GetTcpTable2 info section
         LOCAL pTcpTableData2 AS MIB_TCPTABLE2 POINTER
         LOCAL WsaInfo        AS WSADATA
         LOCAL TcpTableData2  AS STRING
         LOCAL hIcon          AS DWORD
         LOCAL BufferSize     AS LONG
         LOCAL EntryCount     AS LONG
         LOCAL EntryIndex     AS LONG
         LOCAL index          AS LONG
        
         IF WSAStartup(MAKWRD(2, 2), WsaInfo) THEN
           MessageBox(%HWND_DESKTOP, "WSAStartup could not start!", $AppName, %MB_OK OR %MB_TOPMOST)
         ELSE
           GetTcpTable2(BYVAL 0, BufferSize, 0) 'First call to get needed buffer size
           TcpTableData2  = NUL$(BufferSize)
           pTcpTableData2 = STRPTR(TcpTableData2)
        
           GetTcpTable2(BYVAL pTcpTableData2, BufferSize, %TRUE) 'Get TCP table (TRUE is for sorted info)
           DIM sTableEntrie(0 TO @pTcpTableData2.dwNumEntries) AS STRING
           FOR EntryIndex = 0 TO @pTcpTableData2.dwNumEntries - 1 'Loop into each entries
             IF @pTcpTableData2.table(EntryIndex).dwLocalAddr * @pTcpTableData2.table(EntryIndex).dwRemoteAddr THEN 'If both are non null, curious coder may comment this
               sTableEntrie(Index + 1) = FORMAT$(Index + 1, "00")                                                 & $TAB  & _ 'index
                                         dwIpToHostName(@pTcpTableData2.table(EntryIndex).dwLocalAddr)            & $TAB  & _ 'Host name
                                         DwIpToString(DwIpMirror(@pTcpTableData2.table(EntryIndex).dwLocalAddr))  & " : " & _ 'Local address
                                         PortToString(@pTcpTableData2.table(EntryIndex).dwLocalPort)              & $TAB  & _ 'Local port
                                         DwIpToString(DwIpMirror(@pTcpTableData2.table(EntryIndex).dwRemoteAddr)) & " : " & _ 'Distant address
                                         PortToString(@pTcpTableData2.table(EntryIndex).dwRemotePort)             & $TAB  & _ 'Distant port
                                         PortStateToText(@pTcpTableData2.table(EntryIndex).dwState)               & $TAB  & _ 'Port state
                                         PortOffLoadStateToText(@pTcpTableData2.table(EntryIndex).dwOffloadState) & $TAB  & _ 'Port off load state
                                         "0x" & HEX$(@pTcpTableData2.table(EntryIndex).dwOwningPid, 4) & _                    'Process id hex
                                         " (" & FORMAT$(@pTcpTableData2.table(EntryIndex).dwOwningPid) & ")"      & $TAB  & _ 'Process id dec
                                         PathNameFromPid(@pTcpTableData2.table(EntryIndex).dwOwningPid)                       'Full exe name, some might need admin right
               INCR Index
             END IF
             EntryCount = Index - 1
           NEXT
           WSACleanup()
         END IF
        
         '---------------------------------------------------------------------------- Dialog & ListView section
        
         DIALOG FONT "Segoe UI", 9
         DIALOG NEW %HWND_DESKTOP, $AppName, , , 550, 150, _
         %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_SYSMENU OR %WS_THICKFRAME, 0 TO hDlg
        
         CONTROL ADD "SysListView32", hDlg, %Listview, "SysListView321", 27, 18, 285, 186, _
         %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %WS_TABSTOP OR %LVS_REPORT OR _
         %LVS_SORTASCENDING OR %LVS_SHOWSELALWAYS, %WS_EX_LEFT OR %WS_EX_RIGHTSCROLLBAR
        
         hListview = GetDlgItem(hDlg, %Listview)
        
         LISTVIEW_SETEXTENDEDLISTVIEWSTYLE(hListview, ListView_GetExtendedListViewStyle(hListview) OR _
         %LVS_EX_FULLROWSELECT OR %LVS_EX_GRIDLINES OR %LVS_EX_HEADERDRAGDROP)
        
         '- Set listview column headers
         ListViewColumn.mask    = %LVCF_FMT OR %LVCF_TEXT OR %LVCF_SUBITEM
         ListViewColumn.fmt     = %LVCFMT_LEFT
         ListViewColumn.pszText = VARPTR(zBuffer)
         ColCount               = 8
         RowCount               = EntryCount
         FOR Col = 0 TO ColCount - 1
           zBuffer = PARSE$("Index" & $TAB & "Name" & $TAB & "Local ip:Port" & $TAB & "Distant ip:Port" & $TAB & _
                            "State" & $TAB & "OffLoad" & $TAB & "Pid"  & $TAB & "FileName", $TAB, Col + 1)
           ListViewColumn.iOrder = Col
           SendMessage(hListview, %LVM_INSERTCOLUMN, Col, VARPTR(ListviewColumn))
         NEXT
        
         '- Set listview data
         FOR Row = 0 TO RowCount
           ListViewItem.pszText = VARPTR(zBuffer)
           ListViewItem.iItem   = Row
           FOR Col = 0 TO ColCount - 1
             zBuffer = PARSE$(sTableEntrie(Row + 1), $TAB, Col + 1) 'Column $TAB separated data
             ListViewItem.iSubItem = Col
             IF Col = 0 THEN 'First column
               ListViewItem.mask   = %LVIF_TEXT OR %LVIF_PARAM
               ListViewItem.lParam = Row
               InsertionPoint = SendMessage(hListview, %LVM_INSERTITEM, 0, VARPTR(ListViewItem))
             ELSE 'Other than first column
               ListViewItem.mask     = %LVIF_TEXT
               ListViewItem.iItem    = InsertionPoint
               SendMessage(hListview, %LVM_SETITEM, 0, VARPTR(ListViewItem))
             END IF
           NEXT
         NEXT
        
         'Auto size columns.
         FOR Col = 0 TO ColCount - 1
           SendMessage(hListview, %LVM_SETCOLUMNWIDTH, Col, MAKLNG(%LVSCW_AUTOSIZE, 0)) 'Auto size columns based on data lenght
           SendMessage(hListview, %LVM_SETCOLUMNWIDTH, Col, MAKLNG(%LVSCW_AUTOSIZE_USEHEADER, 0)) 'Auto size columns based on header string lenght
         NEXT
        
         hIcon = ExtractIcon(GetModuleHandle(""), "Shell32.dll", 150) 'Get some icon
         SetClassLong(hDlg, %GCL_HICONSM, hIcon) 'Set dialog icon
         SetClassLong(hDlg, %GCL_HICON, hIcon)   'Set dialog icon
        
         DIALOG SHOW MODAL hDlg, CALL MainProc
        
         DestroyIcon(hIcon)
        
        END FUNCTION
        '______________________________________________________________________________
        '
        Last edited by Pierre Bellisle; 14 Jun 2019, 02:47 PM.

        Comment


        • #5
          Thank you Pierre, that's very nice programming and this what I need now. It is better than Netstat

          Comment


          • #6
            Looks great, but I get a missing declaration on line 223 with PB10.

            Comment


            • #7
              I tried to compile with Jose' and PB includes and both work. Maybe your copy and paste messed up the line. Below is line 223 and the continuation line 224

              Code:
               LISTVIEW_SETEXTENDEDLISTVIEWSTYLE(hListview, ListView_GetExtendedListViewStyle(hListview) OR _
               %LVS_EX_FULLROWSELECT OR %LVS_EX_GRIDLINES OR %LVS_EX_HEADERDRAGDROP)
              What declaration is missing?

              Comment


              • #8
                I did some minor corrections to the code above.
                Note that running code as admin should get file name instead of an 'N/A' entry.

                Comment


                • #9
                  Thanks Pierre, it seems that running this program as an admin works better as it can display more program names (instead of N/A )

                  The question is how can we determine or check if the program has been executed as an admin or not? is there a test that we can use to ensure that the program
                  can be executed as an admin ?

                  Comment


                  • #10
                    For a program to start as Admin, you need a manifest that ask for "requireAdministrator" level.

                    Create "xpthemeAdm.xml" file with the following text:

                    Code:
                    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
                      <assemblyIdentity
                        name="SomeName.exe"
                        processorArchitecture="x86"
                        version="1.0.0.0"
                        type="win32"
                      />
                      <description>Windows Shell</description>
                    
                      <!-- Theme section -->
                      <dependency>
                        <dependentAssembly>
                          <assemblyIdentity
                            type="win32"
                            name="Microsoft.Windows.Common-Controls"
                            version="6.0.0.0"
                            processorArchitecture="x86"
                             publicKeyToken="6595b64144ccf1df"
                             language="*"
                          />
                        </dependentAssembly>
                      </dependency>
                    
                      <!-- Trustinfo section -->
                      <asmv3:trustInfo xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
                        <asmv3:security>
                          <asmv3:requestedPrivileges>
                            <!-- level="asInvoker" level="highestAvailable" level="requireAdministrator" -->
                            <asmv3:requestedExecutionLevel
                              level="requireAdministrator"
                              uiAccess="false" />
                          </asmv3:requestedPrivileges>
                        </asmv3:security>
                      </asmv3:trustInfo>
                    
                    </assembly>
                    Then just after the last "#INCLUDE" line in code, add this:
                    #RESOURCE MANIFEST, 1, "xpthemeAdm.xml"

                    -

                    To know when some code is running under Administrator right, use the following function.
                    Code:
                    %SECURITY_NT_AUTHORITY = 5
                    '______________________________________________________________________________
                    
                    FUNCTION IsUserAdmin() AS LONG 'Return %TRUE when user is Admin.
                     'IsUserAnAdmin() api may not be there in future Windows release, so MS recommed the following...
                     LOCAL NtAuthority         AS SID_IDENTIFIER_AUTHORITY
                     LOCAL AdministratorsGroup AS LONG
                     LOCAL IsMember            AS LONG
                    
                     NtAuthority.value(5) = %SECURITY_NT_AUTHORITY 'SECURITY_NT_AUTHORITY = 5
                    
                     IF AllocateAndInitializeSid(NtAuthority, 2, %SECURITY_BUILTIN_DOMAIN_RID, _
                                                 %DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, _
                                                 AdministratorsGroup) THEN
                        IF CheckTokenMembership(%NULL, BYVAL AdministratorsGroup, IsMember) THEN
                          IF IsMember THEN FUNCTION = %TRUE
                        END IF
                        FreeSid(BYVAL AdministratorsGroup)
                     END IF
                    
                    END FUNCTION
                    '______________________________________________________________________________

                    Comment


                    • #11
                      Thank you, Pierre. Note that the use of xpthemeAdm.xml file works fine. However I couldn't get the
                      FUNCTION IsUserAdmin() to work.

                      Hence, it does not matter now as long as the xpthemeAdm.xml file works which forces the program to run as an administrator

                      Comment


                      • #12
                        Also, Pierre, I notice that this is xml theme file is for XP while I'm using a windows 7 machine , do you have a win 7 theme file ?

                        Thanks in advance

                        Comment


                        • #13
                          The XP in xpTheme only mean that the concept was introduced with Windows XP.

                          Comment


                          • #14
                            Not a clue what my problem is. I put the line back to a single and no change. Tried both Jose and regular includes. Still get missing declaration on line 222 error, the LISTVIEW_SETEXTENDEDLISTVIEWSTYLE line.

                            Comment


                            • #15
                              You could just comment out the entire line and it will compile without it. You just will not get all the styles that Pierre selected. Try removing one of the %LVS at a time until it compiles.

                              Comment


                              • #16
                                Try replacing the line with direct api call...
                                Code:
                                 SendMessage(hListview, BYVAL &H1036, 0, SendMessage(hListview, &H1037, 0, 0) OR &H31)
                                 '%LVM_SETEXTENDEDLISTVIEWSTYLE = &H1036 : LVM_GETEXTENDEDLISTVIEWSTYLE = &H1037
                                 '%LVS_EX_FULLROWSELECT OR %LVS_EX_GRIDLINES OR %LVS_EX_HEADERDRAGDROP = &h31

                                Comment


                                • #17
                                  Thank you Pierre, that xpthemeAdm.xml will do

                                  Comment


                                  • #18
                                    Conrad,

                                    ListViewCtrl.inc:
                                    Code:
                                    SUB LISTVIEW_SETEXTENDEDLISTVIEWSTYLE (BYVAL hwndLV AS DWORD, BYVAL dwExStyle AS DWORD)
                                    SendMessage hwndLV, %LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwExStyle
                                    END SUB
                                    The ListView_SetExtendedListViewStyle sub is in José's ListViewCtrl.inc API Headers 3.1.07.
                                    It was not present in 3.1.0.6... Do you have the latest version?

                                    Did you do any change in the #IF %PB_REVISION ... #ENDIF section?
                                    Last edited by Pierre Bellisle; 19 Jun 2019, 09:52 AM.

                                    Comment


                                    • #19
                                      I never had a problem Pierre. I was trying to help Conrad. Your code compiled correctly for me with both pbwin and JR includes. See post 7.

                                      Comment


                                      • #20
                                        Try DiamondCS port explorer - save it to a logfile and read that logfile is you want the results.

                                        Comment

                                        Working...
                                        X