copy using windows logon script

I would like to copy a shortcut to the desktop of each domain user. I have put the shortcut in a shared directory on the server and set permissions. How do copy it to the All Users Desptop of each computer upon user login?
NormanDaoustAsked:
Who is Participating?
 
Chris DentConnect With a Mentor PowerShell DeveloperCommented:

Anyway, for this version it'll end up with:

Copy File from "\\crispserv\portal\CRISP Portal.lnk"
To "%UserProfile%\Desktop\CRISP Portal.lnk"
0
 
nihlcatCommented:
You can create a batch file containing:

copy "%SystemRoot%\shared_folder\calc.exe" "c:\Documents and Settings\All Users\Desktop"

and name it something like "sortcut.bat"

Then you can add it to their Profile tab under their account, or push it out via group policy
0
 
nihlcatCommented:
Oops, sorry I copied from my batch file wrong:

copy "%SystemRoot%\shared_folder\YOURSHORTCUT.LNK" "c:\Documents and Settings\All Users\Desktop"
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
NormanDaoustAuthor Commented:
if at all possible I would like to accomplish this using vbs since all other scripts on our system are vb scripts.
0
 
nihlcatCommented:
Oh, ok.  Someone else will have your anser then.  :)
0
 
Chris DentPowerShell DeveloperCommented:
To copy a file with VBScript...

set objFileSystem = CreateObject ("Scripting.FileSystemObject")

set objFile = objFileSystem.GetFile("<source file>")
objFile.Copy("<target file>")

Now to make things slightly more complicated you'll have to teach VBScript how to read an Environmental Variable (if you wanted to use the %UserProfile% path).

If you assume the source file name and destination are the same you get this little script:

' Script to copy a file

Option Explicit

' Variable Declaration

Dim objFileSystem, objShell
Dim objEnVar, objFile
Dim strUserVar, strTargetPath

' Constant Declaration

Const FILE = "<File Name to Copy>"

' Initialize Objects

Set objFileSystem = CreateObject ("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

' Figure out what UserProfile is

Set objEnVar = objShell.Environment("PROCESS")
strUserVar = objEnVar.Item("UserProfile")

' Building the Target path - this one dumps it onto the Desktop for the current user

strTargetPath = strUserVar & "\Desktop\" & FILE

' Copy the file

set objFile = objFileSystem.GetFile(FILE)
objFile.Copy(strTargetPath)
0
 
Chris DentPowerShell DeveloperCommented:

hehe all that to achieve the one line nihlcat posted ;)
0
 
nihlcatCommented:
=)
0
 
Chris DentPowerShell DeveloperCommented:
Although I did miss the All Users bit... that simplifies things slightly - well if you can at least assume everyone uses the C: Drive:

' Script to copy a file

Option Explicit

' Variable Declaration

Dim objFileSystem
Dim objFile

' Constant Declaration - These must include the Filename itself

Const SOURCE = "<Source Path and File Name>"
Const DESTINATION = "C:\Documents and Setttings\All Users\Desktop\<filename>"

' Initialize Objects

Set objFileSystem = CreateObject ("Scripting.FileSystemObject")

' Copy the file

set objFile = objFileSystem.GetFile(SOURCE)
objFile.Copy(DESTINATION)

A little easier...
0
 
NormanDaoustAuthor Commented:
good point abou the C: drive, it may not always be the case. So I am trying to run the first chunk of code and I'm getting a path not found error from the line: objFile.Copy(strTargetPath)
0
 
NormanDaoustAuthor Commented:
... In fact, here is the modified code I'm trying to run. Is this right Chris-Dent?

Option Explicit

' Variable Declaration

Dim objFileSystem, objShell
Dim objEnVar, objFile
Dim strUserVar, strTargetPath

' Constant Declaration

Const FILE = "\\crispserv\portal\CRISP Portal.lnk"

' Initialize Objects

Set objFileSystem = CreateObject ("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

' Figure out what UserProfile is

Set objEnVar = objShell.Environment("PROCESS")
strUserVar = objEnVar.Item("UserProfile")

' Building the Target path - this one dumps it onto the Desktop for the current user

strTargetPath = strUserVar & "\Desktop\" & FILE

' Copy the file

set objFile = objFileSystem.GetFile(FILE)
objFile.Copy(strTargetPath)
0
 
Chris DentPowerShell DeveloperCommented:

Almost... sorry.. that version was crappy for handling different locations... try this one:

Option Explicit

' Variable Declaration

Dim objFileSystem, objShell
Dim objEnVar, objFile
Dim strUserVar, strSourcePath, strTargetPath

' Constant Declaration

Const SOURCEPATH = "\\crispserv\portal\"
Const SOURCEFILENAME = "CRISP Portal.lnk"
Const DESTFILENAME = "CRISP Portal.lnk"

' Initialize Objects

Set objFileSystem = CreateObject ("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

' Figure out what UserProfile is

Set objEnVar = objShell.Environment("PROCESS")
strUserVar = objEnVar.Item("UserProfile")

' Building the Target path - this one dumps it onto the Desktop for the current user

strSourcePath = SOURCEPATH & SOURCEFILENAME
strTargetPath = strUserVar & "\Desktop\" & DESTFILENAME

' Copy the file

set objFile = objFileSystem.GetFile(strSourcePath)
objFile.Copy(strTargetPath)
0
All Courses

From novice to tech pro — start learning today.