Link to home
Start Free TrialLog in
Avatar of sendtojp
sendtojp

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of tymes
tymes
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sendtojp
sendtojp

ASKER

tymes,


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

barrymercer,

Thanks for writing the shell command


Thanks

-JP
Even be a VB programmer I am unfamilar with a *.vbs file, how is this ran?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
posting 2:41 was posted before 2:33
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.
name = Wscript.arguments(0)
target = Wscript.arguments(1)

I get a subscrit out of range error
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

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.  
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/