Run with switches

Windows specific questions.
Post Reply
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Run with switches

Post by deltarho[1859] »

I wrote the following years ago on an XP box. I was developing an application which used a plethora of switches in the command tail. It was a pain testing it after each compile and I needed something to speed testing up. When finished I decided to keep it on board as I felt that it was a handy little utility in its own right. I have been using it quite a bit lately so figured some of you may find it handy as well.

If we execute the exe as is then we will get: "I only work from the right click context menu". So, you now know what it does. <smile\>

When invoked from the right click context menu we may get this, for example, "LOG file: I only work with EXE files". So, now you know what it doesn't do.

To get it to run from the right click context menu we need to execute the following registry script. The right click context menu will now display "Run with switches".

Code: Select all

REGEDIT4
 
[HKEY_CLASSES_ROOT\*\shell\RunSwitch]
@="Run with switches"
 
; IMPORTANT: Edit the following @= line to reflect your location of RunSwitch.exe
; Don't forget to use \\ and not \
 
[HKEY_CLASSES_ROOT\*\shell\RunSwitch\command]
@="C:\\PBWin\\RunSwitch\\RunSwitch.exe %L"
; dummy line to make sure that a line is here <smile>
If you want to undo the registry script then use this

Code: Select all

REGEDIT4
 
[-HKEY_CLASSES_ROOT\*\shell\RunSwitch]
; dummy line to make sure that a line is here <smile>
REGEDIT 4 is OK with Windows 10 since we are not using unicode.

Here is a screenshot:

Image

The title is the exe we have right clicked on. We simply type the switches and click OK. With the above NIST-Time.exe will now run with the switches.

If we click OK with an empty input box then RunSwitch will simply close; as it will when we click on Cancel and the Close button.

The command tail is limited to 2048 characters. If you need more than that - shorten the switch names. <laugh>

Thats it! Nothing earth shattering but I wouldn't boot up without it.

Here is a link to a zip of the exe. The exe is tiny - 45.5KB.

RunSwitch.zip
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Run with switches

Post by MrSwiss »

Whilst it may be useful for testing, there are some flaws (as far as I'm concerned).
Changes to Registry *manually* ==> *bad news* (two times: even worse!)
Using *old*, aka: WIN XP style, to manipulate a WIN 10 Registry = NO WAY, ever!
No source, no fun: "Sorry but, I won't touch it, even with gloves on." :-)

All above is based on experience, as a Domain-Admin, on mainly WIN-Servers diff. ver's.
I've done quite a bit of Registry *tuning* on those (but always, with current Tools).
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Run with switches

Post by deltarho[1859] »

Changes to Registry *manually* ==> *bad news* (two times: even worse!)
The registry is not being changed manually - it is been done via a script and published for all to examine. If it is not clear what the script is doing then a spot of reading is required. I made a point of making sure the script was well commented for folks who are not familiar with reg files.
Using *old*, aka: WIN XP style, to manipulate a WIN 10 Registry = NO WAY, ever!
If the difference between 'REGEDIT 4' and 'Windows Registry Editor Version 5.00' is not understood then a spot of reading is required. If folks are happier with 'Windows Registry Editor Version 5.00' then use it.
No source, no fun: "Sorry but, I won't touch it, even with gloves on." :-)
RunSwitch.exe was written using PowerBASIC and Jose Roca's header files, I am using his CWindow_InputBox, with ony 16 lines of code and is far from rocket science.

RunSwitch.exe is nine years old and has been used on Windows XP, Windows 7 and Windows 10 and has never put a foot wrong.
All above is based on experience, as a Domain-Admin, on mainly WIN-Servers diff. ver's.
My registry experience goes back to Windows 98. I wrote code to restore the registry to a previous version during a boot. Final testing included smashing the current registry before a restart. I wrote some defrag code as well - Windows 98 did not like large registry files.

If others "won't touch it, even with gloves on" but like the idea then they can write a FreeBASIC version of RunSwitch and publish it here.

If anyone uses my code and has a problem then let me know. I won't be holding my breath. <smile>
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Run with switches

Post by MrSwiss »

deltarho[1859] wrote:... is not understood then a spot of reading is required.
Is that similar to the reading, you've done, before *forcing* W10 Creators Upgrade, on your system?
With all the resulting problems, you're fond of describing, in detail ... (it was amusing reading). :-)

There is usually a reason (or reasons), why your *Box* isn't *cleared by MS*, for an automatic Upgrade.
It's also *common knowledge* that MS-releases are actually, what other Company's call *Beta*.
deltarho[1859] wrote:RunSwitch.exe was written using PowerBASIC and Jose Roca's header files ...
Btw: I've also had my stint with PB (version 2.10/2.11) so, reading the code, shouldn't be a problem.
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Run with switches

Post by deltarho[1859] »

Is that similar to the reading, you've done, before *forcing* W10 Creators Upgrade, on your system?
I had no problems with the first release of Windows 10, none with the November Update and none with the Anniversary Update. Well, I did. I only have a couple of shortcuts on my desktop and on each 'major' update they were given arrows. I have a registry script to remove them. There he goes messing with the registry again. <grin>. A friend of mine had big issues with every one of the major updates. His November Update was so bad he contacted Microsoft and they advised him to roll back, forget about it and wait for the Anniversary update. He waited for the Creators invite after I told him not to 'jump the gun' as I had done. His Creators Update was flawless, except for the arrows on his desktop shortcuts.

I had another issue. My power button no longer woke the system up from Sleep - the fan came on but nothing else. That issue is now being reported by other users. None of the 'solutions' put forward worked - clearly written by people who do not have the problem. In fact, the Creators Update made changes in this area which I have not seen mentioned by Microsoft or reviewers of Window 10. It took me a while but I figured out what they have done and now have the power button working as previously. The Power Options is missing a necessary comment.
Btw: I've also had my stint with PB (version 2.10/2.11) so, reading the code, shouldn't be a problem.
The better approach would be to write your own. As I mentioned it only takes a few lines of code and is far from rocket science. The 'engine' of the idea is the registry script and that is in the 'open'.

I have another utility, called PathToClip, which has either 'Filepath to Clipboard' or 'Folderpath to Clipboard' put into the right click context menu. Obvious what that does but that also uses a registry script so perhaps i should keep that to myself. <smile>
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Run with switches

Post by MrSwiss »

deltarho[1859] wrote:I have another utility, called PathToClip, which has either 'Filepath to Clipboard' or 'Folderpath to Clipboard' put into the right click context menu.
Obvious what that does but that also uses a registry script so perhaps i should keep that to myself. <smile>
No, feel free to do, as you like. That's what this Forum is all about.

The question about providing source code, might just be *popped up* by others here. Reasons are:
  • FB = multi: *OS and HW architecture* = easier to cater for, with source code, for:
    e.g. libraries / dll(s) / so(s) / helper(s) / utilities etc.
    This then means, one doesn't have to do: compiling for all the OS's/HW-bases etc.
    It is quite different, to PowerBASIC, which was focused on DOS/WIN/Intel only.
In short, FreeBASIC is more: "multi culti", as we call it in Switzerland (aka: multi cultural).
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Run with switches

Post by deltarho[1859] »

The question about providing source code, ...
I have only been here a short while and have 'knocked out' quite a bit of source code.

My opening post gave the forum a utility that I wrote nine years ago. The question of giving the forum the source code should not have risen. I have written many utilities ranging from updating the system clock in the background by polling time severs, downloading From and Subject from my mail server at a regular interval so that I can delete what I do not want before allowing the rest into my email client and many file encryption applications one of which uses AES CTR. Some friends have suggested that I should publish some as freeware but I do not have the time or the inclination. If I gave links to them here I would not expect people to give them the 'cold shoulder' because I didn't provide the source code any more than people giving CCLeaner, for example, the cold shoulder because CCleaner didn't publish the source code when it 'hit the streets' many years ago.

As implied RunSwitch is a simple little program but I won't be supplying the source code on principle now. As mentioned the essence of the idea is the registry script. There are many tutorials on the internet on how to include items in the right click context menu but I didn't leave that to members - I provided the script.
It is quite different, to PowerBASIC, which was focused on DOS/WIN/Intel only.
This thread is in the Windows forum. <Rolls eyes>
St_W
Posts: 1626
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Run with switches

Post by St_W »

Due to the open source nature of FreeBasic the open source spirit is probably more prevalent in these forums here than e.g. in PowerBasic forums, as PowerBasic was always closed-source software targetted at professionals. While I prefer project presentations which include the source code, I'm also totally fine with Freeware or paid closed-source software. Personally I think that asking for source code is fine in general, but it always depends on the how (you can probably guess that I don't really like the style of saying that as seen from some other users :-) ).

So thank You for sharing this tool and please feel free to share any other of your closed-source software you'd like to.
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Run with switches

Post by deltarho[1859] »

Thanks St_W.

I hope no one thinks that I an trying to hide something by not showing RunSwitch source code. I am afraid that I took exception to Mr Swiss' first post.

From what I have seen of the quality of code here since joining I should imagine many will be able able to write a FreeBASIC version of RunSwitch in just a few minutes.

If anyone would like to have a crack at it but are struggling to get the ball rolling here is a description of how RunSwitch works.

The giveaways are in the registry script: shell and command.

When we click on 'Run with Switches' in the right click context menu the command key default value is executed. The filepath of RunSwitch is given a command tail of %L. %L is replaced with the long filename of the exe we right clicked on. RunSwitch examines the command tail and if it is found empty then it knows that it was not invoked from the right click context menu. If not empty then the command tail is parsed to extract the file's extension. It only continues if it is EXE.

Having passed those two tests it is now a simple matter to concatenate the command tail with the switches typed into the input box and shell the result. Job done!

It is worth mentioning that 'Run with Switches' also appears in the right click context menu of shortcuts. The Chrome browser has hundreds of switches with most of them for developers but some are useful for users. We could, of course, add switches to the Target input box of the shortcut's property sheet but I find it handier to go via RunSwitch.
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Run with switches

Post by deltarho[1859] »

Just for the record here is my attempt at a FreeBASIC version of RunSwitch. It took longer than I anticipated; I could not find a GUI input dialog box. José Roca published one on May 03, 2017 - the day after this thread's opening post. Incredible! It will be published in the next version of his CWindow code. In the meantime here is the *** INPUT BOX DIALOG *** code. I have added it to the latest Release Candidate 27.

The PowerBASIC version of RunSwitch uses an old version of PowerBASIC so does not utilise some of the later parsing functions. Since I am using José's CWindow.inc I opted to use some of his parsing functions.

The output of the following is identical to the PowerBASIC version except the extension is dropped from the dialog box title.

For shelling I am using the Windows API ShellExecute.

Code: Select all

#INCLUDE ONCE "Afx/CWindow.inc"
 
Dim As String sExtension, sSwitch
 
If Len(Command) = 0 Then
  MessageBox( Null, "I only work from the right click context menu.", "RunSwitch", _
  MB_ICONINFORMATION + MB_TOPMOST + MB_OK)
  End
End If
 
sExtension = AfxGetFileExt( Command )
If LCase( sExtension ) <> ".exe" Then
  MessageBox( Null, UCase( Mid( sExtension, 2 ) ) + " file: I only work with EXE files.", "RunSwitch", _
  MB_ICONINFORMATION + + MB_TOPMOST + MB_OK )
  End
End If
 
sSwitch = AfxInputBox( 0, 0, 0, AfxGetFileName( Command ), "Please provide switches (Max 2048 chars)", "" )
If Len( sSwitch ) = 0 Then
  End
Else
  ShellExecute(0, "", Command, sSwitch , "", SW_SHOWNORMAL)
End If
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Run with switches

Post by deltarho[1859] »

I use Google Maps quite a lot but have noticed of late that it misbehaves in a variety of ways. I suspect that there is a conflict with one of my extensions in SlimJet, a variety of Google Chrome. However, in incognito mode Google Maps behaves itself.

If you have similar issues here is a fast way to use the incognito mode without having to open Chrome and go into incognito mode from there.

Simple right click on Chrome's shortcut, I have one in the tiles of Windows 10, click 'Run with switches' and type -incognito and then click OK.
Post Reply