Link to home
Create AccountLog in
Avatar of SP3CLt
SP3CLtFlag for United States of America

asked on

VBS or Batch File - Add a Shortcut to an All Users Desktop Folder

Hello Experts,

I need a VB Script or Batch File to add a shortcut to a all users desktop folder called "Corporate Shortcuts". The link is https://ipay.adp.com.

The requested Icon location is \\pcfileprint\PC_Signatures\CDR Link Project\Bank-Check.ico

I have the the following code ready, however it will place the icon/shortcut on the desktop not the All Users/ Desktop / Corporate Shortcuts folder..


Thanks in advance!

'CreateSC.vbs
Dim objShell:Set objShell=CreateObject("Wscript.Shell")
strDesktop = objShell.SpecialFolders("Desktop")
Dim objSC: Set objSC=objShell.CreateShortCut(strDesktop & "\iPAY-adp.lnk")
With objSC
  .WorkingDirectory="https://ipay.adp.com"
  .TargetPath="https://ipay.adp.com"
  .IconLocation ="\\pcfileprint\PC_Signatures\CDR Link Project\Bank-Check.ico"
  .Save
End With
Set objSC=Nothing
Set objShell=Nothing

Open in new window

Avatar of sirbounty
sirbounty
Flag of United States of America image

This has been asked before - your users will need access to write to that folder if you're trying to do it under a logon script, for example.
See https://www.experts-exchange.com/questions/23347528/GPO-that-copies-Internet-shortcut-to-allusers-desktop-via-VBScript.html

You don't want the "Desktop" special folder though, use:

strAllUserDesktop = objShell.ExpandEnvironmentStrings("%AllUsersProfile%") & "\Desktop"
Try changing line 3 & 4 to the code below.

sew

strDesktop = objShell.SpecialFolders("ALLUSERSPROFILE")
Dim objSC: Set objSC=objShell.CreateShortCut(strDesktop & "\Desktop\iPAY-adp.lnk")

Open in new window

Avatar of SP3CLt

ASKER

Hmm, I did not mention that the job will be sent using an altiris solution which will run the job with system permissions.
Also, the folder on ( C:\Documents and Settings\All Users\Desktop\Corporate Shortcuts ) already exists on all workstations, so I'd like the scrip to place the shortcut there.
Thanks for the lightning fast response! (Sungen, Sirbounty)
You're welcome... You can replace line 4 with the code below.
sew

Dim objSC: Set objSC=objShell.CreateShortCut(strDesktop & "\Desktop\Corporate Shortcuts\iPAY-adp.lnk")

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of SP3CLt

ASKER

Hmm, this one seems to work, however it is placing the shortcut wherever the script is ran - so in other words, if it's run on the desktop, the shortcut will be placed on the desktop. Ran on the server, shortcut placed in the same path :)
 
Any other ideas?
Thanks!
 

 
 

'CreateSC.vbs
Dim objShell:Set objShell=CreateObject("Wscript.Shell")
'strDesktop = objShell.SpecialFolders("Desktop")
strAllUserDesktop = objShell.ExpandEnvironmentStrings("%AllUsersProfile%") & "\Desktop\Corporate Shortcuts\ADP_iPay.ink"
Dim objSC: Set objSC=objShell.CreateShortCut("iPAY-adp.lnk")
With objSC
'  .WorkingDirectory="https://ipay.adp.com"
  .TargetPath="https://ipay.adp.com" 
  .IconLocation ="\\pcfileprint\PC_Signatures\CDR Link Project\Bank-Check.ico"
  .Save
End With
Set objSC=Nothing
Set objShell=Nothing
 

Open in new window

>> the job will be sent using an altiris solution which will run the job with system permissions.

If it *is* running as the SYSTEM account, it won't have access to
"\\pcfileprint\PC_Signatures\CDR Link Project\Bank-Check.ico"

to read the icon location.  The SYSTEM account, as far as network access goes, by default only has access to the NetLogon share of your domain controllers.  So if you place the .ico file in your NetLogon share, you will be able to reference it there.

Regards,

Rob.
'CreateSC.vbs
Dim objShell:Set objShell=CreateObject("Wscript.Shell")
strLogonServer = objShell.ExpandEnvironmentStrings("%LOGONSERVER%")
strAllUsersDesktop = objShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%") & "\Desktop"
Dim objSC: Set objSC=objShell.CreateShortCut(strAllUsersDesktop & "\iPAY-adp.lnk")
With objSC
  .WorkingDirectory="https://ipay.adp.com"
  .TargetPath="https://ipay.adp.com"
  .IconLocation = strLogonServer & "\NetLogon\PC_Signatures\CDR Link Project\Bank-Check.ico"
  .Save
End With
Set objSC=Nothing
Set objShell=Nothing

Open in new window

Avatar of SP3CLt

ASKER

Thanks Rob, however the \\pcfileprint is not a DC, simply a File\Print Server - Domain users all have access.
Regardless, the icon has very low priority - the main objective to execute a script which will place the specified weblink/shortcut in the "C:\Documents and Settings\All Users\Desktop\Corporate Shortcuts"
Would a new script be a better idea?
 
How about a list of PCs?
Then you can simply copy the shortcut to all systems using this from a command line:

for /f %a in (c:\PCList.txt) do copy "%allusersprofile%\desktop\corporate Shortcuts\ADP_iPay.ink" "\\%a\c$\documents and setttings\all users\desktop\corporate Shortcuts" /y
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of SP3CLt

ASKER

Okay I got it to work! I modified a few of your submissions (from everyone) and here is what I came up with...
'CreateSC.vbs
Dim objShell:Set objShell=CreateObject("Wscript.Shell")
strLogonServer = objShell.ExpandEnvironmentStrings("%LOGONSERVER%")
strAllUsersDesktop = objShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%") & "\Desktop\Corporate Shortcuts"
Dim objSC: Set objSC=objShell.CreateShortCut(strAllUsersDesktop & "\iPAY-adp.lnk")
With objSC
  .WorkingDirectory="https://ipay.adp.com"
  .TargetPath="https://ipay.adp.com"
  .IconLocation ="\\pcfileprint\PC_Signatures\CDR Link Project\Bank-Check.ico"
  .Save
End With
Set objSC=Nothing
Set objShell=Nothing

Open in new window