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
LVL 1
sendtojpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Operating Systems

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.