Create Shortcuts using DOS batch files (1 Viewer)

ajetrumpet

Banned
Local time
Today, 11:31
Joined
Jun 22, 2007
Messages
5,638
all,

i have found this batch file on a website for windows 95 and 98. it creates a folder called "NEW FOLDER" in the programs list on the start menu. in the folder it creates a shortcut to the file you specified in the .bat file command. i am trying to run this on vista, and all i see in the CMD are the commenting sections. nothing else happens. there is no debugger for DOS, so i'm wondering if anyone might see an error here, or know of a different location for .inf file, or any other file or syntax that may need to be changed for the vista folder structure. thanks! (block in red is all one line)
Code:
@echo off


if %4[==[ goto syntax
if not exist %1 if not exist %1\nul goto syntax
for %%? in (%2 %3) do if not exist %%?\nul goto syntax
%5 %0 %1 %2 %3 %4 rem "{newfolder}" InstallHinfSection

[COLOR="Red"]echo > %temp%\#SHORTCUTTEST#.bat 
"C:\Users\Adam\STATS.MDB" %C:\Users\Adam\desktop% 
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs" "STATS" %1[/COLOR]

echo > %temp%\#k#.inf [version]
echo >>%temp%\#k#.inf signature="$chicago$"
echo >>%temp%\#k#.inf [DefaultInstall]
echo >>%temp%\#k#.inf UpdateInis=Addlink
echo >>%temp%\#k#.inf [Addlink]
echo >>%temp%\#k#.inf setup.ini, progman.groups,, "group0=%6"
echo >>%temp%\#k#.inf setup.ini, group0,, ""%6""
echo >>%temp%\#k#.inf setup.ini, group0,,""%4",""%path%"",,0,"

for %%? in (call del) do %%? %temp%\#path#.bat
start/w rundll setupx.dll,%7 DefaultInstall 132 %temp%\#k#.inf
del %temp%\#k#.inf
move "%3\{newfolder}\*.*" %2 > nul
rd "%3\{newfolder}"
goto end


:syntax
for %%? in (cls echo[) do %%?

for %%? in (pause cls echo[) do %%?


:end
pause
 

DCrake

Remembered
Local time
Today, 17:31
Joined
Jun 8, 2005
Messages
8,632
AJ
Here is a module that prompts the user if they want to create a shortcut when they first exit the application. This can be done at any time you wish.

Code:
Option Compare Database
Option Explicit

Function CreateDatabaseShortcut(Optional Location = "Desktop")
On Error GoTo CreateDatabaseShortcut_error

'Makes a shortcut to this database file in Location
'Location options are "Desktop","AllUsersDesktop","Favorites","StartMenu","AllUsersStartMenu","Startup","AllUsersStartup"

Dim shell, path, link, msg, r

Select Case Location
   Case "Desktop"
      msg = "Create a shortcut to the database on your desktop?"
   Case "AllUsersDesktop"
      msg = "Create a shortcut to the database on the desktop for all users of this machine?"
   Case "Favorites"
      msg = "Create a shortcut to the database in your list of favourites?"
   Case "StartMenu"
      msg = "Create a shortcut to the database in your Start All Programs Menu?"
   Case "AllUsersStartMenu"
      msg = "Create a shortcut to the database on the Start All Programs Menu for all users of this machine?"
   Case "Startup"
      msg = "Create a shortcut to the database in your Startup folder?"
      msg = msg & vbNewLine & "The database will open automatically every time you start this machine."
   Case "AllUsersStartup"
      msg = "Create a shortcut to the database in the Startup folder for all users of this machine?"
      msg = msg & vbNewLine & "The database will open automatically every time this machine is started."
   Case Else
      MsgBox "Not a valid shortcut to the database location: " & Location, vbExclamation + vbOKOnly, "Error in CreateDatabaseshortcut to the database"
      GoTo CreateDatabaseShortcut_Exit
End Select

r = MsgBox(msg, vbQuestion + vbYesNo, "Confirm")
If r = vbNo Then GoTo CreateDatabaseShortcut_Exit

Set shell = CreateObject("WScript.shell")
path = shell.SpecialFolders(Location)
Set link = shell.CreateShortcut(path & "\" & "NAME OF SHORTCUT" & ".lnk")

link.Description = "NAME OF SHORTCUT"
link.TargetPath = CurrentProject.path & "\" & CurrentProject.Name
link.WindowStyle = 3
link.WorkingDirectory = CurrentProject.path
link.Save

msg = Replace(msg, "Create a Shortcut to the database", "A shortcut to the database has been created")
msg = Replace(msg, "?", ".")
MsgBox msg, vbOKOnly + vbInformation, "Shortcut Created"
   
CreateDatabaseShortcut_Exit:
On Error Resume Next
Set shell = Nothing
Exit Function

CreateDatabaseShortcut_error:
Select Case Err
   Case Else
      MsgBox Err & "-" & Error$, vbCritical + vbOKOnly, "Error in module CreateDatabaseShortcut"
      Resume CreateDatabaseShortcut_Exit
End Select
End Function

Function MakeShortcut()
On Error GoTo MakeShortcut_error

   Dim s As String
   Dim r As Long
      s = "Would you like me to create a shortcut to this database on"
      s = s & vbNewLine
      s = s & "your desktop so that you can find it again later?"
      s = s & vbNewLine & vbNewLine
      r = MsgBox(s, vbYesNo + vbQuestion, "Make Shortcut?")
      If r = vbYes Then
         CreateDatabaseShortcut
      End If

MakeShortcut_Exit:
On Error Resume Next
Exit Function

MakeShortcut_error:
Select Case Err
   Case Else
      MsgBox Err & "-" & Error$, vbCritical + vbOKOnly, "Error in module MakeShortcut"
      Resume MakeShortcut_Exit
End Select
End Function

You can also beef it up by asking them where they want to create the shortcut (not included).

Might be worth while saving in code respository if desired.

David
 

Users who are viewing this thread

Top Bottom