Jump to content

Recommended Posts

Posted

i have the code below (now granted its pilfered rather than written by me) and it sort of works to pin items to taskbar/start screen but if i remove next it fails and if i leave it it adds in an infinate loop any ideas as to whats wrong?

 

Set objShell = CreateObject("Shell.Application")

Set objFolder = objShell.Namespace("C:\Windows\")

Set objFolderItem = objFolder.ParseName("Notepad.exe")

Set colVerbs = objFolderItem.Verbs

For Each objVerb in colVerbs

If Replace(objVerb.name, "&", "") = "Pin to Start" Then objVerb.DoIt

Wscript.Echo("Added shortcut to Start Screen")

If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt

Wscript.Echo("Added shortcut to Taskbar")

next

End If

'Next

Posted

You're code is a bit wrong. The Ifs arent encased properly so the messages will print for every verb and the Next is in the wrong place:

 

Set objShell = CreateObject("Shell.Application") 
Set objFolder = objShell.Namespace("C:\Windows\")
Set objFolderItem = objFolder.ParseName("Notepad.exe") 
Set colVerbs = objFolderItem.Verbs 
For Each objVerb in colVerbs
   If Replace(objVerb.name, "&", "") = "Pin to Start" Then
       objVerb.DoIt
       Wscript.Echo("Added shortcut to Start Screen")
   End If
   If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then
       objVerb.DoIt
       Wscript.Echo("Added shortcut to Taskbar")
   End If
Next

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...