Solved

# Batch or VBScript to add a shortcut to Desktop for certain users

Posted on 2010-08-19
837 Views
Hi..
I've been searching EE but I can't seem to find exactly what I need.

I have a shortcut http:\\Imp that I need to place on certain users desktop.  These users may be part of group or may not be part of a group so I am not easily able to use AD.
Is there a way with VBScript or Batch file that I can add this shortcut to specific users, where the users are in a text file?

Thanks.
0
Question by:TrishITGuru
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 9
• 7
• 6
• +1

LVL 96

Expert Comment

ID: 33476558
Yes, but why not create a group in AD and then just check for group membership?  There's no realistic limit to the number of groups that can be used.

Otherwise, you would use FOR:

For /f "tokens=1" %%a in (users.txt) do if "%%a"=="%username%" copy "x:\path\to\shortcut.lnk" "%userprofile%\desktop"
0

Author Comment

ID: 33476698
what is x:\path\to\shortcut.lnk?
All I have been given is http:\\Imp.  Its supposed to open an IE8 window so the users can then use the web-based application.
Would the path in the file be the actual path of the application?
0

Expert Comment

ID: 33476742
You can add a script for each specific user.  Open AD, select a user, properties, Profile, logon script.  Put here the location of the script.

But like leew said, the easiest way is to make a new group for these users.
0

Author Comment

ID: 33476838
Its been a rough day and I know I know the answer but I'm going to ask anyway...
IF I can get my customer to use AD (which I prefer) would you recommend using GPO to add the shortcut or something else within AD?
0

LVL 26

Expert Comment

ID: 33477139
leew can correct me if I'm wrong but I believe he is going on the assumption that you have the ICON stored somewhere on the server. (You have created the ICON and tested that it works haven't you?) The x:\path\to\shortcut.lnk telling the batch file where that ICON is so it can copy it to the desktop. Make sense?

If you can get them to use AD then it might be easier to use GPO as there is not a native "if member" in Windows like there is in Novell.

Did I miss anything

0

Author Comment

ID: 33477195
To be honest, I have no idea if there is an icon or not.  All I was given by the customer is to add a shortcut that when clicked will open up IE8 and get users to the application... all I was given was http:\\IMP (IMP is the name of the application).
I don't mess with shortcuts or icons very often so its kind of new to me.  Usually the icons/shortcuts are already created in some location and I add it to a logon script, but the customer has none of that and they don't want to use a logon script.
So I have to find other ways of doing it.  I was looking for a plan B if plan A (Active Directory) doesn't work.
I would prefer to just add all these users to a group in AD and then just add the link they need to a GPO for them.
0

LVL 26

Expert Comment

ID: 33477730
Here is a script to add a shortcut to www.google.com. It should be easy enough to modify.
@echo off


0

Author Comment

ID: 33477803
Can I just add that to the GPO (i.e. have the GPO call that script) for the selected users?
0

LVL 96

Expert Comment

ID: 33477829
Actually you said "I have a shortcut" - so in my script is the path to the shortcut - .lnk files are shortcuts.  .url files are favorites in IE (though I suppose some would call them INTERNET shortcuts.  In either case, you would copy whatever the file is that contains your shortcut - that's what x:\path\to\shortcut.lnk is supposed to represent.
0

Author Comment

ID: 33477909
With what you all have posted, it appears the best or easiest way is to put a script in some sort of batch file and call that batch file via GPO, is that correct?
Do you recommend that over using Active Desktop within AD/GPO?
0

LVL 96

Expert Comment

ID: 33478004
That's what I'd be doing - either in the login script or via a group policy, checking group membership and if a member, copying the shortcut.
0

LVL 26

Expert Comment

ID: 33478052
Actually, if there is no reason that everyone can't have access to the http:\\lmp "site", or if there is security on that "site" then the easiest way may be to use GPO and add the link to everyone's favorites. That eliminates unnecessary "clutter" on the desktop and eliminates the need to copy anything.
0

Author Comment

ID: 33478505
The customer believe if we use GPO then if the user deletes the shortcut or favorite then it will come back when the user next logs in.
Is there a way to use GPO and then make sure when its deleted it won't come back?
0

LVL 26

Expert Comment

ID: 33478560
That could be accomplished with some more work by using the RunOnce but I would need to work on that.

Another way is to have the user open IE to the site and then go to File/Send/Shortcut to Desktop and that way only the ones that need/want it would get the shortcut on their desktop. Then if they can delete it if they don't need/want it anymore.
0

LVL 96

Expert Comment

ID: 33478617
The reason you put something this in a login script is to ensure it's always there.  If you want the user to have the option of deleting it, then I would just run a script as domain admin and place the shortcut on the designated machines.

For example, make a list of all the machines that should get this shortcut and then run
For /f "tokens=1" %%a in (users.txt) do if "%%a"=="%username%" copy "x:\path\to\shortcut.lnk" "\\%%a\c$\documents and settings\all users\desktop" This isn't foolproof - if you have vista or 7 clients you'll have to change the copy to path... but the idea is once it's on the machine never to do it again, then you don't want this done by a script that repeats every logon. 0 Author Comment ID: 33478722 Just finished talking with the customer. They don't want to use GPO. They want it so the user has the ability to delete it without it coming back. We use roaming profiles, so its not based on machine, its based on user. I already asked why they don't just have the user bookmark the web page, and they said that isn't an option. So, I am pretty much limited to creating a script that can run that will simply use xcopy to put a shortcut for a web page on a desktop. They do not use a path for shortcuts (as stated above, i.e. shortcut.lnk) so I either have to create that path myself or simply put the URL in the xcopy. I've never used xcopy so I'm not sure how to implement that with vbscript. I do have the list of users and their profile path. 0 LVL 26 Expert Comment ID: 33478844 Okay, Do you agree with this then leew? 1. Do you have access to http:\\lmp (I am guessing that is a lower case L) 2. If so, then go to the site and then create a shortcut on your desktop File/Send/Shortcut to Desktop 3. Using the script leew gave you to start with copy the shortcut from your desktop to the %username%\desktop directory where the roaming profiles are stored. 0 Author Comment ID: 33479043 I have the following in my VBScript but its been a long time since I've used command line within VBScript. How would I read the users from the file and execute the command? rcmd For /f ""tokens=1"" %%a in (c:\users.txt) do if ""%%a""==""%username%"" xcopy ""\\BOS-S-2-FS1\%username%\System\XP\Desktop" 0 LVL 26 Expert Comment ID: 33479079 The (c:\users.txt) is where you put the location\name of the file. 0 LVL 96 Accepted Solution Lee W, MVP earned 125 total points ID: 33479097 In general yes, but I always recommend testing on a machine or two first. Though let me revise the command - the one posted most recently puts the shortcut on the desktop of all users for the machine in question. but if we don't want ALL users of a given machine to see it, then we should copy it to the user's roaming profile WHILE THEY ARE LOGGED OUT (this is why I hate roaming profiles - if they used folder redirection, this wouldn't be an issue and would be faster on the network) Do this at night or on a weekend or early before they arrive; For /f "tokens=1" %%a in (users.txt) do if "%%a"=="%username%" copy "x:\path\to\shortcut.lnk" "\\RoamingProfilesServer\ProfileShare\UserName(IfApplicable)\Desktop" NOTE: I'm using plain old copy - NOT xcopy. XCOPY can work, but why bother? If you need more help with this, I'd recommend posting the EXACT name of the file the shortcut is - and it's path, as well as an example path to one of the users profiles. 0 Author Comment ID: 33479268 this is what is in my users.txt: \\servera\username$
and on down the list.
The place I need to copy it to is \servera\username\system\dekstop (where servera changes based on their location).
The shortcut is located on my desktop c:\docs and settings\....\http:\\IMP

0

LVL 26

Assisted Solution

pony10us earned 125 total points
ID: 33480714
leew:

What do you think of the following? I think there is something wrong in the way I have it but I can't put my finger on it.

For /f "tokens=2,3 delims=^\ (users.txt) do if "%%b"=="%username%" copy "%userprofile%\desktop\<name of shortcut> "%%a\%%b\system\Desktop"

0

LVL 96

Expert Comment

ID: 33507989
You are correct - there is something wrong - your line is the first line, the corrected one (though I didn't test) should be the second:
For /f "tokens=2,3 delims=^\ (users.txt) do if "%%b"=="%username%" copy "%userprofile%\desktop\<name of shortcut> "%%a\%%b\system\Desktop"
For /f "tokens=2,3 delims=^\" (users.txt) do if "%%b"=="%username%" copy "%userprofile%\desktop\<name of shortcut>" "%%a\%%b\system\Desktop"

(You missed two quotes).
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
###### Suggested Courses
Course of the Month6 days, 17 hours left to enroll