Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

desktop shortcut

Status
Not open for further replies.

Briandr

MIS
Jul 11, 2003
177
US
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.
 
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.
 
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
 
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.
 
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
 
AllUsersDesktop does not work on Windows 7. The script errors out.
 
Try this:

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

---------------------------------------
Bob Beck
Systems Administrator
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top