No announcement yet.

To Create a Desktop Shortcut Icon by Scripting

  • Filter
  • Time
  • Show
Clear All
new posts

  • To Create a Desktop Shortcut Icon by Scripting

    Greetings first post and completely lost on where to go from where I am at.

    Goal: To create a Lock Workstation Icon on the Desktop.

    I know that I can create a batch that can be pushed down by GP. The issue is actually creating the batch. I have tried several different examples that were posted on some of the threads from this site and been to the Microsoft website and had no success. Each attempt I would get the following message, "(fill in the blank) is not a recognized as an internal or external command, operable program or batch file." I have been trying to drop it in the Folder; documents and settings/all users/desktop and I know what the target is for the application.

    I am, by no means, proficient in scripting. I am more of an end-user support person. Any thoughts (I know I need to learn a lot more about scripting, to get somewhere) and help would be greatly appreciated.

  • #2
    Re: To Create a Desktop Shortcut Icon by Scripting

    On Error Resume Next 
    Dim sPath, sFilename
    Set objShell = CreateObject("WScript.Shell")
    Set objFso = CreateObject("Scripting.FileSystemObject")
    strPath = objShell.SpecialFolders("AllUsersDesktop") & "\"
    strFilename = "Lock Workstation.lnk"
    If Not objFso.FileExists(strPath & strFilename) Then
      Set oLink = objShell.CreateShortcut(strPath & strFilename)
       oLink.TargetPath = "rundll32.exe"
       oLink.Arguments = "user32.dll,LockWorkStation"
       oLink.Description = "Lock Workstation"
       oLink.WorkingDirectory = "c:\windows\system32"
       oLink.IconLocation = "Shell32.dll, 44"
    End If
    Create a blank text file, paste in the code. Rename the file with a .vbs extension and add it to your gp logon script.
    Last edited by ahinson; 21st October 2006, 00:00.

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **


    • #3
      Re: To Create a Desktop Shortcut Icon by Scripting

      I had a similar requirement (not desktop locking, just a UNC shortcut) however after extensive searching I could not find the answer, so i figured it out anyway.

      here is my result

      Set objShell=Wscript.CreateObject("")
      strDesktopFolder=objShell.SpecialFolders("Desktop") & _
      Set objShortcut=objShell.CreateShortcut(strDesktopFolder & _
       "The Name of the shortcut.lnk")
      objShortCut.TargetPath = "\\server\folder"
      objShortCut.Description = "Open Company Documents"
      "...if I turn out to be particularly clear, you've probably misunderstood what I've said” - Alan Greenspan