Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Drag And Drop Problemi con LUA

    Salve a tutti.
    Ho un creato un applicazione documentale che agisce su file e registro di Windows e che per alcune modifiche ha bisogno di essere eseguito come amministratore ( <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> ).

    A questo punto sto avendo problemi con un sistema automatizzato per inserire i documenti usando la funzione Drag And Drop in quanto il sistema di protezione LUA mi impedisce di attivare il drag sul mio Form.

    Se tale applicazione viene lanciata senza i privilegi di amministratore il Drag And drop funge correttamente.

    Ho letto che è possibile abilitare la funzione usando delle dll di sistema.
    Ho provato diverse guide, ma non sono riuscito a farlo funzionare .
    Qualcuno di vuoi riesce gentilmente ad aiutarmi?!?!


    codice:
        Private Sub trascina_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles trascina_qui.DragEnter
            If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                e.Effect = DragDropEffects.Copy
            Else
                e.Effect = DragDropEffects.None
            End If
        End Sub
    
        Private Sub trascina_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles trascina_qui.DragDrop
       
    
           
                If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                    Dim filePaths As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
                     For Each filePath As String In filePaths
    
    
                    Next filePath
    
                 end if
    
        End Sub
    Premetto che disabilitando la protezione LUA il Drag And Drop funge anche se lancio l'applicazione con i privilegi di Amministratore.


    Grazie Anticipatamente
    Ultima modifica di ToNyLuCa; 25-11-2015 a 22:27

  2. #2
    Nessuno riesce a darmi una dritta?!?
    Ho provato a creare anche un Applicazione separata che tramite il drag and drop passa il comando al primo programma e importa i file..solo che se apro il programma separatamente e quindi devo aprire due programmi il tutto funge correttamente, ma se richiamo il secondo programma da un pulsante logicamente questo passa i privilegi admin anche a questo bloccando il funzionamento del drag and drop.

    Ho provato anche a studiarmi come ad aprire un software esterno con privilegi diversi da quello che lo richiama, ma non ho trovato niente di valido, qualcuno riesce ad aiutarmi?

  3. #3
    Utente di HTML.it L'avatar di Kahm
    Registrato dal
    Dec 2004
    residenza
    Rome
    Messaggi
    3,582
    http://www.winfxitalia.com/script/16...istrativi.aspx

    e comunque gli ultimi sistemi windows proteggono molto
    devi avere una cartella TUA, e non andare a scrivere tipo in C:\ o qualsiasi altra cartella che non sia la tua di installazione
    Devi semplicemente seguire le linee guida Microsoft, ossia NON SCRIVERE
    dentro alle cartelle di sistema (es. Programmi).
    NN vi diro mai chi sono in realta,
    tutti i miei 3D sono orfani, non insistete per farmi rispondere ai 3D aperti da me

  4. #4
    Ciao e grazie per la risposta.
    Comunque il mio programma ha un installazione e va a installarsi in c:\nomeprogramma
    Quello che mi hai postato è una guida come avviare il programma come amministratore,
    ma il mio programma lavora già come amministratore e non posso abbassargli i privilegi perché va a scrivere nel registro, il mio problema è proprio quello che il drag and drop non mi funge se il programma viene avviato come amministratore, mentre se tolto l amministratore o disattivo LUA funge, ma logicamente non mi fa scrivere più nel registro...
    C'è un modo magari dove posso cambiare i privilegi dal programma stesso, tipo da amministratore abbassare i privilegi e poi aumentarli finita la procedura?

    Grazie anticipatamente

  5. #5
    Finalmente ho trovato la soluzione :-D
    codice:
    Imports System.Text
    Imports System.Runtime.InteropServices
    
    Namespace Utilities
        Public Class ElevatedDragDropManager
            Implements IMessageFilter
    
    #Region "P/Invoke"
            <DllImport("user32.dll")> _
            Private Shared Function ChangeWindowMessageFilterEx(hWnd As IntPtr, msg As UInteger, action As ChangeWindowMessageFilterExAction, ByRef changeInfo As CHANGEFILTERSTRUCT) As <MarshalAs(UnmanagedType.Bool)> Boolean
            End Function
    
            <DllImport("user32.dll")> _
            Private Shared Function ChangeWindowMessageFilter(msg As UInteger, flags As ChangeWindowMessageFilterFlags) As <MarshalAs(UnmanagedType.Bool)> Boolean
            End Function
    
            <DllImport("shell32.dll")> _
            Private Shared Sub DragAcceptFiles(hwnd As IntPtr, fAccept As Boolean)
            End Sub
    
            <DllImport("shell32.dll")> _
            Private Shared Function DragQueryFile(hDrop As IntPtr, iFile As UInteger, <Out()> lpszFile As StringBuilder, cch As UInteger) As UInteger
            End Function
    
            <DllImport("shell32.dll")> _
            Private Shared Function DragQueryPoint(hDrop As IntPtr, ByRef lppt As POINT) As Boolean
            End Function
    
            <DllImport("shell32.dll")> _
            Private Shared Sub DragFinish(hDrop As IntPtr)
            End Sub
    
            <StructLayout(LayoutKind.Sequential)> _
            Private Structure POINT
                Public X As Integer
                Public Y As Integer
    
                Public Sub New(newX As Integer, newY As Integer)
                    X = newX
                    Y = newY
                End Sub
    
                Public Shared Widening Operator CType(p As POINT) As Drawing.Point
                    Return New Drawing.Point(p.X, p.Y)
                End Operator
    
                Public Shared Widening Operator CType(p As Drawing.Point) As POINT
                    Return New POINT(p.X, p.Y)
                End Operator
            End Structure
    
            Private Enum MessageFilterInfo As UInteger
                None
                AlreadyAllowed
                AlreadyDisAllowed
                AllowedHigher
            End Enum
    
            Private Enum ChangeWindowMessageFilterExAction As UInteger
                Reset
                Allow
                Disallow
            End Enum
    
            Private Enum ChangeWindowMessageFilterFlags As UInteger
                Add = 1
                Remove = 2
            End Enum
    
            <StructLayout(LayoutKind.Sequential)> _
            Private Structure CHANGEFILTERSTRUCT
                Public cbSize As UInteger
                Public ExtStatus As MessageFilterInfo
            End Structure
    #End Region
    
            Public Shared Instance As New ElevatedDragDropManager()
            Public Event ElevatedDragDrop As EventHandler(Of ElevatedDragDropArgs)
    
            Private Const WM_DROPFILES As UInteger = &H233
            Private Const WM_COPYDATA As UInteger = &H4A
            Private Const WM_COPYGLOBALDATA As UInteger = &H49
    
            Private ReadOnly IsVistaOrHigher As Boolean = Environment.OSVersion.Version.Major >= 6
            Private ReadOnly Is7OrHigher As Boolean = (Environment.OSVersion.Version.Major = 6 AndAlso Environment.OSVersion.Version.Minor >= 1) OrElse Environment.OSVersion.Version.Major > 6
    
            Protected Sub New()
                Application.AddMessageFilter(Me)
            End Sub
    
            Public Sub EnableDragDrop(hWnd As IntPtr)
                If Is7OrHigher Then
                    Dim changeStruct As New CHANGEFILTERSTRUCT()
                    changeStruct.cbSize = CUInt(Marshal.SizeOf(GetType(CHANGEFILTERSTRUCT)))
                    ChangeWindowMessageFilterEx(hWnd, WM_DROPFILES, ChangeWindowMessageFilterExAction.Allow, changeStruct)
                    ChangeWindowMessageFilterEx(hWnd, WM_COPYDATA, ChangeWindowMessageFilterExAction.Allow, changeStruct)
                    ChangeWindowMessageFilterEx(hWnd, WM_COPYGLOBALDATA, ChangeWindowMessageFilterExAction.Allow, changeStruct)
                ElseIf IsVistaOrHigher Then
                    ChangeWindowMessageFilter(WM_DROPFILES, ChangeWindowMessageFilterFlags.Add)
                    ChangeWindowMessageFilter(WM_COPYDATA, ChangeWindowMessageFilterFlags.Add)
                    ChangeWindowMessageFilter(WM_COPYGLOBALDATA, ChangeWindowMessageFilterFlags.Add)
                End If
    
                DragAcceptFiles(hWnd, True)
            End Sub
    
            Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
                If m.Msg = WM_DROPFILES Then
                    HandleDragDropMessage(m)
                    Return True
                End If
    
                Return False
            End Function
    
            Private Sub HandleDragDropMessage(m As Message)
                Dim sb = New StringBuilder(260)
                Dim numFiles As UInteger = DragQueryFile(m.WParam, &HFFFFFFFFUI, sb, 0)
                Dim list = New List(Of String)()
    
                For i As UInteger = 0 To numFiles - 1
                    If DragQueryFile(m.WParam, i, sb, CUInt(sb.Capacity) * 2) > 0 Then
                        list.Add(sb.ToString())
                    End If
                Next
    
                Dim p As POINT
                DragQueryPoint(m.WParam, p)
                DragFinish(m.WParam)
    
                Dim args = New ElevatedDragDropArgs()
                args.HWnd = m.HWnd
                args.Files = list
                args.X = p.X
                args.Y = p.Y
    
                RaiseEvent ElevatedDragDrop(Me, args)
            End Sub
        End Class
    
        Public Class ElevatedDragDropArgs
            Inherits EventArgs
            Public Property HWnd() As IntPtr
                Get
                    Return m_HWnd
                End Get
                Set(value As IntPtr)
                    m_HWnd = value
                End Set
            End Property
            Private m_HWnd As IntPtr
            Public Property Files() As List(Of String)
                Get
                    Return m_Files
                End Get
                Set(value As List(Of String))
                    m_Files = value
                End Set
            End Property
            Private m_Files As List(Of String)
            Public Property X() As Integer
                Get
                    Return m_X
                End Get
                Set(value As Integer)
                    m_X = value
                End Set
            End Property
            Private m_X As Integer
            Public Property Y() As Integer
                Get
                    Return m_Y
                End Get
                Set(value As Integer)
                    m_Y = value
                End Set
            End Property
            Private m_Y As Integer
    
            Public Sub New()
                Files = New List(Of String)()
            End Sub
        End Class
    End Namespace
    codice:
    Private Sub Form1_Load(sender As System.Object, e As EventArgs) Handles MyBase.Load
    	ElevatedDragDropManager.Instance.EnableDragDrop(DataGridView1.Handle) ' Enable elevated drag drop on DataGridView1. Note that I used the Handle property
    	AddHandler ElevatedDragDropManager.Instance.ElevatedDragDrop, AddressOf Form1_ElevatedDragDrop
    End Sub
    
    Private Sub Form1_ElevatedDragDrop(sender As System.Object, e As ElevatedDragDropArgs)
    	If e.HWnd = DataGridView1.Handle Then ' Check where the drag drop came from
    		For Each file In e.Files
    			MsgBox(file) ' Show all the files that were drag-dropped
    		Next
    	End If
    End Sub
    Ecco qui la soluzione :-D

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.