WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Shortcut Information

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Shortcuts Take Over From Program Manager (Progman) and DDE

Keywords: shortcuts shortcutmake DDE Progman 

Windows 95 and Windows NT 4.0 have eliminated the need to use Dynamic Data Exchange to change the Program Manager Groups and Icons. As a matter of fact, the Program Manager no longer exists. Programs and Groups now appear on the Desktop, on the Start Menu and in the Windows Explorer as Files and Folders. Icons which appear on the Desktop and on the Start Menu generally appear in the Windows directory under the sub-directories Start Menu and Desktop.
For example:   C:\WINDOWS\Start Menu\
	       C:\WINDOWS\Desktop\
To manipulate Files and Folders, use the WinBatch File and Shortcut commands. We've created some sample code demonstrating how you might manipulate the Windows Explorer to reflect your changes in Groups and Icons.

Firstly, determine whether you're on a Windows 95 or NT 4.0 machine, before proceeding further. If you know you're on an appropriate system, you can skip this part in your own code.

 
        if ( (WinMetrics(-4) >= 4) && (WinVersion(@MAJOR)>=4))   ; Win95  or NT 4.0
                Explorer=AppExist("Explorer")
        else
                Explorer=0    ; for all else force explorer off
        endif
        
        If Explorer == 0 
                Message("Group and Icon Test", "No Explorer found, exiting program.")
                exit
        endif

MAKE SHORTCUT IN THE USER PROFILE DIRECTORY:

AddExtender("WWNET34I.DLL")
USERNAME=Environment("USERNAME")

ShortCutMake("C:\WINNT\PROFILES\%USERNAME%\SENDTO\WinZip62.lnk","V:\WINAPPS\WINZIP.62\WINZIP.EXE","V:\WINAPPS\WINZIP.62\WINZIP.EXE","V:\WINAPPS\WINZIP.62\",@NORMAL)

GET PROGRAM DIRECTORY:

There are two ways of writing to the Start Menu. You can hard code the line:
      thestart="C:\Windows\Start Menu\"
However, be aware. This approach will not work in all circumstances. The Start Menu could be in another place. The fool proof way to find the Start Menu and other program icon information is to look in the Registry.
 
strtdir=RegQueryValue(@REGCURRENT,"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders[Programs]")
Message("GET PROGRAM DIRECTORY", "The start directory is %@CRLF% %@CRLF% %strtdir%. %@CRLF%%@CRLF% Look under Explorer to verify.") 

CREATE A GROUP:

Groups are simply directories in the new Windows interface. No major hoop jumping is involved in their creation. Simply dust off the WinBatch Dir commands and voila, a group you'll have.

First check to see if the destination directory you want already exists. If it doesn't exist, then create it with DirMake. Change to this new directory.

  
        newdir="%strtdir%\Yowsa"
        If DirExist (newdir) == @true 
                DirChange(newdir)
        else 
                DirMake(newdir)
                DirChange(newdir)
        endif
        Message("CREATE A GROUP", "The new directory is %@CRLF%%@CRLF% %newdir%")

CREATE AN ICON:

Icons are no longer limited to the Program Manager. They appear everywhere in the new Windows interface. Nor do you need to do anything special to make them appear. Everytime you copy or write a file of any type to a new place, that file will automatically show its icon.

The Windows 95 interface has a handy feature which allows you to access a file from multiple places. Instead of leaving multiple copies of files here and there, you can create a shortcut which points to the exe. A shortcut can be placed in a dozen different places without the hoopla of needing to install again or waste disk space or deal with file version management.

In making an icon, you can copy a file to a directory with the command FileCopy or you can use ShortcutMake to create a *.lnk file. In our example, ShortcutMake will create a few icons in the current directory. Before we create them though, we will check to see if they're already there with FileExist.

  
if FileExist("Add Me Up.lnk") == @FALSE 
	    ShortcutMake("Add Me Up.lnk", "C:\WINDOWS\CALC.EXE", "", "C:\WINDOWS\", @NORMAL)
endif 
if FileExist("write my notes.lnk") == @FALSE 
	    ShortcutMake("write my notes.lnk", "C:\WINDOWS\NOTEPAD.EXE", "", "C:\WINDOWS\", @NORMAL)
endif 
if FileExist("Solitaire.lnk") == @FALSE 
	    ShortcutMake("Solitaire.lnk", "C:\WINDOWS\sol.exe", "", "C:\WINDOWS\", @NORMAL)
endif 
Message("CREATE AN ICON", "Feel free to look under %newdir% for the new files.")

DELETE AN ICON

Just as creating an icon is easily accomplished using either the File or Shortcut commands, its deletion is equally simple. There is no Shortcut command for deletion. Once a shortcut is made, it is treated as a file thereafter.
 
if FileExist("write my notes.lnk") == @TRUE then FileDelete("write my notes.lnk")
if FileExist("Solitaire.lnk") == @TRUE then FileDelete("Solitaire.lnk")
Message("DELETE AN ICON", "Now check %newdir%.  %@CRLF%%@CRLF% Were two of the files deleted?")

DELETE A GROUP:

Since a group is nothing more than a directory, use the DirRemove command to delete it. The catch is, with WinBatch, a directory must be empty before it can be removed.
   ;DirRemove(newdir) 
in this case would result in an error. "1030 DirRemove: Dir not removed." Delete the semi-colon and run it if you'd like to see the error first hand.

So, if the directory needs to be empty, then you'll need to empty it. Try the following:

	     
	filelist=FileItemize("*.*")	  ;Grab a list of files in the current directory.
	 
	Use a loop to delete the files...
	count=ItemCount(filelist, @TAB)	  ;Count the number of files in the directory.
	For i = 1 to count			     ;Delete the files in a loop
		item=ItemExtract(i, filelist, @TAB)  ;Grab each file one at a time
		FileDelete(item)		     ;Delete the file
	Next
	
	FileDelete(filelist)	   ; ...Or delete the list in one commmand.
	
	DirChange("C:\")	   ; Change to a different directory so the other can be removed.
	DirRemove(newdir)	   ; With the directory empty of files, DirRemove should now work.
	message("DELETE A GROUP", "The directory has been removed. %@CRLF%%@CRLF% We're done.")
Now you should have all the necessary pieces to wreck havoc with your users' directories. Deleting their favorite icons, changing their groups, hiding their files.
 
      
 
 exit
 

Article ID:   W13855
Filename:   Shortcuts Take over From ProgMan - Examples.txt
File Created: 2001:03:01:12:21:34
Last Updated: 2001:03:01:12:21:34