Does Powershell support drag and drop?

Welcome Forums General PowerShell Q&A Does Powershell support drag and drop?

Viewing 9 reply threads
  • Author
    Posts
    • #275508
      Participant
      Topics: 3
      Replies: 11
      Points: 58
      Rank: Member

      I have this CMD Batch, I hope I can use it PowerShell like this :

      :parse
      IF "%~1"=="" GOTO endparse
      call :handle_one_file %1
      SHIFT
      GOTO parse
      :endparse

      :handle_one_file
      TITLE "%~1"
      echo do something about "%~1"

       

    • #275625
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,986
      Helping Hand
      Rank: Community Hero

      Dragging a file to a powershell window will paste the path. For instance, if you wanted to get file details with Get-Item, you can type Get-Item<space> and then drag a file into the Powershell window:

    • #275799
      Participant
      Topics: 3
      Replies: 11
      Points: 58
      Rank: Member

      so,  there no way to do drag and drop using power shell?

      sorry another question, is possible to use “%~1” parameter from CMD and using it on PowerShell?

      and thank for the reply

    • #275808
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,986
      Helping Hand
      Rank: Community Hero

      so,  there no way to do drag and drop using power shell?

      Not really sure exactly what you mean by ‘drag and drop’ here. Explain what you are dragging and where you are dropping it to execute what? You can drag files into a Powershell window to get a path.

      is possible to use parameter from CMD and using it on PowerShell?

      Again, not really sure what you are asking. Explain exactly what you want to do and expected results. Provide examples.

    • #275814
      Participant
      Topics: 3
      Replies: 11
      Points: 58
      Rank: Member

      something like this

      edit : somehow the reply text always show as html code, i dont know how to fix it, sorry

      • This reply was modified 1 month, 2 weeks ago by kucingkucing09.
      • This reply was modified 1 month, 2 weeks ago by grokkit.
    • #275826
      Participant
      Topics: 3
      Replies: 11
      Points: 58
      Rank: Member

      i hate this, the text always show as HTML code, when i did edit this, the reply is gone,

      anyway the example code:

      :parse
      IF “%~1″==”” GOTO endparse
      call :handle_one_file %1
      SHIFT
      GOTO parse
      :endparse

      :handle_one_file
      TITLE “%~1”
      PowerShell -ExecutionPolicy Bypass -C “%~1”

    • #275970
      Senior Moderator
      Topics: 10
      Replies: 201
      Points: 1,096
      Helping Hand
      Rank: Community Hero

      somehow the reply text always show as html code, i dont know how to fix it, sorry

      Yes, you didn’t read the guide. If you had, you would know why it happens and how to fix it.

    • #275991
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,986
      Helping Hand
      Rank: Community Hero

      Yes, that should be possible assuming you are dragging a PS1 file to the bat. Would recommend the full path to Powershell. Also would say there isn’t really a need for a batch file at all as you are dragging a PS1 to open CMD to open Powershell. CMD\DOS is considered deprecated and in Windows 10 the CMD prompt is actually Powershell, hence you would be opening Powershell to open Powershell to execute a PS1.

      https://support.microsoft.com/en-us/windows/powershell-is-replacing-command-prompt-fdb690cf-876c-d866-2124-21b6fb29a45f#:~:text=To%20create%20the%20best%20command,the%20whitespace%20in%20File%20Explorer.

    • #277110
      Participant
      Topics: 0
      Replies: 1
      Points: 8
      Rank: Member

      Drag and drop is a wonderful facility that most of us will use every day without even thinking about it.

    • #280875
      Participant
      Topics: 0
      Replies: 5
      Points: 21
      Rank: Member

      To achieve our objective, we need to make use of two events, DragOver, and DragDrop.

      DragOver occurs when the mouse is over the control on which we wish to ‘drop’ our object. We’ll typically just use this for changing our pointer to show a move or copy operation is in operation.

      DragDrop occurs once the actual operation is finished. That is, the object has been dragged into the form and over the control, and the mouse button released.

      To implement this in our application, carry out the following:

      Create a form
      Create a Textbox on the form
      Set the following properties for the Textbox
      Name : txtDragandDrop
      Label : Contents dragged:
      AllowDrop : true

      We now define the events that will be processed, and their handlers.

      DragDrop : txtDragandDrop_DragDrop
      DragOver : txtDragandDrop_DragOver

      If you are developing this application in PowerShell Studio, you will need to first export the code, either to a standalone EXE, or .PS1 file.

      Run the application from either of the above.
      Drag a file of you choice from explorer to the textbox.

      I hope this information will be helpful!

      Ben Martin

Viewing 9 reply threads
  • You must be logged in to reply to this topic.