Announcement

Collapse
No announcement yet.

Call a description of an existing shortcut

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Call a description of an existing shortcut

    I have a script that I have been using for a while now that creates a shortcut in a folder in My Documents and sets a user input description to the created shortcut that can be shown in windows explorer by showing "Comments".

    The script does multiple other things and may be ran multiple times for a given job so it is getting rather tedious to retype a description every time the script is ran. I would like for the script to check if the shortcut exists and if so automatically populate the user input box for the description (jobDescription) with the existing description.

    Here is the working part of the script:
    Code:
    	JobDescription=Inputbox("Optional: Enter a short description of the job","Job Description", CurrentJob )
    	If jobDescription = "" then
    	   jobDescription = CurrentJob
      end If  
      set WshShell = WScript.CreateObject("WScript.Shell")
        strDocuments = "C:\Documents and Settings\" & name & "\My Documents\Released Jobs"
        strLink = strDocuments & "\" & job & ".lnk"
      set oShellLink = WshShell.CreateShortcut(strLink)
        oShellLink.TargetPath = "\\okcsxds01\TS\Jobs\active\ENG\" & job & "\"
        oShellLink.Description = JobDescription
        oShellLink.WorkingDirectory = "\\okcsxds01\TS\Jobs\active\ENG\" & job & "\"
        oShellLink.Save
    Any help/suggestions would be greatly appreciated.

    Thanks,
    Tyler
    Last edited by Rems; 4th January 2011, 20:55.

  • #2
    Re: Call a description of an existing shortcut

    check if the shortcut exists and, if so automatically populate the user input box for the description (jobDescription) with the existing description:
    Code:
    Const CSIDL_MY_DOCUMENTS = &H5&
    
    CurrentJob = "missing variable 1"
    job = "missing variable 2"
    
    
    strDocuments = GetSpecialFolder(CSIDL_MY_DOCUMENTS) & "\Released Jobs"
    strLink = strDocuments & "\" & job & ".lnk"
    
    set WshShell = WScript.CreateObject("WScript.Shell")
    Set fso = CreateObject("scripting.filesystemobject")
    
    set oShellLink = WshShell.CreateShortcut(strLink)
    
    If fso.FileExists(strLink) Then
       jobDescription = oShellLink.Description
       JobDescription = Trim( _
         Inputbox("Optional: Enter a new short description of the job", _
         "Job Description", jobDescription ))
    End If
    
    If jobDescription = "" then
       jobDescription = CurrentJob
    End If
    
    oShellLink.TargetPath = "\\okcsxds01\TS\Jobs\active\ENG\" & job & "\"
    oShellLink.Description = JobDescription
    oShellLink.WorkingDirectory = "\\okcsxds01\TS\Jobs\active\ENG\" & job & "\"
    
    If NOT fso.FolderExists(strDocuments) Then fso.CreateFolder(strDocuments)
    oShellLink.Save
    
    Function GetSpecialFolder(sfolder)
       With CreateObject("Shell.Application")
          With .Namespace(sfolder)
             GetSpecialFolder = .Self.Path
          End With
       End With
    End Function
    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment

    Working...
    X