Windows 10 How to integrate software in the windows?

Discussion in 'Programming and Scripting' started by neocode, Feb 24, 2016.

  1. neocode

    neocode New Member

    Joined:
    Feb 24, 2016
    Messages:
    4
    Likes Received:
    0
    Hello, I'm new here, I'm wondering how I can integrate software in the Windows.

    For example, if I want to add an item to the context menu, in the explorer window, to send a file to an OLD folder.
    upload_2016-2-24_14-30-48.

    So, after click in «Send to Old» it would create a folder «yyyy-MM-dd - Old» in the same path of the file and then move the file to this Old folder.

    To add the item to the context menu, I suspect I must change the windows registry, which is ok. But I don't know how to know the path of the selected file in the explorer window.

    Any ideas\tutorials about where to start to do this kind of addins for windows?

    Which language code should I use?

    Many thanks!
     
  2. Neemobeer

    Neemobeer Windows Forum Team
    Staff Member

    Joined:
    Jul 4, 2015
    Messages:
    2,410
    Likes Received:
    363
    To add items to the right-click content menu you will edit the registry.
    The main registry hive you will want to edit is HKEY_CLASSES_ROOT. If you want the menu change on all file types then you will edit the * key or if you want the change on a specific file type you would edit the .extension. For the * for this example.

    Expand the * key then shell. Right click on shell and select New > Key. Name this whatever you want the menu to say. For or example we'll say it's called Open in Notepad. Right click on "Open in Notepad" and again New > Key and name it command this name is important. Now click on command and on the right you have a (Default) value, double click on it to edit the value. For the value data type with the quotes. "C:\Windows\notepad.exe" "%1". Thats it now when you right click a file you should see a "Open in Notepad" the %1 passes that file name to shell and on to notepad to open. There are other extra pieces you can add, such as click on "Open in Notepad" on the right, right click and select new "String Value" and name it Icon. Double-click this and enter "C:\Windows\notepad.exe" and now your right click item will have an notepad icon.
     
    neocode likes this.
  3. neocode

    neocode New Member

    Joined:
    Feb 24, 2016
    Messages:
    4
    Likes Received:
    0
    Thank you Neemobeer!
    All you've said works pretty well, now I just need to know how can I retrieve the file path from shell or how a program receive the file path? Ty
     
  4. Neemobeer

    Neemobeer Windows Forum Team
    Staff Member

    Joined:
    Jul 4, 2015
    Messages:
    2,410
    Likes Received:
    363
    The %1 means first argument in batch file terms, the program itself needs to have that capability and many do. If you run a program from the command prompt and type <programname> /? you will generally get a list of command parameters a program will accept. You can incorporate any of them into the context menu. It is pretty important to always enclose the %1 with quotes since the file path may include spaces and the quotes ensures the full path is treated as one argument.
     
  5. Neemobeer

    Neemobeer Windows Forum Team
    Staff Member

    Joined:
    Jul 4, 2015
    Messages:
    2,410
    Likes Received:
    363
    Also if your trying to expand what is referred to as "The Ribbon" (all the buttons in explorer) ribbon1.

    You can do that in the registry as well.
    Extending the Ribbon (Windows)
     
  6. neocode

    neocode New Member

    Joined:
    Feb 24, 2016
    Messages:
    4
    Likes Received:
    0
    Ok, then I can do it simply with a batch file, that works just fine.

    Thank you Meemobeer! Also ty for the ribbon tip.
     
  7. Neemobeer

    Neemobeer Windows Forum Team
    Staff Member

    Joined:
    Jul 4, 2015
    Messages:
    2,410
    Likes Received:
    363
    This would do what you want with powershell.
    • Save it in a powershell script such as CopyToOld.ps1
    • Copy the script to C:\Windows
    • [One time] set your powershell execution policy (From an elevated powershell prompt type Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Unrestricted
    • Then for the command registry (Default) value you would type
    • powershell -WindowStyle Hidden -File C:\Windows\CopyToOld.ps1 "%1"

    Code:
    $filepath = $args[0]
    
    $file = Get-Item -Path $filepath
    $filename = $file.Name
    $directory = $file.Directory.Name
    $parent = $file.Directory.Parent.FullName
    $olddirectory = "$parent\$(Get-Date -Format "yyyy-MM-dd") $directory"
    
    New-Item -ItemType Directory -Path "$olddirectory"
    Move-Item -Path $filepath -Destination "$olddirectory\$filename"
     
  8. neocode

    neocode New Member

    Joined:
    Feb 24, 2016
    Messages:
    4
    Likes Received:
    0
    Wow thank you again, I dont even knew that the powershell exists... always learning.

    Works very well just had to change the :

    $directory = $file.Directory.Name
    $parent = $file.Directory.Parent.FullName
    $olddirectory = "$parent\$(Get-Date -Format "yyyy-MM-dd") $directory"
    to

    [delete line]
    $parent = $file.Directory.FullName
    $olddirectory = "$parent\$(Get-Date -Format "yyyy-MM-dd")"​

    $olddirectory was not being set correctly here.
     

Share This Page

Loading...