Copying a shortcut file to the users desktop in XP

Hi

I have a .hml shortcut which was sent by a survey department.I downloaded the html shortcut.When i open it directly opens a webpage with the user name and password already entered.I have to say ok to logs into the website.

We use window 2008 DC and I want this shortcut be placed on all the XP PC users desktop.We use VB script when the user logs in. Is it possible add a script so that shortcut is copied to the users desktop.

Or if you have any other better way of doing this please suggest.

Thanks
lianne143Asked:
Who is Participating?
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.

Red-KingIT ManagerCommented:
This should be quite straight forward to do.
You can do it with a batch file or add it to your vbscript
The following line would need to be added to the bat file and called at login;
xcopy "\\Server.mydoamin.local\Shared\WebLink.htm" "%USERPROFILE%\desktop\"

Open in new window

Be sure to include the trailing slash so that it knows it's a folder it's copying into or else it will fail iirc.

Here's something that should work in vbscript, though some of this may be specific to Windows 7;
' -----------------------------------------------------------------------------
' 	MyFile.vbs
'	VBScript which is executed during user logon to copy a file
' 	Author Red King
' 	Version 0.1 - 09/09/2013
' -----------------------------------------------------------------------------
Option Explicit

'	Declare Variables
Dim myFileSys, myNetwork, WSHShell, WSHProcess, appShell, userprofileEnv


'	Create Objects and Assign Variables
Set WSHShell = CreateObject("Wscript.Shell")
Set appShell = CreateObject("Shell.Application")
Set WSHProcess = WSHShell.Environment("Process")
Set myFileSys = CreateObject("Scripting.FileSystemObject")
Set myNetwork = CreateObject("WScript.Network")

DomainLogonServer	= WSHProcess("LogonServer")

'	Assign Environment Variables
userprofileEnv 		= WSHShell.ExpandEnvironmentStrings("%USERPROFILE%")

CopyFile


Sub CopyFile()

	Dim remoteLocation, desktopLocation

	remoteLocation = "\\Server.mydoamin.local\Shared"
	desktopLocation = userprofileEnv & "\Desktop"

	On Error Resume Next

	If myFileSys.FileExists(remoteLocation  & "\WebLink.htm" ) Then
		'	Do Nothing
	Else
	'		If the file doesn't exist locally copy it from a remote location
		myFileSys.CopyFile remoteLocation  & "\WebLink.htm", desktopLocation  & "\"
	End If

End Sub

Open in new window



You could then add either script to a Group Policy that applies to all Authenticated Users.
Open the Group Policy Management Console (GPMC) and create a new policy in an appropriate location that will apply to the users you want it to apply to.
Edit the policy.
Under 'User Configuration' go to 'Policies -> Windows Settings -> Scripts (Logon/Logoff)'
Open the Logon option.
Click the 'Show Files' button and copy your batch file or vbscript file to the folder that opens.
Close the folder and click the 'Add' button.
Type in the name of the catch file (MyFile.bat) or cscript followed by the name of the vbscript file (cscript MyFile.vbs)
Click OK, close the policy and you're done.
0
lianne143Author Commented:
I copied the batch file to the c drive of the local PC and If I execute the .bat file logged in as a administrator , it copies the .htm file to the desktop. But if I run as a user it says access denied.
xcopy "\\AppServer\Shared\WebLink.htm" "C:\Documents and Settings\All Users\Desktop"
0
Red-KingIT ManagerCommented:
Hi,

The reason you're getting an access denied error is that you're trying to copy to "All Users" desktop.
Anything copied here is available for everybody who logs into the computer and would only need to be done once.
It's because copying (or deleting) something from that location would potentially effect multiple users that the average user is not allow write to that location.

For a user to be able to run the script they must copy it to a location that they can write to. In this case that's their own desktop.
In order to script this in a batch file for eveybody to use you will need to use an environment variable. The one you need to use is: %userprofile%

If you use the following, with the environment variable in the destination, it will work;
xcopy "\\AppServer\Shared\WebLink.htm" "%userprofile%\Desktop"

Open in new window

0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Red-KingIT ManagerCommented:
If you'd like to see a list of environment variables that you can use in a script open a command prompt and type the command: set

This will generate a list in the format
<variable>=<value>

Open in new window


For example, here are a few from my computer that are common to all windows installations;

APPDATA=C:\Users\myuser\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=LPTP008
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=H:
HOMEPATH=\
HOMESHARE=\\STRG001.mydomain.local\Users$\myuesr
ILOCALAPPDATA=C:\Users\myuser\AppData\Local
LOGONSERVER=\\SVR004
NUMBER_OF_PROCESSORS=4
OS=Windows_NT
USERNAME=myuser
USERPROFILE=C:\Users\myuser
windir=C:\Windows

Open in new window


With any of the above you can take the text before the equals, surround it with percentage signs (%), and use it in a script.
The Value is anything after the equals sign and will change between computers and users.

So I could write a batch file to spit out the username and server I've logged onto as follows;
echo %USERNAME%
echo %LOGONSERVER%

Open in new window

0
lianne143Author Commented:
Now  when I run the .vbs locally on client PC as a user,the file gets copied successfully to the user desktop.

But when I add this line to the existing user logon script
xcopy "\\AppServer\Shared\WebLink.html" "%userprofile%\Desktop"

and when the user logs on I get a pop up window , which says:

Windows Script host
Script: \\Server1\netlogon\student.vbs
Line: 8
Char:47
Error:unexpected end of statement
Code:800A04401
Source:Microsoft VBScript Complation error
0
Red-KingIT ManagerCommented:
What is the content of student.vbs?

The xcopy line cannot be used in vbscript directly. It must be executed through a shell.
You can only have the xcopy line as is in a batch file
0
lianne143Author Commented:
The content of the student.vbs is it has a .exe path and  its a printer service which it executes when user logs in .
0
Red-KingIT ManagerCommented:
Hi,

You can't run .exe files from directly within a vbs script. Just like with the xcopy command you must run the exe through a command shell (dos), i.e. you use vbs to create a shell and tell it to execute your exe.

In this code a variable for your shell is declared, defined, used each time the RunProgram subroutine is executed and destroyed at the end of the script.

You will need to incorporate this into your vbs script.

' -----------------------------------------------------------------------------
' 	RunProgram.vbs
'	VBScript which is executed to run a program on a command line
' 	Author Red King
' 	Version 0.1 - 07/10/2013
' -----------------------------------------------------------------------------

Option Explicit

'	#########################
'	Declare Variables
'	#########################
Dim WSHShell

'	#########################
'	Create Objects and Assign Variables
'	#########################
Set WSHShell = CreateObject("Wscript.Shell")


'-------------------------------------------------------------------------------
'+++++++++++++++++++++++++++++++Main Body+++++++++++++++++++++++++++++++++++++++
'-------------------------------------------------------------------------------

Call RunProgram("ipconfig -a")

Call RunProgram("C:\Windows\notepad.exe")

Set WSHShell = Nothing
WScript.Quit

'-------------------------------------------------------------------------------
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'-------------------------------------------------------------------------------



'		==========================
'		<<<<<<<<<<<<<>>>>>>>>>>>>>
'	Subroutine used to execute an external program
'		<<<<<<<<<<<<<>>>>>>>>>>>>>
'		==========================
Sub RunProgram(command)

	Dim shellReturn
	
	shellReturn = 0
	
	shellReturn = WSHShell.Run(command, 10, TRUE)
	WScript.Echo(shellReturn)
	
End Sub

Open in new window


Have a look at the MSDN reference for more detail on the Run method for the shell.
0
LeeTutorretiredCommented:
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0
Red-KingIT ManagerCommented:
Hi,

I've provided detailed information to answer the posted question using 2 different approaches, batch file and vbscript.
There is more than sufficient information here to answer the original question. This answer may also be useful to others trying to achieve something similar.
I suggest that this question is marked answered rather than deleted.

Kind regards,
Rory
0

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
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
Windows Server 2008

From novice to tech pro — start learning today.