create a shortcut using VB

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
So i have a VB script that looks like this.here we go

Question for which operating system (1 for win 7/vista and 2 for xp)
strMenu="Select which operating system you are using" & VbCrLf &_
""& VbCrLf &_
"1. Windows 7 / Vista 64 bit" & VbCrLf &_
"2. Windows xp" & VbCrLf &_
"3. Windows 7 / vista 32 bit" & VbCrLf &_
""
Input for os
os=InputBox(strMenu,"OS Selection",1)

Set default constructors for operating system path for the start menu
xp="Documents and SettingsAll UsersStart MenuPrograms"
sevenvista="ProgramDataMicrosoftWindowsStart MenuPrograms"

User will choose a default program to use or will create their own.
pselection="Select which program you are creating a shortcut for" & VbCrLf &_
""& VbCrLf &_
"1. Create your own/not on list"+" "+"2. Itunes" & VbCrLf &_
"3. Google Chrome"+" "+"4. Webroot" & VbCrLf &_
"5. kaspersky"+" "+"6. Norton" & VbCrLf &_
"7. Microsoft Office" & VbCrLf &_
""

Start of the switch
selection=InputBox(pselection,"Program Selection",1)
If IsNumeric(selection) Then
Select Case selection

Start if first case structure
Case 1
Custom Shortcut creator
Questions for creation of shortcut
Destination question
dest=InputBox("What folder will the shortcut be saved in? c:program datamicrosoftwindowsstart menuprograms <already included")
Target path question
tp=InputBox("Where is the program location? c:program filesPROGRAM LOCATION <already included")
Description/icon name question
description=InputBox("Name of the shortcut")
Working directory question
wd=InputBox("what is the working directory? C:Program filesWORKINGDIRECTORY")

Set oWS = WScript.CreateObject("WScript.Shell")
if os = 1 then sLinkFile = "C:"+sevenvista+dest+""+description+".lnk"
if os = 2 then sLinkFile = "C:"+xp+dest+""+description+".lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
oLink.TargetPath = "c:ProgramFiles"+tp
oLink.Arguments = ""
oLink.Description = description
oLink.IconLocation = "c:program files"+tp
oLink.WorkingDirectory = "c:program files"+wd
oLink.WindowStyle = "1"
oLink.Save

Case 2
iTunes shortcut creation
if os = 2 then user=InputBox("What is the user name")
Set oWS = WScript.CreateObject("WScript.Shell")
if os = 1 then sLinkFile = "c:"+sevenvista+"iTunes"+"Itunes.lnk"
if os = 2 then sLinkFile = "c:"+xp+"iTunes"+"Itunes.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
if os = 1 then oLink.TargetPath = "c:program files(x86)iTunesiTunes.exe"
if os = 2 then oLink.TargetPath = "c:program filesiTunesiTunes.exe"
oLink.Arguments = ""
oLink.Description = iTunes
if os = 1 then oLink.IconLocation = "c:program files(x86)iTunesiTunes.exe"
if os = 2 then oLink.IconLocation = "c:program filesiTunesiTunes.exe"
if os = 1 then oLink.WorkingDirectory = "c:program files(x86)iTunes"
if os = 2 then oLink.WorkingDirectory = "c:program filesiTunes"
oLink.WindowStyle = "1"
oLink.Save

Case 3
Google Chrome Shortcut creation
if os = 2 then user=InputBox("What is the user name")
Set oWS = WScript.CreateObject("WScript.Shell")
if os = 1 then sLinkFile = "c:"+sevenvista+"iTunes"+"Itunes.lnk"
if os = 2 then sLinkFile = "C:Documents and Settings"+user+"Start MenuProgramsGoogle ChromeGoogle Chrome.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
if os = 1 then oLink.TargetPath = "c:program files(x86)iTunesiTunes.exe"
if os = 2 then oLink.TargetPath = "%userprofile%Local SettingsApplication DataGoogleChromeApplicationChrome.exe"
oLink.Arguments = ""
oLink.Description = iTunes
if os = 1 then oLink.IconLocation = "c:program files(x86)iTunesiTunes.exe"
if os = 2 then oLink.IconLocation = "%userprofile%Local SettingsApplication DataGoogleChromeApplicationChrome.exe"
if os = 1 then oLink.WorkingDirectory = "c:program files(x86)iTunes"
if os = 2 then oLink.WorkingDirectory = "%userprofile%Local SettingsApplication DataGoogleChromeApplication"
oLink.WindowStyle = "1"
oLink.Save

Case 4
Webroot Shortcut
WrSelection="Which version do you have?" & VbCrLf &_
""& VbCrLf &_
"1. Webroot spy Sweeper"+" "+"2. Webroot Secure Anywhere" & VbCrLf &_
""

webrootselection=InputBox(wrselection,"Webroot Shortcut Selection",1)
If IsNumeric(webrootselection) Then
Select Case selection
Webroot Spy Sweeper
Case 1
if os = 2 then user=InputBox("What is the user name")
Webroot Secure Anywhere
Case 2

End Select
Else
WScript.Echo "Invalid option. Numbers only."
End If


Case 5
Kaspersky Shortcut
kselection="Which version do you have?" & VbCrLf &_
""& VbCrLf &_
"1. Kaspersky 2008"+" "+"2. Kaspersky 2009" & VbCrLf &_
"3. Kaspersky 2010"+" "+"4. Kaspersky 2011" & VbCrLf &_
"5. Kaspersky 2012"& VbCrLf &_
""

kasselection=InputBox(kselection,"Webroot Shortcut Selection",1)
If IsNumeric(kasselection) Then
Select Case kasselection

Kas 2008
Case 1


Kas 2009
Case 2

kas 2010
Case 3

kas 2011
Case 4

Kas 2012
Case 5




End Select
Else
WScript.Echo "Invalid option. Numbers only."
End If

Case 6
Norton Shortcut


Case 7
Microsoft shortcut
mSelection="Which version do you have?" & VbCrLf &_
""& VbCrLf &_
"1. Office 2007 Home and student" & VbCrLf &_
"2. Office 2007 Home and Business" & VbCrLf &_
"3. Office 2007 Professional"& VbCrLf &_
""& VbCrLf &_
"4. Office 2010 Home and Student" & VbCrLf &_
"5. Office 2010 Home and Business"& VbCrLf &_
"6. Office 2010 Professional" & VbCrLf &_
""

moselection=InputBox(mSelection, "Microsoft Office shortcut selection", 1)
If IsNumeric(moselection) Then
Select Case moselection

Case 1
Office 2007 home and student
Word
if os = 2 then user=InputBox("What is the user name")
Set oWS = WScript.CreateObject("WScript.Shell")
if os = 1 then sLinkFile = "c:"+sevenvista+"Microsoft Office"+"Microsoft Word 2007.lnk"
if os = 2 then sLinkFile = "c:"+xp+"Microsoft Office"+"Microsoft Word 2007.lnk"
if os = 3 then sLinkFile = "c:"+sevenvista+"Microsoft Office"+"Microsoft Word 2007.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
if os = 1 then oLink.TargetPath = "C:Program Files(x86)Microsoft OfficeOffice12WINWORD.exe"
if os = 2 then oLink.TargetPath = "C:Program FilesMicrosoft OfficeOffice12WINWORD.exe"
if os = 3 then oLink.TargetPath = "C:Program FilesMicrosoft OfficeOffice12WINWORD.exe"
oLink.Arguments = ""
if os = 1 then oLink.IconLocation = "C:Program Files(x86)Microsoft OfficeOffice12WINWORD.exe"
if os = 2 then oLink.IconLocation = "C:Program FilesMicrosoft OfficeOffice12WINWORD.exe"
if os = 3 then oLink.IconLocation = "C:Program FilesMicrosoft OfficeOffice12WINWORD.exe"
if os = 1 then oLink.WorkingDirectory = "C:Program Files(x86)Microsoft Office"
if os = 2 then oLink.WorkingDirectory = "C:Program FilesMicrosoft Office"
if os = 3 then oLink.WorkingDirectory = "C:Program FilesMicrosoft Office"
oLink.WindowStyle = "1"
oLink.Save

excel
Set oWS = WScript.CreateObject("WScript.Shell")
if os = 1 then sLinkFile = "c:"+sevenvista+"Microsoft Office"+"Microsoft Excel 2007.lnk"
if os = 2 then sLinkFile = "c:"+xp+"Microsoft Office"+"Microsoft Excel 2007.lnk"
if os = 3 then sLinkFile = "c:"+sevenvista+"Microsoft Office"+"Microsoft Excel 2007.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
if os = 1 then oLink.TargetPath = "C:Program Files(x86)Microsoft OfficeOffice12excel.exe"
if os = 2 then oLink.TargetPath = "C:Program FilesMicrosoft OfficeOffice12excel.exe"
if os = 3 then oLink.TargetPath = "C:Program FilesMicrosoft OfficeOffice12excel.exe"
oLink.Arguments = ""
if os = 1 then oLink.IconLocation = "C:Program Files(x86)Microsoft OfficeOffice12excel.exe"
if os = 2 then oLink.IconLocation = "C:Program FilesMicrosoft OfficeOffice12excel.exe"
if os = 3 then oLink.IconLocation = "C:Program FilesMicrosoft OfficeOffice12excel.exe"
if os = 1 then oLink.WorkingDirectory = "C:Program Files(x86)Microsoft Office"
if os = 2 then oLink.WorkingDirectory = "C:Program FilesMicrosoft Office"
if os = 3 then oLink.WorkingDirectory = "C:Program FilesMicrosoft Office"
oLink.WindowStyle = "1"
oLink.Save

Power Point
Set oWS = WScript.CreateObject("WScript.Shell")
if os = 1 then sLinkFile = "c:"+sevenvista+"Microsoft Office"+"Microsoft Power Point 2007.lnk"
if os = 2 then sLinkFile = "c:"+xp+"Microsoft Office"+"Microsoft Power Point 2007.lnk"
if os = 3 then sLinkFile = "c:"+sevenvista+"Microsoft Office"+"Microsoft Power Point 2007.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
if os = 1 then oLink.TargetPath = "C:Program Files(x86)Microsoft OfficeOffice12POWERPNT.exe"
if os = 2 then oLink.TargetPath = "C:Program FilesMicrosoft OfficeOffice12POWERPNT.exe"
if os = 3 then oLink.TargetPath = "C:Program FilesMicrosoft OfficeOffice12POWERPNT.exe"
oLink.Arguments = ""
if os = 1 then oLink.IconLocation = "C:Program Files(x86)Microsoft OfficeOffice12POWERPNT.exe"
if os = 2 then oLink.IconLocation = "C:Program FilesMicrosoft OfficeOffice12POWERPNT.exe"
if os = 3 then oLink.IconLocation = "C:Program FilesMicrosoft OfficeOffice12POWERPNT.exe"
if os = 1 then oLink.WorkingDirectory = "C:Program Files(x86)Microsoft Office"
if os = 2 then oLink.WorkingDirectory = "C:Program FilesMicrosoft Office"
if os = 3 then oLink.WorkingDirectory = "C:Program FilesMicrosoft Office"
oLink.WindowStyle = "1"
oLink.Save

One Note
Set oWS = WScript.CreateObject("WScript.Shell")
if os = 1 then sLinkFile = "c:"+sevenvista+"Microsoft Office"+"Microsoft OneNote 2007.lnk"
if os = 2 then sLinkFile = "c:"+xp+"Microsoft Office"+"Microsoft OneNote 2007.lnk"
if os = 3 then sLinkFile = "c:"+sevenvista+"Microsoft Office"+"Microsoft OneNote 2007.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
if os = 1 then oLink.TargetPath = "C:Program Files(x86)Microsoft OfficeOffice12onenote.exe"
if os = 2 then oLink.TargetPath = "C:Program FilesMicrosoft OfficeOffice12onenote.exe"
if os = 3 then oLink.TargetPath = "C:Program FilesMicrosoft OfficeOffice12onenote.exe"
oLink.Arguments = ""
if os = 1 then oLink.IconLocation = "C:Program Files(x86)Microsoft OfficeOffice12onenote.exe"
if os = 2 then oLink.IconLocation = "C:Program FilesMicrosoft OfficeOffice12onenote.exe"
if os = 3 then oLink.IconLocation = "C:Program FilesMicrosoft OfficeOffice12onenote.exe"
if os = 1 then oLink.WorkingDirectory = "C:Program Files(x86)Microsoft Office"
if os = 2 then oLink.WorkingDirectory = "C:Program FilesMicrosoft Office"
if os = 3 then oLink.WorkingDirectory = "C:Program FilesMicrosoft Office"
oLink.WindowStyle = "1"
oLink.Save



End Select
Else
WScript.Echo "Invalid option. Numbers only."
End If


End Select
Else
WScript.Echo "Invalid option. Numbers only."
End If


ANYWAY... I wanted to use VB to create the shortcuts. I saw some example of how to do it, but im just get an error message. I searched here and found this http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/74cf6cd6-d04c-4a0e-9119-1ddf565f9497 but it wasnt much help.
I point in the right direction is all i need. Thanks in advance.

View the full article
 
Back
Top