laptopC Posted October 30, 2007 Posted October 30, 2007 Hello.Is it possible to copy shortcut from network share to all users desktop with computer startup script?I have tried these: (Finnish version of Windows is in use so työpöytä = desktop)copy /y \\server\share\shortcut.lnk "c:\documents and settings\all users\työpöytä\"copy /y \\server\share\shortcut.lnk "c:\documents and settings\all users\työpöytä\shortcut.lnk"..but it wont work. Is there a problem with ä and ö? Or is it even possible to do this with system account?I would like to do this is because I want to upgrade one application that has been previously installed fromsetup.exe and the new version of this app would be installed from .MSI. The problem is that users would haveshortcuts in their desktops pointing nowhere because the new version installs elsewhere than previous.
Yzöwl Posted October 30, 2007 Posted October 30, 2007 My suggestion is a VBScript which searches for that specific shortcut name on the all users desktop and replaces the location of the target path with your new one.
laptopC Posted October 30, 2007 Author Posted October 30, 2007 Thanks. It worked with VBScript. The code looked something like this:Set oWS = WScript.CreateObject("WScript.Shell")sLinkFile = "C:\documents and settings\all users\työpöytä\link.lnk"Set oLink = oWS.CreateShortcut(sLinkFile)oldpath=oLink.TargetPathnewpath="C:\program files\program\executable.exe"oLink.WorkingDirectory="C:\program files\program"oLink.TargetPath=newpathoLink.SaveThe original script failed to copy links to directory with letters ä and ö. Tested this with temp directory.
gunsmokingman Posted October 30, 2007 Posted October 30, 2007 Thanks. It worked with VBScript. The code looked something like this:Set oWS = WScript.CreateObject("WScript.Shell")sLinkFile = "C:\documents and settings\all users\työpöytä\link.lnk"Set oLink = oWS.CreateShortcut(sLinkFile)oldpath=oLink.TargetPathnewpath="C:\program files\program\executable.exe"oLink.WorkingDirectory="C:\program files\program"oLink.TargetPath=newpathoLink.SaveThe original script failed to copy links to directory with letters ä and ö. Tested this with temp directory.Try thisConst ALL_USERS_DESKTOP = &H19&Dim Folder, FolderPath, newpath, oLink, oWS, Shell, sLinkFileSet Shell = CreateObject("Shell.Application")Set Folder = objShell.Namespace(ALL_USERS_DESKTOP)Set FolderPath = objFolder.SelfSet oWS = WScript.CreateObject("WScript.Shell")sLinkFile = FolderPath.PathSet oLink = oWS.CreateShortcut(sLinkFile)oldpath=oLink.TargetPathnewpath="C:\program files\program\executable.exe"oLink.WorkingDirectory="C:\program files\program"oLink.TargetPath=newpathoLink.Save
Yzöwl Posted October 30, 2007 Posted October 30, 2007 Well it seems from what you've posted that the task is a lot simpler than I'd presumed. I thought that the shortcut you were hoping to deploy was for an application on the server. To do what you'd originally hoped for something like this would probably suffice:Const CommonDesktop = &H19&Const OverwriteExisting = TRUE'ShortcutstrSC = "\\Server\Share\link.lnk"Set objShell = CreateObject("Shell.Application")Set objFolder = objShell.Namespace(CommonDesktop)Set objFolderItem = objFolder.SelfstrAUDesktop = objFolderItem.PathSet objFSO = CreateObject("Scripting.FileSystemObject")objFSO.CopyFile strSC, strAuDesktop, OverWriteExistingIf you wanted to do as I originally intimated, i.e search all shortcuts on the all users desktop for a the old string and replace it with the new one, you could try something like thisConst CDtop = &H19&Set oApp = CreateObject("Shell.Application")Set oShell = CreateObject("WScript.Shell")Set oFso = CreateObject("Scripting.FilesystemObject")' String in the target property to search forsTargetStrOld = "C:\Program Files\OldProgDir\executable.exe"' New string to setsTargetStrNew = "C:\Program Files\NewProgDir\executable.exe"Set oDir = oApp.Namespace(CDtop)Set oDItem = oDir.SelfsLocn = oDItem.PathChkLnk(sLocn)Sub ChkLnk (sFolder) Set oFolder = oFso.GetFolder(sFolder) Set oFiles = oFolder.Files For Each oFile In oFiles If LCase(oFso.GetExtensionName(oFile)) = "lnk" Then Set oLnk = oShell.CreateShortcut(oFile) If LCase(oLnk.TargetPath) = LCase(sTargetStrOld) Then oLnk.TargetPath = sTargetStrNew oLnk.Save End If End If NextEnd SubThis one should work regardless of whether the shortcut name has been changed.In both cases and the example provided by gunsmokingman, you'll note that we've used constants which specify the All Users Desktop folder regardless of its actual name/spelling etc.
laptopC Posted October 31, 2007 Author Posted October 31, 2007 (edited) Thanks again from answers. Here is some backgroud.The application is locally installed, and it is currently installed from setup.exe which install it to c:\program files\appdirectory\. It is also available in MSI package which installs it to c:\program files\appdirectory2\. I have a script that checks computers registry and if the string for MSI install is not found the uninstall is started and new version from MSI is installed. Something like this:reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{the-string-goes-here}if errorlevel==1 goto setupif errorlevel==0 goto end:setupUninstall script heremsiexec /i \\server\share\application.msi -qn\\server\share\script.vbs:endexitSo this uninstalls previous version, installs new and modifies the shortcuts from common desktop (script.vbs). script.vbs will be done from those what you posted. This already does what I originally wanted it to do, but lets say that some computers are missing shortcuts from common desktop and users have created their own to their personal desktops. In that case I guess that I should also create logon script to check those. Would it work if I just replace Const UDtop = &H10&Set oApp = CreateObject("Shell.Application")Set oShell = CreateObject("WScript.Shell")Set oFso = CreateObject("Scripting.FilesystemObject")' String in the target property to search forsTargetStrOld = "C:\Program Files\OldProgDir\executable.exe"' New string to setsTargetStrNew = "C:\Program Files\NewProgDir\executable.exe"'Check for registry keysTargetRegKey ="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{key-here}"If RegKeyExists(sTargetRegKey) then Set oDir = oApp.Namespace(UDtop) Set oDItem = oDir.Self sLocn = oDItem.Path ChkLnk(sLocn) Sub ChkLnk (sFolder) Set oFolder = oFso.GetFolder(sFolder) Set oFiles = oFolder.Files For Each oFile In oFiles If LCase(oFso.GetExtensionName(oFile)) = "lnk" Then Set oLnk = oShell.CreateShortcut(oFile) If LCase(oLnk.TargetPath) = LCase(sTargetStrOld) Then oLnk.TargetPath = sTargetStrNew oLnk.Save End If End If Next End SubElseWScript.QuitFunction RegKeyExists(ByVal sRegKey) ' Returns True or False based on the existence of a registry key. ' This part is a compliment from Torgeir Bakken. Dim sDescription RegKeyExists = True sRegKey = Trim (sRegKey) If Not Right(sRegKey, 1) = "\" Then sRegKey = sRegKey & "\" End If On Error Resume Next oShell.RegRead "HKEYNotAKey\" sDescription = Replace(Err.Description, "HKEYNotAKey\", "") Err.Clear oShell.RegRead sRegKey RegKeyExists = sDescription <> Replace(Err.Description, sRegKey, "") On Error Goto 0 End FunctionEnd If</Edit> Edited October 31, 2007 by Yzöwl Additional information appended
Yzöwl Posted October 31, 2007 Posted October 31, 2007 There shouldn't be a reason why not!Const CDtop = &H19&Const UDtop = &H10&Set oApp = CreateObject("Shell.Application")Set oShell = CreateObject("WScript.Shell")Set oFso = CreateObject("Scripting.FilesystemObject")' String in the target property to search forsTargetStrOld = "C:\Program Files\OldProgDir\executable.exe"' New string to setsTargetStrNew = "C:\Program Files\NewProgDir\executable.exe"Set oDir = oApp.Namespace(CDtop)Set oDItem = oDir.SelfsLocn1 = oDItem.PathSet oDir = oApp.Namespace(UDtop)Set oDItem = oDir.SelfsLocn2 = oDItem.PathChkLnk(sLocn1)ChkLnk(sLocn2)Sub ChkLnk (sFolder) Set oFolder = oFso.GetFolder(sFolder) Set oFiles = oFolder.Files For Each oFile In oFiles If LCase(oFso.GetExtensionName(oFile)) = "lnk" Then Set oLnk = oShell.CreateShortcut(oFile) If LCase(oLnk.TargetPath) = LCase(sTargetStrOld) Then oLnk.TargetPath = sTargetStrNew oLnk.Save End If End If NextEnd Sub
dubsdj Posted October 31, 2007 Posted October 31, 2007 I use desktop redirection for that ... It can be a pain to make it work properly but when it does it's very good.
Yzöwl Posted October 31, 2007 Posted October 31, 2007 I use desktop redirection for that ... It can be a pain to make it work properly but when it does it's very good.No you don't, we're simply fixing a broken shortcut the desktop locaton has no relevance.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now