Solved

copy using windows logon script

Posted on 2004-10-26
1,177 Views
Last Modified: 2010-04-19
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?
0
Question by:NormanDaoust
    12 Comments
     
    LVL 6

    Expert Comment

    by:nihlcat
    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
     
    LVL 6

    Expert Comment

    by:nihlcat
    Oops, sorry I copied from my batch file wrong:

    copy "%SystemRoot%\shared_folder\YOURSHORTCUT.LNK" "c:\Documents and Settings\All Users\Desktop"
    0
     

    Author Comment

    by:NormanDaoust
    if at all possible I would like to accomplish this using vbs since all other scripts on our system are vb scripts.
    0
     
    LVL 6

    Expert Comment

    by:nihlcat
    Oh, ok.  Someone else will have your anser then.  :)
    0
     
    LVL 70

    Expert Comment

    by:Chris Dent
    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
     
    LVL 70

    Expert Comment

    by:Chris Dent

    hehe all that to achieve the one line nihlcat posted ;)
    0
     
    LVL 6

    Expert Comment

    by:nihlcat
    =)
    0
     
    LVL 70

    Expert Comment

    by:Chris Dent
    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
     

    Author Comment

    by:NormanDaoust
    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
     

    Author Comment

    by:NormanDaoust
    ... 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
     
    LVL 70

    Expert Comment

    by:Chris Dent

    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
     
    LVL 70

    Accepted Solution

    by:

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

    Copy File from "\\crispserv\portal\CRISP Portal.lnk"
    To "%UserProfile%\Desktop\CRISP Portal.lnk"
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: MongoDB Object-Document Mapper for NodeJS

    NodeJS (JavaScript on the server) is awesome, but some developers get confused about NoSQL when it comes to working in Node with MongoDB (NoSQL database). Do you need a better explanation of how to use Node.js with MongoDB? The most popular choice is the Mongoose library.

    I have never ceased to be amazed how many problems you can encounter on a fresh install of a Windows operating system.  This is certainly case in point& Unable to complete ANY MSI installation.  This means Windows Updates are failing and I can't …
    Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    857 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now