Surprised I didn't see an example of this, so wanted to post it.
Here's a quick implementation of a method to run unelevated apps from your elevated app by routing it through Explorer, as outlined by Raymond Chen.
Requirements
-VB6: oleexp.tlb v5.01 or higher, with included addon mIID.bas (released the same day as this snippet... I had a partial set of the shell automation objects in oleeximp.tlb, not sure why it was complete, or not in oleexp.tlb, so for convenience I put out a quick new version with a complete set in oleexp.tlb. So you only need oleexp.tlb 5.01+ (and mIID.bas) if you get the new version. Otherwise that, oleexpimp.tlb, and shell32).
-twinBASIC: Windows Development Library for twinBASIC (WinDevLib). References->Available Packages
-Windows XP or newer
Code
And it's that simple. Just call LaunchUnelevated with a path to the exe.Code:Public Sub LaunchUnelevated(sPath As String, Optional sArgs As String = "") Dim pShWin As ShellWindows Set pShWin = New ShellWindows #If TWINBASIC Then Dim pDispView As IDispatch #Else Dim pDispView As oleexp.IDispatch 'VB6 has a built in hidden version that will cause an error if you try to use it. Specify oleexp's unrestricted version. #End If Dim pServ As IServiceProvider Dim pSB As IShellBrowser Dim pDual As IShellFolderViewDual Dim pView As IShellView Dim hwnd As LongPtr Dim vrEmpty As Variant Set pServ = pShWin.FindWindowSW(CVar(CSIDL_DESKTOP), vrEmpty, SWC_DESKTOP, hwnd, SWFO_NEEDDISPATCH) pServ.QueryService SID_STopLevelBrowser, IID_IShellBrowser, pSB pSB.QueryActiveShellView pView pView.GetItemObject SVGIO_BACKGROUND, IID_IDispatch, pDispView Set pDual = pDispView Dim pDispShell As IShellDispatch2 Set pDispShell = pDual.Application If sArgs <> "" Then pDispShell.ShellExecute sPath, CVar(sArgs) Else pDispShell.ShellExecute sPath End If End Sub


Reply With Quote
