|
-
Apr 5th, 2012, 01:47 PM
#1
Thread Starter
New Member
Re: How to separate code blocks in vbs
 Originally Posted by BoOkWoRm
You need to specify the path for the shortcut, example:
Code:
objLink.TargetPath = CurrentDirectory & "\downIt.bat"
Ok this is what I have now is this good code or should I still declare WorkingDirectory and TargetPath after DIM or no need?
Code:
option explicit
' Program starts running here.
call CreateShortCut()
sub CreateShortCut()
dim objShell, strEnvironment, objLink, CurrentDirectory
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"
objLink.TargetPath = CurrentDirectory & "\downIt.bat"
objLink.WindowStyle = 1
objLink.WorkingDirectory = CurrentDirectory
objLink.Hotkey = "CTRL+SHIFT+ALT+U"
objLink.Description = "This will update the scanner from the internet."
objLink.Save
end sub
-
Apr 5th, 2012, 02:12 PM
#2
Addicted Member
Re: How to separate code blocks in vbs
 Originally Posted by papayrus
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.
-
Apr 5th, 2012, 02:55 PM
#3
Thread Starter
New Member
Re: How to separate code blocks in vbs
 Originally Posted by His Nibbs
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.
-
Apr 5th, 2012, 03:35 PM
#4
Junior Member
Re: How to separate code blocks in vbs
 Originally Posted by papayrus
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.
For the sake of sanity and house cleaning, here's a better example to your final code above:
Code:
Option Explicit
Dim objShell, strEnvironment, objLink, CurrentDirectory
Set objShell = CreateObject("WScript.Shell")
CurrentDirectory = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
' Program starts running here.
Call CreateShortCut()
Sub CreateShortCut()
strEnvironment = objShell.ExpandEnvironmentStrings("%USERPROFILE%\Start Menu\Programs\Accessories")
Set objLink = objShell.CreateShortcut(strEnvironment & "\downIt.lnk")
objLink.Description = "Shortcut to downIt"
objLink.TargetPath = CurrentDirectory & "\downIt.bat"
objLink.WindowStyle = 1
objLink.WorkingDirectory = CurrentDirectory
objLink.Hotkey = "CTRL+SHIFT+ALT+U"
objLink.Description = "This will update the scanner from the internet."
objLink.Save
END Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|