• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 633
  • Last Modified:

Create shortcut to the desktop and Start --> Programs win 98'-XP in a batch file

I am creating a package of a program and runing the Installation in a Batch file.

The shortcut is pointing to a file in "Program files" (i.e.  %appdata%)

Thank You

-JP
0
sendtojp
Asked:
sendtojp
  • 8
  • 3
3 Solutions
 
tymesCommented:
DesktopShortcut "Shortcut to Program", "%programfiles%\Appdir\App.exe"

Save following file as DesktopShortcut.vbs
...
Dim WSHShell, fsObj
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set fsObj = WScript.CreateObject("Scripting.FileSystemObject")
Function DesktopShortcut( name, target )
 Dim Shortcut,DesktopPath,StartupPath
 DesktopPath = WSHShell.SpecialFolders("Desktop")
 Set Shortcut = WSHShell.CreateShortcut(DesktopPath & "\" & name & ".lnk")
 Shortcut.TargetPath = target
 StartupPath = fsObj.GetParentFolderName( target )
 If fsObj.FolderExists( StartupPath ) then
    Shortcut.WorkingDirectory = StartupPath
 End If
 Shortcut.Save
End Function
0
 
barrymercerCommented:
This is the start menu for "all users"
%allusersprofile%\start menu\programs

which on my system (xp)is C:\Documents and Settings\All Users\Start Menu\Programs
0
 
sendtojpAuthor Commented:
tymes,


The two shortcut cuts I want to make are to the desktop & Programs

barrymercer,

Thanks for writing the shell command


Thanks

-JP
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
sendtojpAuthor Commented:
Even be a VB programmer I am unfamilar with a *.vbs file, how is this ran?
0
 
tymesCommented:
desktop=%userProfile%\Desktop\
programs=%userProfile%\Programs\Start Menu\
or for everyone
desktop=%AllusersProfile%\Desktop\
programs=%AllusersProfile%\Programs\Start Menu\

Adjust the script accordingly.

Yeah, and I just cut the script out of some stuff I had.  I guess it shouldn't be a function, add
replace the Function line with
name = Wscript.arguments(0)
target = Wscript.arguments(1)
and remove the End Function line.

Perhaps add a third parameter destination too.
Destination = Wscript.arguments(2)
which would replace the DesktopPath line and variable references.


0
 
sendtojpAuthor Commented:
Here is the contents of the vbs, I meant to write 'Even being a VB Programmer I '
never used a vbs  before'.  I uess you live and you learn something.

There is a problem with the code  I placed MSGBOX's between the code line with the error.  The code reachs 'point1' but not 'point2'
'........................

 DesktopShortcut "Shortcut to Program", "%programfiles%\Appdir\Test.vbs"

'Save following file as DesktopShortcut.vbs

Dim WSHShell, fsObj
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set fsObj = WScript.CreateObject("Scripting.FileSystemObject")
Function DesktopShortcut( name, target )
 Dim Shortcut,DesktopPath,StartupPath
  msgbox "point1"
  DesktopPath = WSHShell.SpecialFolders("Desktop")
 msgbox "point2"
 Set Shortcut = WSHShell.CreateShortcut(DesktopPath & "\" & name & ".lnk")
 Shortcut.TargetPath = target
 StartupPath = fsObj.GetParentFolderName( target )
 If fsObj.FolderExists( StartupPath ) then
    Shortcut.WorkingDirectory = StartupPath
 End If
 Shortcut.Save
End Function
0
 
sendtojpAuthor Commented:
posting 2:41 was posted before 2:33
0
 
sendtojpAuthor Commented:
tymes,

If you are interested I have code to open an Access 2003 database without the Access warning poping up.  Off topic but it is good code to have.
0
 
sendtojpAuthor Commented:
name = Wscript.arguments(0)
target = Wscript.arguments(1)

I get a subscrit out of range error
0
 
sendtojpAuthor Commented:
Also how do you declear a string in a vbs file


'........................
Dim WSHShell, fsObj
Dim Desktop, Programs As String


Desktop = "%AllusersProfile%\Desktop\"
Programs = "%AllusersProfile%\Programs\Start Menu\"



 DesktopShortcut "Shortcut to Program", "%programfiles%\Appdir\Test.vbs"

'Save following file as DesktopShortcut.vbs


Set WSHShell = Wscript.CreateObject("WScript.Shell")
Set fsObj = Wscript.CreateObject("Scripting.FileSystemObject")
name = Wscript.arguments(0)
target = Wscript.arguments(1)


'Function DesktopShortcut(name, target)
 Dim Shortcut, DesktopPath, StartupPath
  MsgBox "point1"
  DesktopPath = WSHShell.SpecialFolders("Desktop")
 MsgBox "point2"
 Set Shortcut = WSHShell.CreateShortcut(DesktopPath & "\" & name & ".lnk")
 Shortcut.TargetPath = target
 StartupPath = fsObj.GetParentFolderName(target)
 If fsObj.FolderExists(StartupPath) Then
    Shortcut.WorkingDirectory = StartupPath
 End If
 Shortcut.Save
'End Function

0
 
sendtojpAuthor Commented:
Intellisense doesn't seem to work on WSHShell?

Set WSHShell = Wscript.CreateObject("WScript.Shell") ' For reference


Is there a object model description for this?

Is there a .SpecialFolders("Program files")


Does this work on '98 thru XP

I got it to generate a shortcut with modifyation.  
0
 
tymesCommented:
If you're doing this to install something, you should just use nullsoft's installer and forget about making your own install script.  You won't need to care about windows versions or about wshshell stuff or directories etc.

http://nsis.sourceforge.net/
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now