Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Script to replace destination on shortcut icon

642 views
Skip to first unread message

Computerbid

unread,
Aug 20, 2002, 11:05:02 AM8/20/02
to
Does anyone know how to write a script/batch on logon
script to replace shortcut on user desktop ? i.e. If a
user has a shortcut point to \\server\username, I want to
change it to P:\username...
Many thanks.

Josh

unread,
Aug 20, 2002, 12:51:03 PM8/20/02
to
you can go at this many ways, You can use SHORTCUT.EXE
from the resource kit, your line would look like ..

SHORTCUT -F -T "target" -N "name" -D "directory"

or if you use KiXtart as your logon script you would have
something that looks like ...

$SName = "name"
$STarget = "target"
$SDir = "directory"
$SDest = "destination"
$RCODE = AddProgramItem($STarget,$SName,"",0,$SDir,0,0)
Copy "SMPDIR\$SName.lnk" $SDest
$RCODE = DelProgramItem($SName)

or using VBS & WSH you can delete broken shortcuts, create
shortcuts, and remove embedded File Links from shortcuts
(I like to use Windows 98 to creat shortcuts - no embedded
UNC path names). see
http://www.microsoft.com/technet/treeview/default.asp?
url=/technet/scriptcenter/dfs/default.asp
for more info,

Reinhardt Kern

unread,
Aug 20, 2002, 1:32:37 PM8/20/02
to
"Computerbid" <compu...@hotmail.com> wrote:

Use Shortcut.exe or SCUT.EXE (google for it)
Both are non-gui command line tools.

Reinhardt

Torgeir Bakken

unread,
Aug 20, 2002, 2:10:44 PM8/20/02
to
Josh wrote:

> or using VBS & WSH you can delete broken shortcuts, create
> shortcuts, and remove embedded File Links from shortcuts

Hi

Actually, with VBS & WSH you can edit (change) the properties of an existing
shortcut as well :-)

--
torgeir


RD

unread,
Aug 20, 2002, 7:04:12 PM8/20/02
to
You can do it with WSH (Windows Scripting Host) - in
Visual Basic Script or JScript.

>.
>

Torgeir Bakken

unread,
Aug 20, 2002, 7:16:42 PM8/20/02
to
Computerbid wrote:

Hi

Ok, here is a VBScript that searches through all shortcuts on the users desktop
as well as "All Users" desktop:


Set oNetwork = CreateObject("WScript.Network")

' String in the target property to search for
sTargetStrOld = "\\anaconda01\" & oNetwork.UserName

' New string to set
sTargetStrNew = "P:\" & oNetwork.UserName


Set oShell = CreateObject("WScript.Shell")
set oFso = CreateObject("Scripting.FilesystemObject")

' Check all shortcuts on the users desktop
sPath = oShell.SpecialFolders("Desktop")
ChkLnk(sPath)

' Check all shortcuts on the "All Users" desktop
sPath = oShell.SpecialFolders("AllUsersDesktop")
ChkLnk(sPath)


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 Sub

--
torgeir


compu...@hotmail.com

unread,
Aug 21, 2002, 8:30:14 AM8/21/02
to
The situation is that we have Win98, NT and 2000 users. I
don't think NT will support VBS by nature. Most of users
have a shortcut to their personal folder (\\server1
\<username>). We need to either re-point it to
f:\<username> or re-create a shortcut for them. The
problem is that Win98 doesn't have %username%. So I think
I'm stuck with KixStart. What common denominator I can use
to determine the OS version ? The one I used so far is
c:\windows\desktop -> Win98. c:\winnt\profiles -> NT,
c:\documents and settings -> Win2k. It's not the best way,
but that's only way I can think of so far. I need your
generous input.
Many thanks.

>.
>

Torgeir Bakken

unread,
Aug 21, 2002, 1:38:22 PM8/21/02
to
compu...@hotmail.com wrote:

> The situation is that we have Win98, NT and 2000 users. I
> don't think NT will support VBS by nature.

If your clients have IE 5.0 or higher, WSH (VBScript) should be available.


--
torgeir


Marty List

unread,
Aug 22, 2002, 12:06:35 PM8/22/02
to

If you do end up using KiXtart, the you can check the OS with the macro
@InWin, like this:

;=====================================
$WindowsNT = 1
$Windows9x = 2
$Platform = @InWin

Select
Case $Platform = $WindowsNT
; Do NT/2000/XP stuff here.
Case $Platform = $Windows9x
; Do 95/98/ME stuff here.
EndSelect
;=====================================


If you need to check the version of each platform, then use the macro @DOS,
like this:

;=====================================
$WindowsNT = 1
$Windows9x = 2
$Platform = @InWin
$Winver = @Dos

Select
Case $Platform = $WindowsNT
Select
Case $Winver = "5.1"
; Do XP stuff here.
Case $Winver = "5.0"
; Do 2000 stuff here.
Case $Winver = "4.0"
; Do NT4 stuff here.
EndSelect
Case $Platform = $Windows9x

; Do 95/98/ME stuff here.
EndSelect
;=====================================

Depending on what you meant by "personal folder", you might be able to use
the KiXtart macros @HomeDir, @HomeDrive and @HomeShr.

If you know the name of the existing shortcut, then just replace it with a
new one using KiXtart. If you don't know the exact name, it will be a lot
trickier. You will have to enumerate through all the .LNK files and then
use a program like the Shortcut.exe I wrote to examine the contents, and
then decide if it needs to be updated or not.

Your best bet is WSH/VBS, which is supported on NT4, but if it's not already
installed you might not want to do all that work to get it installed.


<compu...@hotmail.com> wrote in message
news:614101c2490e$802dcc10$a4e62ecf@tkmsftngxa06...

RD

unread,
Aug 23, 2002, 5:08:03 AM8/23/02
to
you can use the "ver" command (command prompt) to
determine the os. This command should be avalable for all
OSes. My advice: learn WSH, it's a long term investment,
and the cleanest way of doing all this.

RD

>.
>

0 new messages