December 08, 2021, 04:51:37 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
   Home   Help Search Login Register  
Pages: [1]
Author Topic: New VB6 Tutorial: Creating Shell Commands  (Read 3762 times)
Posts: 3655

« on: March 22, 2004, 09:55:23 AM »

I hope this helps someone out...I've tested this in Windows 98 as well as Windows XP, so it seems to be quite universal.

by Necros Ihsan Nodtveidt
Finished March 22nd, 2004 at 12:31AM Atlantic Standard Time! Smiley

This quick tutorial is intended to show how to create simple shell commands for folders. It is not intended to be used as a registry guide, nor an exhaustive programming guide. It is assumed that the user has a solid understanding of string manipulation and directory structure.

I recommend downloading the Registry Module for quickest results in this demonstration. It's a collection of registry and control functions that are not intrinsic to Visual Basic 6. It is comprised of mostly third-party code snippets.

Basic shell commands are kept within HKEY_CLASSES_ROOT under the Directory key. The focus of this quick tutorial is on the 'shell' key under the Directory key.

We'll need a "Parent" key that will contain a value to be displayed in the shell. For the purposes of this demonstration, we'll call it "My.Command". Create a key like so:


As with all created keys, there will be a Default value. You will need to alter this to change the text for your shell command. If using the Registry Module from this page, you set a default value by passing no value for the 'Key' argument. The ampersand rule applies in setting the default value, so you'll be able to set a keyboard shortcut just like when you build any menu in Visual Basic 6.

Now that you have the Parent key, you need a Command key. Create a child key from My.Command:


This will tell Windows that your new key has a command that can be invoked. Again, this new key has a default value which you will set with your executable file and a %1. You will need to enclose both in double quotes, like so:

   "C:\Program Files\My Program\My Program.exe" "%1"

You can easily do this in VB by using Chr$(34).

-Upon using your new shell command, your application will receive a Command$ when it starts. This Command$ will likely be enclosed in double quotes.
-Multiple folders can be selected and opened with your new shell command. When this happens, multiple instances of your program are started.
-This technique can also be used on the Drive key as opposed to the Directory key. This will pass the root of the drive as the Command$. This can be quite useful for programs which affect entire drives.
-Don't use + to combine strings. VB will convert string variables to Variants before combining them if you use this method, which is inefficient. Use & to combine string variables.
-An easy way of keeping the registry setting up-to-date in case your program ever moves is to write its location on startup using the application's current path. An often-used mistake is to directly rely on App.Path for this. However, since App.Path will return a backslash for a drive root and no backslash for normal directories, it is wise to copy App.Path to a string variable and then check its last character with the Right$ function. It is always a good idea to make sure your directory string has a trailing backslash:

   Dim appie As String
   appie = App.Path
   If Right$(appie, 1) <> "\" Then appie = appie & "\"

I'd knock on wood, but my desk is particle board.
Posts: 4550

« Reply #1 on: March 24, 2004, 02:29:13 PM »

Woohoo! Thanx nek. This will surely help me in my VB progging =)
Pages: [1]
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!