Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Script to copy a shortcut to all users and overwrite an existing one.

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,28113
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Script to copy a shortcut to all users and overwrite an existing one.
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Script to copy a shortcut to all users and overwrite an... - 11/17/2005 11:04:40 PM   
  Woodzter

 

Posts: 57
Score: 0
Joined: 10/25/2005
Status: offline
I need a script to copy a shortcut from a location on our server to the  all users desktop and all users start menu. All staff currently have  a shortcut in this location but after reconfiguring our network the current short cut points to the wrong place. With 2000+ users, i cannot rely on them creating their own.

Is there a way i can have a script that copies the new shortcut and tells it to over write the old one.

Also if run in a GPO on Computer Configuration will it have the authority to do it or do i need a admin password in the script?

Thanks
 
 
Post #: 1
 
 RE: Script to copy a shortcut to all users and overwrit... - 11/18/2005 7:05:31 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
I have done a script exactly what you need and it works perfectly.

I put this script under user instead of computer. i'm sure it'll work both ways.

This script will delete the shortcut you don't want on the user's desktop and will create a new shortcut which you want from a certain location in the server to their desktop


Option Explicit
Dim oFS, oWsh, oNetwork, strUser, Shell
Dim DesktopPath, link
Dim folder, file, icon1, icon2, icon3, icon4, icon5
Set oWsh = CreateObject("WScript.Shell")
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
Set oNetwork= CreateObject("Wscript.Network")
Set Shell = CreateObject("WScript.Shell")
strUser = oNetwork.UserName
DesktopPath = Shell.SpecialFolders("Desktop")
Set link = Shell.CreateShortcut(DesktopPath & "\Phone List.lnk")  'the new shortcut name
link.TargetPath = "\\Prod2\N_Drive\Public\Phone List Update\PHONELIST.XLS"  ' the location where you store the file on the server
link.Save
icon1 = UCase(oWsh.SpecialFolders("Desktop") & "\PHONELIST.XLS.lnk")  'these are the ones i wanted to delete
icon2 = UCase(oWsh.SpecialFolders("Desktop") & "\Shortcut to PHONELIST.lnk") 'these are the ones i wanted to delete
icon3 = UCase(oWsh.SpecialFolders("Desktop") & "\PHONELIST.lnk") 'these are the ones i wanted to delete
icon4 = UCase(oWsh.SpecialFolders("Desktop") & "\BLA PHONE LIST.XLS.lnk") 'these are the ones i wanted to delete
icon5 = UCase(oWsh.SpecialFolders("Desktop") & "\PHONELIST.XLS") 'these are the ones i wanted to delete
Set folder = oFS.GetFolder(DesktopPath)
For Each file In folder.Files
Select Case UCase(file)
Case icon1
oFS.DeleteFile(file)
Case icon2
oFS.DeleteFile(file)
Case icon3
oFS.DeleteFile(file)
Case icon4
oFS.DeleteFile(file)
Case icon5
oFS.DeleteFile(file)
Case Else
End Select
Next
WScript.Quit (0)

(in reply to Woodzter)
 
 
Post #: 2
 
 RE: Script to copy a shortcut to all users and overwrit... - 11/20/2005 3:59:37 AM   
  Woodzter

 

Posts: 57
Score: 0
Joined: 10/25/2005
Status: offline
@kracksmith

Not quite what i wanted, but it will definately come in for oter job ahead. First of all thanks fo ryour time to help me.

i need to explain a little more i feel. I have a shorcut on the server called 'cssvert' I manually copied this shortcut from another pc. It launches a .exe file on each individual users pc. They currently have a shortcut already but it is now pointing to a out dated exe file. What i want to be able to do is copy my shortcut from the server to 'All Users>Desktop & the All Users>Strat Menu>Programs folder'. They currently have a exact name shortcut in those places, I want a script to be able to copy to these locations and overwrite the original shortcuts.

(in reply to kracksmith)
 
 
Post #: 3
 
 RE: Script to copy a shortcut to all users and overwrit... - 11/20/2005 7:15:02 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
Woodzter,

KrackSmith's example is what you need, only you need to tweak some...

Example:

ShortcutPath = "C:\Documents and Settings\All Users\"

'delete the old shortcut, you could add a FileExist() just in case a user doesn't have the old shortcut
objFSO.DeleteFile(ShortcutPath & "Desktop\Phone List.lnk")
objFSO.DeleteFile(ShortcutPath & "Start Menu\Programs\Phone List.lnk")

'store the new shortcut
Set ProgramsLink = Shell.CreateShortcut(ShortcutPath & "Start Menu\Programs\Phone List.lnk") 
ProgramsLink.TargetPath =  "\\Prod2\N_Drive\Public\Phone List Update\PHONELIST.XLS" 
ProgramsLink.Save

Set DesktopLink = Shell.CreateShortcut(ShortcutPath & "Desktop\Phone List.lnk") 
DesktopLink.TargetPath = "\\Prod2\N_Drive\Public\Phone List Update\PHONELIST.XLS" 
DesktopLink.Save

< Message edited by Snipah -- 11/20/2005 7:16:11 AM >


_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to Woodzter)
 
 
Post #: 4
 
 RE: Script to copy a shortcut to all users and overwrit... - 11/20/2005 10:26:46 AM   
  Woodzter

 

Posts: 57
Score: 0
Joined: 10/25/2005
Status: offline
Is the scripts just creating a new shortcut...........?

I just want to delete the curent shortcut and icon a nd copy my shortcut which i have on the server to the same locations?

(in reply to Snipah)
 
 
Post #: 5
 
 RE: Script to copy a shortcut to all users and overwrit... - 11/20/2005 10:28:49 PM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
quote:

objFSO.DeleteFile(ShortcutPath & "Desktop\Phone List.lnk")


This line DELETES the current shortcut

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to Woodzter)
 
 
Post #: 6
 
 RE: Script to copy a shortcut to all users and overwrit... - 11/21/2005 2:45:25 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
I see what you want.

you have a shortcut somewhere in the server

and you want this shortcut from the server to be on their desktop


1st, why do you want to work off a shortcut from the server?

I'm not very good in scripting so I can't write a new script for your case unless i spend a lot of time researching it out putting it together.

I'm sure there are some experts here that can write one out quickly or at least help you more

but can't you work off the original file from the server instead of working it off the shortcut from the server?

if you can work the original off from the server then my script above would be perfect.

(in reply to Snipah)
 
 
Post #: 7
 
 RE: Script to copy a shortcut to all users and overwrit... - 11/21/2005 6:33:40 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
Is he saying he wants a shortcut to a shortcut?

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to kracksmith)
 
 
Post #: 8
 
 RE: Script to copy a shortcut to all users and overwrit... - 11/22/2005 9:31:17 PM   
  Woodzter

 

Posts: 57
Score: 0
Joined: 10/25/2005
Status: offline
Sorry i have not been back sooner guys. As you have probarbly guessed i am new to scripting and need all the help i can get. On ths current post i decided to try and use what you have helped me with and try and understand and adapt to use for myself.

1st..... the shorcut i wanted to delete i had problems with. They were created during a MSI software install and did not want to be deleted. So i first concentrated on a script to delete these first. I dabbled with the'if files does not exist do nothing' part of scripting because once the script ran a second time it threw up a error. I mastered this after a bit of playing and help from the internet.

2nd..... i needed to copy the shortcut.lnk files i had on the server to the new loactions on the users laptops and workstations. I did this with a simple batch file copy command and it worked well
So I am now sorted with the problem i had.

I would like to move away form .bat files and use all vbscripts but because of the lack of time i have to practice i have to do what i know works.

My knowledge has improved slighty (very slighty ) and i am pleased with what i have done bit i know you guys could probarbly do one script that will do the lot in one go but i'm afraid i have a lot more basic knowledege to pick up yet.

We all have to start some where i guess.?

Thanks for both of you for helping me......

This is a copy of the vb and ,bat file i used.

.bat


copy /Y  \\serverlocatopn\"shortcut.lnk" "C:\Documents and Settings\All Users\Desktop\*.*"
copy /Y \\serverlocatopn\"shortcut.lnk" "C:\Documents and Settings\All Users\Start Menu\Programs\*.*"


vbscript to delete

Call DeleteIfFound ("C:\Documents and Settings\All Users\Desktop\shortcut.lnk")

 Function DeleteIfFound (FilePath)
  Dim Fso
  Set Fso = CreateObject ("Scripting.FileSystemObject")
  If Fso.FileExists (FilePath) Then
   Fso.DeleteFile (FilePath)
  End If
  Set Fso = Nothing
 End Function

Call DeleteIfFound ("C:\Documents and Settings\All Users\Start Menu\Programs\shortcut.lnk.lnk")

 Function DeleteIfFound (FilePath)
  Dim Fso
  Set Fso = CreateObject ("Scripting.FileSystemObject")
  If Fso.FileExists (FilePath) Then
   Fso.DeleteFile (FilePath)
  End If
  Set Fso = Nothing
 End Function



(in reply to Snipah)
 
 
Post #: 9
 
 RE: Script to copy a shortcut to all users and overwrit... - 11/23/2005 1:57:08 AM   
  Country73


Posts: 712
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
Something like this should work out for you-

If Fso.FileExists("\\" & strComputer & "\c$\Documents and Settings\All Users\Desktop\shortcut.lnk")Then
Fso.DeleteFile "\\" & strComputer & "\c$\Documents and Settings\All Users\Desktop\shortcut.lnk"
Fso.CopyFile "\\" & strServer & "\Share\Location_of_Shortcut\shortcut.lnk", "\\" & strComputer & "\c$\Documents and Settings\All Users\Desktop\"
End If

Or you could just use this which will overwrite the shortcut if it is found

Fso.CopyFile "\\" & strServer & "\Share\Location_of_Shortcut\shortcut.lnk", "\\" & strComputer & "\c$\Documents and Settings\All Users\Desktop\",True

< Message edited by Country73 -- 11/23/2005 2:11:02 AM >

(in reply to Woodzter)
 
 
Post #: 10
 
 RE: Script to copy a shortcut to all users and overwrit... - 11/23/2005 4:56:03 AM   
  Woodzter

 

Posts: 57
Score: 0
Joined: 10/25/2005
Status: offline
Thanks,

I knew someone could make it easier.

(in reply to Country73)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Script to copy a shortcut to all users and overwrite an existing one. Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts