Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

how can i create a shortcut from a batch file?

- - - - -

  • Please log in to reply
28 replies to this topic

#1
someuser77

someuser77

    Newbie

  • Member
  • 27 posts
hello
i am writing a small batch file and i need it to create a shortcut on Windows 2000 to a specific file.
i know it can be done in vbs, the question is how do i do it in a batch file?


How to remove advertisement from MSFN

#2
oneless

oneless

    Advanced Member

  • Member
  • PipPipPip
  • 374 posts
I dont know how can you creat a link with a batch file ,
but when I need once that
I created the link manually , I save it (is a file)
and then I copy the link in the right
location on another computer .
if the destination file is also in the right place
(where point the link) , is ok !
     oneLess

#3
someuser77

someuser77

    Newbie

  • Member
  • 27 posts
well, in that case i will have to carry around 2 files: the .bat and the .lnk. no fun.
the point is to make one file, that will generate what it needs.

#4
MtK

MtK

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 909 posts

hello
i am writing a small batch file and i need it to create a shortcut on Windows 2000 to a specific file.
i know it can be done in vbs, the question is how do i do it in a batch file?

<{POST_SNAPBACK}>

you could use this:
Shortcut creator
Posted Image
"Know Your Limits And Ignore Them..."

#5
someuser77

someuser77

    Newbie

  • Member
  • 27 posts
thank you for your reply, but again:
i will need to carry around 2 files: the .bat and the .exe. no fun.
the point is to make one file, that will generate what it needs.
do you think it can be done?
i found something over here but the code is too messy for me to read. :blushing:
do you think it can be rewritten to somehting?

#6
MtK

MtK

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 909 posts

thank you for your reply, but again:
i will need to carry around 2 files: the .bat and the .exe. no fun.
the point is to make one file, that will generate what it needs.
do you think it can be done?
i found something over here but the code is too messy for me to read.  :blushing:
do you think it can be rewritten to somehting?

<{POST_SNAPBACK}>

where exactly is the SHORCUT code over there?
Posted Image
"Know Your Limits And Ignore Them..."

#7
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag
I dont know if this will help here is a script that makes shortcuts .

It Works Like This
1\ You input a name
2\ You Type In a number for a icon from shell32.dll
3\ A Dialog opens up amd you use that to select the app you want
a short cut to.
4\ It leaves the shortcut on desktop.
Edit To Your Needs

  Dim shell, X1, X2, X3, Mx2, Mx2a, Z2

     Set Shell = WScript.CreateObject("WScript.Shell")
     Set ObjFSO = CreateObject("UserAccounts.CommonDialog")
    
  function recall
  X2=ObjFSO.FileName
  Mx2 = "You Selected: " & X2
  shell.popup Mx2 , 3, "Gsm ShortCut Maker", 0 + 64
  end function

  function NotThere
  X3="No File Was Selected" & Vbcrlf & "Preparing To Quit"
  shell.popup  X3, 3, "Exiting Script",0 + 64
  end function

  Function GsmGetFile
  ObjFSO.Filter = "All Files|*.*"
  InitFSO = ObjFSO.ShowOpen
  If InitFSO = False Then
   NotThere
   Wscript.Quit
Else
   X2=ObjFSO.FileName
   recall
   Set Shell = nothing
   Set ObjFSO = nothing
End If
End Function

  Set sh = CreateObject("WScript.Shell")
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set oWS = WScript.CreateObject("WScript.Shell")
  struser = InputBox("Type In The Name Of The ShortCut","GsmMakeShortCut","GsmSC")
  strIcon = InputBox("Type In The Icon You Want From Shell32.dll" &_
  vbCrLf & "Recommended Icons Number Are" & vbCrLf & "15" & Space(5) & "19" & Space(5) & "155, ","GsmMakeShortCut","GsmSC")
  GsmGetFile
  strApp = X2  
         set WshShell = WScript.CreateObject("WScript.Shell")
         strDesktop = WshShell.SpecialFolders("Desktop")
         set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & struser & ".lnk")
         oShellLink.TargetPath = strApp
         oShellLink.WindowStyle = 1
         oShellLink.Hotkey = "Ctrl+Alt+e"
         oShellLink.IconLocation = "shell32.dll," & strIcon 'Zero is the index        
         oShellLink.Description = "Shortcut Script"
         oShellLink.WorkingDirectory = "\.."
         oShellLink.Save
         wshShell.Popup "Hello",4, "Gsm",0+48+1024


Edited by gunsmokingman, 28 December 2005 - 01:34 AM.



GunSmokingMan



#8
Aegis

Aegis

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,298 posts
Or an even better method:

RUNDLL32.EXE APPWIZ.CPL,NewLinkHere (Dest)

#9
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag

Or an even better method:

RUNDLL32.EXE APPWIZ.CPL,NewLinkHere (Dest)

<{POST_SNAPBACK}>


Tell Me how it better
Can you choice the icon
Can you select any thing on your local hard drive
Does it have the a hot key attach to it.
oShellLink.Hotkey = "Ctrl+Alt+e"
Plus It leave it on the desktop, and with minor
modification you could leave it on the start menu.

I tried it and could not find any short cuts or get it to work
on my desktop.


GunSmokingMan



#10
someuser77

someuser77

    Newbie

  • Member
  • 27 posts

where exactly is the SHORCUT code over there?

its a batch script designed to make a shortcut. or so it says.

thanks for the code gunsmokingman, but i will have to add a .vbs file to the batch, i'll do so if theres no other way.

Aegis, the line opens a wizard that requires user input. losing the point of the script.

what i did manage to do is to find this article about making shortcuts, but i cant get it to work. :no:
[Version] 
signature="$CHICAGO$"
[DefaultInstall]
UpdateInis=Addlink
[AddLink] 
setup.ini, progman.groups,, "group1=""c:\""" 
setup.ini, group1,,"""thisIsMyShortcut"",""explorer.exe"",,,,,""explorer.exe"""


#11
Kelsenellenelvian

Kelsenellenelvian

    WPI Guru

  • Developer
  • 8,739 posts
  • OS:Windows 7 x64
  • Country: Country Flag
Make the short cut, zip it in an sfx file and direct the sfx file to unzip silently to wherever the destination is.

#12
someuser77

someuser77

    Newbie

  • Member
  • 27 posts
again, in that case i will have 2 files: .bat and .exe
i am trying to make only one .bat file that will do the job.
i know i can make one .exe file that will hold all the files i need, but i wouldnt want users to think they have to install something when they dont.

#13
Martin Zugec

Martin Zugec

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,373 posts
2someuser: You cant make shortcut from batch file - only thing you can do is to create "temporary" script/inf file from batch, call it and delete it after - this is the same technology as Rob used in your link.
Like my opinions? Read Deployment/scripting blog
Like my scripts? They are under DrinkWare license :)

#14
someuser77

someuser77

    Newbie

  • Member
  • 27 posts
okay.
.vbs and .inf are bouth silent, right?
so we know how to make a .vbs, now how do i make a .inf that will create a shortcut?

#15
Martin Zugec

Martin Zugec

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,373 posts
Simple...

[version]
signature=$chicago$

[DefaultInstall]
UpdateInis=AddShortcut

[AddShortcut]
setup.ini, progman.groups,, "group1=""Calculator Group"""
setup.ini, group1,,"""Calculator"",""%windir%\system32\calc.exe"",,,,%17%"

Like my opinions? Read Deployment/scripting blog
Like my scripts? They are under DrinkWare license :)

#16
Martin Zugec

Martin Zugec

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,373 posts
What exactly would you like to do?
Like my opinions? Read Deployment/scripting blog
Like my scripts? They are under DrinkWare license :)

#17
brian873

brian873

    Advanced Member

  • Member
  • PipPipPip
  • 335 posts
http://www.abyssmedia.com/

This compay do a program called Qick Batch File Compiler. It converts your batch file to a an EXE and lets you inclued customs resources such as other files. Although not a batch file in the end you will only have onne file to carry around.

Maybe not what you are looking for but someting to think about

hail hail

#18
someuser77

someuser77

    Newbie

  • Member
  • 27 posts
when i try to install the inf file i get the error:
Posted Image

#19
Martin Zugec

Martin Zugec

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,373 posts
You got XP, right?
Like my opinions? Read Deployment/scripting blog
Like my scripts? They are under DrinkWare license :)

#20
someuser77

someuser77

    Newbie

  • Member
  • 27 posts
windows 2000 SP4.
thats why i posted in the windows 2000 forum. ;)
but it shouldnt make any difference. does it?

#21
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,530 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

You need to search this site, two different methods using inf files have been posted regarding this subject. One of the subjects has been discussed in the last few days. Try a search for +inf +shortcut

#22
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag
If You want to run a vbs from batch plus clean up the files
This makes it only 1 file
Green is what you add to the script
Blue is the script varible

Echo off && Cls && Mode 55,5 && Color 5e && Title Shortcut
set VBS=%systemdrive%\MyVbsShortcut.vbs
>> %vbs% echo  Dim WshShell : set WshShell = WScript.CreateObject("WScript.Shell")
>> %vbs%echo  Dim Fso : set Fso = WScript.CreateObject("Scripting.FileSystemObject")
>> %vbs%echo  strDesktop = WshShell.SpecialFolders("Desktop")
>> %vbs%echo  set oShellLink = WshShell.CreateShortcut(strDesktop ^& "\  PLACE_NAME_HERE .lnk")
>> %vbs% echo   oShellLink.TargetPath = THE_LOCATION_OF_THE_SHORTCUT_TO_APP 'EG: NOTEPAD.EXE
>> %vbs%echo  oShellLink.WindowStyle = 1
>> %vbs%echo  oShellLink.Hotkey = "Ctrl+Alt+e"
>> %vbs%echo  oShellLink.IconLocation = "shell32.dll, ^& PLACE_NUNBER_OF_ICON_HERE " 'Zero is the index        
>> %vbs% echo   oShellLink.Description = "My shortcut to NAME_WHATEVER"
>> %vbs%echo  oShellLink.WorkingDirectory = "\.."
>> %vbs%echo   oShellLink.Save
>> %vbs%echo           wshShell.Popup "Hello",4, "Gsm",0+48+1024 'This Line Is safe to remove
>> %vbs%echo  Fso.deleteFile("NAME_OF_BATCH_HERE")
>> %vbs%echo  Fso.deleteFile(" %vbs% ")

start %vbs%


Edited by gunsmokingman, 12 May 2005 - 05:24 PM.



GunSmokingMan



#23
someuser77

someuser77

    Newbie

  • Member
  • 27 posts
thank you for your help, but i need to get access to the windir, unfortenately this is not working:
Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.Environment("Volatile").Item("windir")
it returns a blank line.

#24
someuser77

someuser77

    Newbie

  • Member
  • 27 posts
all done. :D
thanks to everyone for your help!

#25
Raynold

Raynold
  • Member
  • 7 posts
hi,
I am new in this forum, so please guide my way...

I have foxit pdf reader that no need to be installed, just copy it into root directory or somewhere else...
my problem is, how do I make an automatic foxit shortcut into desktop ?

thanks...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN