Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 854
  • Last Modified:

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

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
TrishITGuru
Asked:
TrishITGuru
  • 9
  • 7
  • 6
  • +1
2 Solutions
 
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"
0
 
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?
0
 
Bo3rCommented:
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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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?
0
 
pony10usCommented:
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
 
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.
0
 
pony10usCommented:
Here is a script to add a shortcut to www.google.com. It should be easy enough to modify.
@echo off

echo [InternetShortcut] > "%userprofile%\Desktop\Google.URL"
echo URL=http://www.google.com >> "%userprofile%\Desktop\Google.URL"
echo IconFile=http://www.google.com/favicon.ico >> "%userprofile%\Desktop\Google.URL"
echo IconIndex=0 >> "%userprofile%\Desktop\Google.URL"

Open in new window

0
 
TrishITGuruAuthor Commented:
Can I just add that to the GPO (i.e. have the GPO call that script) for the selected users?
0
 
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.
0
 
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?
0
 
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.
0
 
pony10usCommented:
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
 
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?
0
 
pony10usCommented:
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
 
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.
0
 
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.
0
 
pony10usCommented:
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
 
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"
0
 
pony10usCommented:
The (c:\users.txt) is where you put the location\name of the file.
0
 
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.
0
 
TrishITGuruAuthor Commented:
this is what is in my users.txt:
\\servera\username$
\\serverb\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
 
pony10usCommented:
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
 
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).
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 9
  • 7
  • 6
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now