permanent Desktop shortcut needed via GPO
-
Wednesday, May 02, 2012 12:32 PM
I have used the script below and when run on my computer it works......I have edited it to point to the URL I need and it works..
.I am a bit fuzzy on why there are 2 objects that get created....the VB script and another objectthat looks like it has a notepad icon on it?
would like some clairifiaction on how and why the 2 "things" are needed and how it all operates...
My ultimate goal is to have this script called via group policy under computer configuration-->startup scripts
but when I put that all together it does not put this shortcut icon on the computers(any domain computer) desktop at startup......
like I said it works locally but I need advise on:
what possible editing to the script or the properties on the resultant objects that may be necessary when I then cop ythem off to the server location where the gp startup scripts calls it from
the method I used to create this is pasted below I am a Scripting novice I cut/pasted off MSDN
The following example creates a WshShell object and uses the CreateShortcut method to create two shortcuts
<package>
<job id="vbs">
<script language="VBScript">
set WshShell = WScript.CreateObject("WScript.Shell")
set oUrlLink = WshShell.CreateShortcut(strDesktop & "\Microsoft Web Site.url")
oUrlLink.TargetPath = "http://www.microsoft.com"
oUrlLink.Save
</script>
</job><job id="js">
<script language="JScript">
var WshShell = WScript.CreateObject("WScript.Shell");
var oUrlLink = WshShell.CreateShortcut(strDesktop + "\\Microsoft Web Site.url");
oUrlLink.TargetPath = "http://www.microsoft.com";
oUrlLink.Save();
</script>
</job>
</package>
All Replies
-
Wednesday, May 02, 2012 12:48 PMWith Windows Server 2008 and above, you can create shortcuts on Desktops via Group Policy Preference extensions. Does that help?
Grant Ward, a.k.a. Bigteddy
-
Wednesday, May 02, 2012 1:06 PM
Not really I am in a Server 2003 domain
and I see much support for calling scripts upon computer start up.......all looks very logical and do-able
I think my problem here is what ever the difference may be between this script running correctly "locally" vs what needs to be tweaked to have it run as if it were local but invoked via GPO
essentially so I do not have to manually load the script into every computer's statup folder
I thank you for your reply and any further advice
-
Wednesday, May 02, 2012 1:22 PM
The only problem I can see with the script and what you're saying is "strDesktop" -- what is the value of this variable? If you're saying that it works fine when you run it locally but doesn't when you run it from Group Policy as a Startup Script, this leads me to believe you might be invoking an user-specific environment variable that isn't instantiated yet at startup. Why? Because, no user is logged on to populate that variable. If this is a startup script though and NOT a logon script, are you wanting to target ALL users' desktops? If so, just target:
C:\Documents and Settings\All Users\Desktop
-
Wednesday, May 02, 2012 1:29 PM
I think we are looking in the rght area....but not being too proficient at scripting...where in this script does this new path get inserted.?
when I run the script the result is that 2 items get addes tothe local desktop.... one iotem looks like a notepoad docuemtn and the other is the acutl URL shortcut..
the notepad object you can right click it and there arethe normal targert and startup loations fields........but I cant figure out how they aregetting populated .....so there must be a sopt in the script I copied you on..... where you would edit a line to insert he path you believe is correct ??
-
Wednesday, May 02, 2012 1:43 PM
If what you posted is the entire script, I have no idea how your script is working at all since I can't see where "strDesktop" is assigned to any valid value. Is the script file you are running a .wsf file? If so, that could be the one that looks like a notepad icon -- all this is telling you is that Windows has the .wsf file extension associated to open by default with Notepad.
If you are using WSF, is there a particular reason for this or just becuase you copied it off of MSDN? If so, I'd recommend changing it to VBS for simplicity if you're new to scripting:
strDesktop = "C:\Documents and Settings\All Users\Desktop" set WshShell = WScript.CreateObject("WScript.Shell") set oUrlLink = WshShell.CreateShortcut(strDesktop & "\Microsoft Web Site.url") oUrlLink.TargetPath = "http://www.microsoft.com" oUrlLink.Save... save as "something.vbs" and rerun.
Edit: Pls note that this "All Users Desktop path" is only valid on Windows XP/2003 systems.- Edited by thepip3r Wednesday, May 02, 2012 1:44 PM
-
Wednesday, May 02, 2012 1:45 PM
Grant,
I'm pretty sure that's VBA and is not valid in VBS. Can you confirm or deny pls?
-
Wednesday, May 02, 2012 1:45 PM
- Proposed As Answer by thepip3r Wednesday, May 02, 2012 1:47 PM
-
Wednesday, May 02, 2012 1:49 PM
yep that script I listed above is the entire enchalada to be truthfull I copied off MSDN
notice it says
shortcutsThe followingmple creates a WshShell object and uses the CreateShortcut method to create two exa
- Edited by DanielDeCoursey Wednesday, May 02, 2012 1:51 PM
-
Wednesday, May 02, 2012 1:52 PMUse one of the scripts BigTeddy posted in the link. They are complete and reference the All Users Desktop on any platform -- that's the best way to go about it.
-
Wednesday, May 02, 2012 1:54 PMyes I copied it and saved it as wsf
-
Wednesday, May 02, 2012 2:15 PMModerator
How about this: When the dialog box appears, press Ctrl+C, which copies the message to the clipboard as text. Then paste the text into this forum. We can read the text instead of trying to read a completely tiny and illegible image. Also, if it reference a line number, you must specify which line of code the line number is referring to. We can't see your screen.
Bill
-
Wednesday, May 02, 2012 2:17 PMthanks i was loosing my mind tryig to get these messages enlarged ....
-
Wednesday, May 02, 2012 2:20 PM
I re saved it as VBS now I get
---------------------------
Windows Script Host
---------------------------
Script: C:\Users\ddecoursey\Desktop\1time.vbs
Line: 1
Char: 1
Error: Expected statement
Code: 800A0400
Source: Microsoft VBScript compilation error---------------------------
OK
--------------------------- -
Wednesday, May 02, 2012 2:21 PMthe examples they provide in the KB link the BT provided ..they say to save them into a "program file" what is that ??
-
Wednesday, May 02, 2012 2:25 PMModerator
Hi,
If your file starts with this line:
<package>
Then the file is not a .vbs file; it is a .wsf file. The reason two icons are getting created on your desktop is that you are running essentially the same actions twice: Once in VBScript, and once in JScript. A .wsf file can encapsulate two different kinds of code in a single script. Please go back and carefully read thepip3r's second response to your question.
Bill
- Edited by Bill_StewartMicrosoft Community Contributor, Moderator Wednesday, May 02, 2012 2:26 PM correction
-
Wednesday, May 02, 2012 2:30 PM
OK I have abandodned the originally stollen MSDN examlpe( event though it works locally)
I have copied the new example supplied by pip3r's and saved it as VBS so when I click it Iget
---------------------------
Windows Script Host
---------------------------
Script: C:\Users\ddecoursey\Desktop\test.vbs
Line: 2
Char: 1
Error: Invalid character
Code: 800A0408
Source: Microsoft VBScript compilation error---------------------------
OK
--------------------------- -
Wednesday, May 02, 2012 2:35 PMA highly suspect error. Make sure your file is a pure text file, with no extra characters in it.
Grant Ward, a.k.a. Bigteddy
-
Wednesday, May 02, 2012 2:41 PM
Actually, I get the same error. This is why I hate VB Script. It's so difficult to debug. No CLI. Even the example from the link I posted gives me a compliation error.
Grant Ward, a.k.a. Bigteddy
-
Wednesday, May 02, 2012 2:47 PM
When i went to save it
it gave me some guff about loosing unicode characters if it was being saved ANSI
so I tried it both ways
if you hate Vb then what is your preference ??
-
Wednesday, May 02, 2012 2:50 PMYes, I had the same strange error when saving it from Notepad. Powershell is my preferred language, but for your scenario, it isn't a viable option.
Grant Ward, a.k.a. Bigteddy
-
Wednesday, May 02, 2012 2:52 PM
So interestingly enough, the scripts in the Microsoft article are wrong -- they won't work as coded. I had to rework it a little and renamed some variables to my preferred standard but this does work and should work for you on any platform:
Set objShell = WScript.CreateObject("WScript.Shell") strDesktop = objShell.SpecialFolders("AllUsersDesktop") Set objMyShortcut = objShell.CreateShortcut(strDesktop & "\MYLINK.lnk") objMyShortcut.TargetPath = "http://www.microsoft.com" objMyShortCut.Save
- Edited by thepip3r Wednesday, May 02, 2012 3:00 PM
- Proposed As Answer by BigteddyMicrosoft Community Contributor Wednesday, May 02, 2012 5:59 PM
- Marked As Answer by DanielDeCoursey Friday, May 04, 2012 11:37 AM
-
Wednesday, May 02, 2012 2:57 PMModerator
Note that VBScript doesn't use "+" for string concatenation but rather "&".
Bill
-
Wednesday, May 02, 2012 3:02 PMUpdated to use the ampersand to be syntactically correct even though the "+" doesn't throw any errors and does successfully concat the two strings together...
-
Wednesday, May 02, 2012 3:20 PMModerator
Hi,
I believe the + "works" due to VBScript automatic type coercion. It's really the addition operator, but when applied to strings, it concatenates them. IMO it's better to specify "&" to make the intention explicit.
Bill
-
Wednesday, May 02, 2012 5:11 PM
hello,
your script does work here locally ( would be niceto give it a diffentrt desktop icon thoguh) but still, do not see anyhting happen when I
place the script file out on my domain controller and then reeference it as a startup script in GP
there is not trace of anyhting at all happening ....I am intending to now put it in he user login script and see .......
this seems to be my stuumbling block to get waht works locally via GP for the entire domain
-
Wednesday, May 02, 2012 5:18 PMMake sure the script is saved in a shared location, and referenced by UNC path in your logon script settings.
Grant Ward, a.k.a. Bigteddy
-
Wednesday, May 02, 2012 5:22 PM
Do you have another .ico image that you'd like to use for the link? It can be done very easily but you'd need to have the .ico file available on all systems where this shortcut will be created.
As far as it not running from Group Policy, if you're using the most recent script I posted, this should work for you during a startup script. However, there are other possible reasons why your script isn't running. Are you running any other vbscripts in your domain? If so, are you invoking them in the same way? What I'm driving at is that many people just call the VBS file directly because Windows has always executed VBS files natively using the WScript engine. However, in my environment, we make an attempt to limit this ability by removing the execution association with VBS files. As a result, when we want to invoke VBS files through Group Policy, we must target the engine we want to use (Cscript in almost all cases) and then pass the actual .vbs file as an argument to the engine.
If you have a similar environment, you'd need to supply the path to the engine you want to use and then pass the vbs as an argument, e.g.:
Name: Parameters
%SystemRoot%\system32\cscript.exe fullyqualifieddomainname\netlogon\myscriptfile.vbs -
Wednesday, May 02, 2012 5:27 PM
I tried it as a logon script, and it works fine.Grant Ward, a.k.a. Bigteddy
- Marked As Answer by DanielDeCoursey Friday, May 04, 2012 11:37 AM
-
Thursday, May 03, 2012 8:23 PM
I was able to use the newer GPOmanagerthat you getwith WIN7
used GPP in the user configuration to do a shortcut..............and then did a GPupdate and the shortcut popped right up on my WIN7 desktop
but i do not getthat same result on a XP workstation that is in my same AD OU wherethis newly tweaked policy is linked ........
the screecastthat showed how to tdo this said although you cany manage GPPS from XP workstations they can be applied
but the shortcut will not popup on the desktop
-
Thursday, May 03, 2012 8:28 PMModerator

