' Make sure variables are declared.
option explicit
' Program starts running here.
call CreateShortCut()
sub CreateShortCut()
dim objShell, strEnvironment, objLink
set objShell = CreateObject("WScript.Shell")
strEnvironment = objShell.ExpandEnvironmentStrings("%USERPROFILE%\Start Menu\Programs\Accessories")
CurrentDirectory = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
set objLink = objShell.CreateShortcut(strEnvironment & "\downIt.lnk")
objLink.Description = "Shortcut to downIt"
TargetPath = CurrentDirectory & "\downIt.bat"
objLink.WindowStyle = 1
WorkingDirectory = CurrentDirectory
objLink.Hotkey = "CTRL+SHIFT+ALT+U"
objLink.Description = "This will update the scanner from the internet."
objLink.Save
end sub
Last edited by papayrus; Apr 5th, 2012 at 12:08 AM.
' Make sure variables are declared.
option explicit
' Program starts running here.
call CreateShortCut()
sub CreateShortCut()
dim objShell, strEnvironment, objLink
set objShell = CreateObject("WScript.Shell")
strEnvironment = objShell.ExpandEnvironmentStrings("%USERPROFILE%\Start Menu\Programs\Accessories")
CurrentDirectory = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
set objLink = objShell.CreateShortcut(strEnvironment & "\downIt.lnk")
objLink.Description = "Shortcut to downIt"
TargetPath = CurrentDirectory & "\downIt.bat"
objLink.WindowStyle = 1
WorkingDirectory = CurrentDirectory
objLink.Hotkey = "CTRL+SHIFT+ALT+U"
objLink.Description = "This will update the scanner from the internet."
objLink.Save
end sub
With the Option Explicit defined you need to include/set all variables accordingly. Try this:
Code:
' Make sure variables are declared.
option explicit
' Program starts running here.
call CreateShortCut()
sub CreateShortCut()
dim objShell, strEnvironment, objLink, CurrentDirectory, TargetPath, WorkingDirectory
set objShell = CreateObject("WScript.Shell")
strEnvironment = objShell.ExpandEnvironmentStrings("%USERPROFILE%\Start Menu\Programs\Accessories")
CurrentDirectory = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
set objLink = objShell.CreateShortcut(strEnvironment & "\downIt.lnk")
objLink.Description = "Shortcut to downIt"
TargetPath = CurrentDirectory & "\downIt.bat"
objLink.WindowStyle = 1
WorkingDirectory = CurrentDirectory
objLink.Hotkey = "CTRL+SHIFT+ALT+U"
objLink.Description = "This will update the scanner from the internet."
objLink.Save
end sub
With the Option Explicit defined you need to include/set all variables accordingly. Try this:
Code:
' Make sure variables are declared.
option explicit
' Program starts running here.
call CreateShortCut()
sub CreateShortCut()
dim objShell, strEnvironment, objLink, CurrentDirectory, TargetPath, WorkingDirectory
set objShell = CreateObject("WScript.Shell")
strEnvironment = objShell.ExpandEnvironmentStrings("%USERPROFILE%\Start Menu\Programs\Accessories")
CurrentDirectory = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
set objLink = objShell.CreateShortcut(strEnvironment & "\downIt.lnk")
objLink.Description = "Shortcut to downIt"
TargetPath = CurrentDirectory & "\downIt.bat"
objLink.WindowStyle = 1
WorkingDirectory = CurrentDirectory
objLink.Hotkey = "CTRL+SHIFT+ALT+U"
objLink.Description = "This will update the scanner from the internet."
objLink.Save
end sub
This actually has no errors and creates the link in accessories and all the items are there accept for the target path and the start in directory boxes are empty in the shortcuts properties. I created a directory and put the downIt.bat in it with the make shortcut VBS here. Am I doing something wrong? I added an attachment screenshot of the links shortcut properties so you can see what I mean.
EDIT::
Just want to add that if in the 2 lines TargetPath = CurrentDirectory & "\downIt.bat" and WorkingDirectory = CurrentDirectory I add to the beginning of those lines objLink. it seems to work perfectly. So should I change them to objLink.TargetPath = CurrentDirectory & "\downIt.bat" and objLink.WorkingDirectory = CurrentDirectory or is this wrong? I also find that if I delete the declarations of TargetPath and WorkingDirectory it is working fine as well.
Last edited by papayrus; Apr 5th, 2012 at 01:18 PM.
should I still declare WorkingDirectory and TargetPath after DIM or no need?
WorkingDirectory and TargetPath are properties of the objLink variable (a shortcut object) which you have declared, so they are not separate variables and there's no need to declare (Dim) them.
With Option Explicit you will get an undefined variable error message if any variables are undefined, so it serves as an essential development aid. Therefore always use Option Explicit.
WorkingDirectory and TargetPath are properties of the objLink variable (a shortcut object) which you have declared, so they are not separate variables and there's no need to declare (Dim) them.
With Option Explicit you will get an undefined variable error message if any variables are undefined, so it serves as an essential development aid. Therefore always use Option Explicit.
Ok so they are part of objLink already like a family but I am confused then about current directory is that part of the objLink property?
EDIT I just thought about it am thinking that no it is not because it is a directory in itself and not part of what a link would be or something like that.