No announcement yet.

ShellExecute permissions issue

  • Filter
  • Time
  • Show
Clear All
new posts

  • ShellExecute permissions issue

    If a PB program is running as a normal user, but attempts to open a file with a program that runs as an administrator -- for example, attempting to view an HTML file when your browser is running as administrator -- then the ShellExecute call doesn't do anything, and simply hangs. When you close the program, it looks like it closes (as in the window for it disappears), but it stays resident in memory because it's still sitting there waiting for ShellExecute to return.

    So... I suppose my question is whether there's any way to avoid this hang? Either by specifying a timeout and detecting the fail, or by checking the administrative level of the browser or program that will be executing the file?

  • #2
    Are you providing a valid hWnd in your SHELLEXECUTEINFO structure (code not shown)?

    You might be getting a user prompt which you never see if you aren't.

    (GetDesktopWindow() is plenty good enough)


    • #3
      Yes, I'm passing a %NULL -- ShellExecute(%NULL, "open", @pszURL, "", "", %SW_SHOWDEFAULT) -- which should be OK. It is quite likely that it's popping open a prompt asking for permission though and not showing it to the user.

      It works fine when the application being called defaults to being run as a normal user, but if the application defaults to being run as admin, it hangs.


      • #4
        I've changed my code to the following:

        LOCAL desktopHandle AS DWORD
        desktopHandle = GetDesktopWindow()
        res = ShellExecute(desktopHandle, "open", @pszURL, "", "", %SW_SHOWDEFAULT)

        I haven't tested it yet, but hopefully now if there is an error dialog generated, it will be displayed in the desktop... Thanks!


        • #5
          I always pass BYVAL 0 for the handle.
          Is GetDeskTopWindow ever needed?

          DeskTopHandle is always 65552 when logged in as administrator.
          UAC is set to always notify.
          UAC message appears if "run as administrator" is checked (when program starts) in shortcut to program.
          Shell always works with handle 0 or 65552.

          Need to log-in as a "LOCAL account" and test again running with and without "run as administrator in shortcut."

          Now testing as LOCAL account
          GetDesktopHandle() always returns 65552. Appears 0 or GetDeskTopWindow() always works and never "hangs" as reported.
 instead of google