Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...These forums are an excellent source and example of the way people can help each other..."

Geography

Where in the world do Tek-Tips members come from?
Briandr (MIS)
22 May 12 13:47
As part of our test roll out Office 2003 & 2007 were installed on the same computers of users. That being said Office 2007 was installed in a separate folder (c:\program file\microsoft office 2007). Post roll out new installs went back to the default folder (c:\program file\microsoft office 2007).

That being said I need to create desktop shortcuts for Outlook. I need to assume it could have been installed in one of two places. How can I tweak the below code to check for Outlook and create the shortcut as appropriate.

dim shell, desktopPath, link
Set shell = WScript.CreateObject("WScript.shell")
desktopPath = shell.SpecialFolders("AllUsersDesktop")
Set link = shell.CreateShortcut(desktopPath & "\Microsoft Outlook 2007.lnk")
link.Description = "Microsoft Outlook 2007"
link.TargetPath = "C:\Program Files\Microsoft Office\Office12\Outlook.exe"
link.WindowStyle = 3
link.WorkingDirectory = desktopPath
link.Save
set shell = nothing


Thanks.
Briandr (MIS)
23 May 12 13:07
Hi,

After messing around with this I ended up with:

Set shell = WScript.CreateObject("WScript.shell")
Set filesys = CreateObject("Scripting.FileSystemObject")
desktopPath = shell.SpecialFolders("AllUsersDesktop")
dim shell,desktop,link
dim filesys
If filesys.FileExists("C:\Program Files\Microsoft Office\Office12\Outlook.exe") Then
Set link = shell.CreateShortcut(desktopPath & "\Microsoft Outlook 2007.lnk")
link.Description = "Microsoft Outlook 2007"
link.TargetPath = "C:\Program Files\Microsoft Office\Office12\Outlook.exe"
link.WindowStyle = 3
link.WorkingDirectory = desktopPath
link.Save
set shell = nothing
End If
If filesys.FileExists("C:\Program Files\Microsoft Office 2007\Office12\Outlook.exe") Then
Set link = shell.CreateShortcut(desktopPath & "\Microsoft Outlook 2007.lnk")
link.Description = "Microsoft Outlook 2007"
link.TargetPath = "C:\Program Files\Microsoft Office 2007\Office12\Outlook.exe"
link.WindowStyle = 3
link.WorkingDirectory = desktopPath
link.Save
set shell = nothing
End If

I think this is good, but I am not sure if I should have anything else in there to jump out of the If-End If loops. Is it needed or overkill if what I have is good. Thanks.
goodfela26 (MIS)
23 May 12 17:20
Just cleaned it up a bit, though I didn't test it as I don't have Office 2007 installed on my system. If this will be a login or startup script, you may want to consider adding some sort of error handling and logging to help troubleshoot and avoid any popups that could cause the script to stall or annoy users.

dim shell,desktopPath,link
dim filesys

Set shell = WScript.CreateObject("WScript.shell")
Set filesys = CreateObject("Scripting.FileSystemObject")
desktopPath = shell.SpecialFolders("AllUsersDesktop")

If filesys.FileExists("C:\Program Files\Microsoft Office\Office12\Outlook.exe") Then
Set link = shell.CreateShortcut(desktopPath & "\Microsoft Outlook 2007.lnk")
link.Description = "Microsoft Outlook 2007"
link.TargetPath = "C:\Program Files\Microsoft Office\Office12\Outlook.exe"
link.WindowStyle = 3
link.WorkingDirectory = desktopPath
link.Save
End If
If filesys.FileExists("C:\Program Files\Microsoft Office 2007\Office12\Outlook.exe") Then
Set link = shell.CreateShortcut(desktopPath & "\Microsoft Outlook 2007.lnk")
link.Description = "Microsoft Outlook 2007"
link.TargetPath = "C:\Program Files\Microsoft Office 2007\Office12\Outlook.exe"
link.WindowStyle = 3
link.WorkingDirectory = desktopPath
link.Save
End If

Set filesys = Nothing
set shell = Nothing

---------------------------------------
Bob Beck
Systems Administrator

Briandr (MIS)
14 Jul 12 23:03
Hi All,

Needed to re-visit this one more time. Bob Beck, thanks for the help you gave me originally. I need to create a separate script to handle Windows 7 computers. With the Windows 7 computers I don't need to worry about Outlook being installed in one or more places. Admittedly I am not a VB scripting guru so can someone help adjust this for Windows 7?

dim shell,desktopPath,link
dim filesys

Set shell = WScript.CreateObject("WScript.shell")
Set filesys = CreateObject("Scripting.FileSystemObject")
desktopPath = shell.SpecialFolders("AllUsersDesktop")

If filesys.FileExists("C:\Program Files\Microsoft Office\Office12\Outlook.exe") Then
Set link = shell.CreateShortcut(desktopPath & "\Microsoft Outlook 2007.lnk")
link.Description = "Microsoft Outlook 2007"
link.TargetPath = "C:\Program Files\Microsoft Office\Office12\Outlook.exe"
link.WindowStyle = 3
link.WorkingDirectory = desktopPath
link.Save
End If

I want to say the only thing that needs changing beyond the file paths is the section dealing with 'SpecialFolders' I think. Which as before I want to make sure I am referencing AllUsersDesktops. I think that changed in W7. Not sure.

Thanks.
HughLerwill (Programmer)
15 Jul 12 6:27
goodfela26 (MIS)
16 Jul 12 12:09
Briandr,

The script should work fine in Windows 7. "AllUsersDesktop" is c:\users\public\desktop (assuming c: is your system drive) in Windows 7. The only thing you'll need to update is the path for Outlook, if that is different than what is currently in the script.

---------------------------------------
Bob Beck
Systems Administrator

Briandr (MIS)
17 Jul 12 18:29
AllUsersDesktop does not work on Windows 7. The script errors out.
goodfela26 (MIS)
17 Jul 12 19:14
Try this:

desktopPath = shell.SpecialFolders("Public") & "\Desktop"

---------------------------------------
Bob Beck
Systems Administrator

Briandr (MIS)
17 Jul 12 19:25
Apparently it does, but the account running the script has to have Admin rights. Thought the account I was testing with did have Admin rights. Way back when I seem to recall running into this. Like alot of these it got put on the back burner and now this whole thing jogged my memory as to what happened. I am good. Thanks.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close