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

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?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee W, MVPTechnology and Business Process AdvisorCommented:
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"
TrishITGuruAuthor Commented:
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?
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.
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

TrishITGuruAuthor Commented:
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?
Steven CarnahanNetwork ManagerCommented:
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

TrishITGuruAuthor Commented:
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.
Steven CarnahanNetwork ManagerCommented:
Here is a script to add a shortcut to It should be easy enough to modify.
@echo off

echo [InternetShortcut] > "%userprofile%\Desktop\Google.URL"
echo URL= >> "%userprofile%\Desktop\Google.URL"
echo IconFile= >> "%userprofile%\Desktop\Google.URL"
echo IconIndex=0 >> "%userprofile%\Desktop\Google.URL"

Open in new window

TrishITGuruAuthor Commented:
Can I just add that to the GPO (i.e. have the GPO call that script) for the selected users?
Lee W, MVPTechnology and Business Process AdvisorCommented:
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.
TrishITGuruAuthor Commented:
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?
Lee W, MVPTechnology and Business Process AdvisorCommented:
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.
Steven CarnahanNetwork ManagerCommented:
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.
TrishITGuruAuthor Commented:
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?
Steven CarnahanNetwork ManagerCommented:
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.
Lee W, MVPTechnology and Business Process AdvisorCommented:
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.
TrishITGuruAuthor Commented:
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.
Steven CarnahanNetwork ManagerCommented:

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.

TrishITGuruAuthor Commented:
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"
Steven CarnahanNetwork ManagerCommented:
The (c:\users.txt) is where you put the location\name of the file.
Lee W, MVPTechnology and Business Process AdvisorCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TrishITGuruAuthor Commented:
this is what is in my users.txt:
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

Steven CarnahanNetwork ManagerCommented:

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"

Lee W, MVPTechnology and Business Process AdvisorCommented:
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).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.