Script Example: Copying Files To User Profiles

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Script Example: Copying Files To User Profiles

Post by CyberCitizen » Tue May 28, 2013 3:41 am

Hey Guys,

Here is another script example I have after I couldn't find an easy way to copy a new user guide to every users home drive (U Drive in this case). Hopefully it helps someone else out.

Image

YouTube: Copy To Users Home Profile Drive v1.2

Code: Select all

Let>APP_TITLE=CSC Copy To Users Home Drive v1.2 - Written By Michael Allen
Let>MSG_HEIGHT=215
Let>MSG_WIDTH=665
Let>MSG_XPOS=30
Let>MSG_YPOS=30
Let>MSG_STAYONTOP=1

Dialog>Dialog1
object Dialog1: TForm
  Left = 248
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  BorderStyle = bsSingle
  Caption = 'CSC Copy To Users Home Drive'
  ClientHeight = 162
  ClientWidth = 644
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'Courier New'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 16
  object Label1: TLabel
    Left = 8
    Top = 8
    Width = 280
    Height = 16
    Caption = 'Please Enter Path To Users U Shares'
  end
  object Label2: TLabel
    Left = 8
    Top = 64
    Width = 352
    Height = 16
    Caption = 'Please Select File To Copy To Users U Shares'
  end
  object Label3: TLabel
    Left = 8
    Top = 112
    Width = 96
    Height = 16
    Caption = 'Progress Bar'
  end
  object Label4: TLabel
    Left = 656
    Top = 8
    Width = 80
    Height = 16
    Caption = 'Processing'
  end
  object UserSharePath: TEdit
    Left = 8
    Top = 24
    Width = 521
    Height = 24
    TabOrder = 0
    Text = '\\bsmadl-fp01\bmusers\'
  end
  object MSButton1: tMSButton
    Left = 536
    Top = 24
    Width = 105
    Height = 25
    Caption = 'Browse'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbFolder
  end
  object FileToCopy: TEdit
    Left = 8
    Top = 80
    Width = 521
    Height = 24
    TabOrder = 2
    Text = '\\sbsadl-sus02\Public\Health Check\AssetLogs\Files\logon.bat'
  end
  object MSButton2: tMSButton
    Left = 536
    Top = 80
    Width = 105
    Height = 25
    Caption = 'Browse'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object ProgressBar1: TProgressBar
    Left = 8
    Top = 128
    Width = 521
    Height = 24
    TabOrder = 4
  end
  object MSButton3: tMSButton
    Left = 536
    Top = 128
    Width = 105
    Height = 25
    Caption = 'Start Copy'
    Default = True
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 5
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object ProcessingList: tMSMemo
    Left = 656
    Top = 24
    Width = 137
    Height = 129
    TabStop = False
    ReadOnly = True
    ScrollBars = ssVertical
    TabOrder = 6
  end
end
EndDialog>Dialog1

SetDialogProperty>Dialog1,,Caption,%APP_TITLE%
SetDialogProperty>Dialog1,,Left,20
SetDialogProperty>Dialog1,,Top,20
SetDialogProperty>Dialog1,,Width,660
AddDialogHandler>Dialog1,MSButton1,OnClick,SelectUserShares
AddDialogHandler>Dialog1,MSButton2,OnClick,SelectFile
AddDialogHandler>Dialog1,MSButton3,OnClick,StartCopy

Show>Dialog1,Dialog1Result

If>%Dialog1Result%=2,Exit

SRT>SelectUserShares
 SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
 GetDialogProperty>Dialog1,MSButton1,Filename,SharePath
 SetDialogProperty>Dialog1,UserSharePath,Text,SharePath
END>SelectUserShares

SRT>SelectFile
 SetDialogProperty>Dialog1,MSButton2,DoBrowse,True
 GetDialogProperty>Dialog1,MSButton2,Filename,File2Copy
 SetDialogProperty>Dialog1,FileToCopy,Text,File2Copy
END>SelectFile


SRT>StartCopy
 GetDialogProperty>Dialog1,UserSharePath,Text,SharePath
 GetDialogProperty>Dialog1,FileToCopy,Text,File2Copy
 If>{(%SharePath%="") OR (%File2Copy%="")}
   MessageModal>Please Ensure You Have Completed Both The User Profiles Field & The File To Copy Field.%CRLF%%CRLF%Regards%CRLF%Michael Allen © 2012
 Else
   SetDialogProperty>Dialog1,MSButton1,Enabled,False
   SetDialogProperty>Dialog1,MSButton2,Enabled,False
   SetDialogProperty>Dialog1,MSButton3,Enabled,False
   SetDialogProperty>Dialog1,MSButton1,Caption,Please
   SetDialogProperty>Dialog1,MSButton2,Caption,Wait
   SetDialogProperty>Dialog1,MSButton3,Caption,Generating
   SetDialogProperty>Dialog1,Label4,Caption,Generating List
   SetDialogProperty>Dialog1,,Width,812
   Let>Pattern=\\$
   RegEx>Pattern,SharePath,0,matches,num,1,,SharePath
   Let>RP_WAIT=1
   Let>RP_WINDOWMODE=0
   RunProgram>cmd /c dir "%SharePath%\*.*" /ad /on /b > "%TEMP_DIR%users.txt"
   Let>Rows=1
   Label>CountStart
   ReadLn>%TEMP_DIR%users.txt,Rows,line
   If>line=##EOF##,Copy
   EndIf
   GetDialogProperty>Dialog1,ProcessingList,Text,Users
   If>%Users%=
     Let>Users=%line%
   Else
     Let>Users=%line%%CRLF%%Users%
   Endif
   SetDialogProperty>Dialog1,ProcessingList,Text,%Users%
   EndIf
   Let>Rows=Rows+1
   Goto>CountStart
   Label>Copy
   Let>Rows=Rows-1
   SetDialogProperty>Dialog1,ProgressBar1,Min,0
   SetDialogProperty>Dialog1,ProgressBar1,Max,%Rows%
   SetDialogProperty>Dialog1,Label4,Caption,Copying To
   SetDialogProperty>Dialog1,MSButton3,Caption,Copying
   ReadFile>%TEMP_DIR%users.txt,Users
   SetDialogProperty>Dialog1,ProcessingList,Text,%Users%
   Let>CF_OVERWRITE=1
   Let>Ln=1
   Label>Start
   //Wait>0.01
   ReadLn>%TEMP_DIR%users.txt,Ln,LineResult
   If>LineResult=##EOF##,PreFinish
   EndIf
   CopyFile>%File2Copy%,%SharePath%\%LineResult%\
   SetDialogProperty>Dialog1,ProgressBar1,Position,%Ln%
   Let>Ln=Ln+1
   GetDialogProperty>Dialog1,ProcessingList,Text,Users
   StringReplace>%Users%,%LineResult%%CRLF%,,Users
   SetDialogProperty>Dialog1,ProcessingList,Text,%Users%
   Goto>Start
   Label>PreFinish
   Let>MSG_CENTERED=1
   SetDialogProperty>Dialog1,ProcessingList,Text,
   MDL>Finished copying file%CRLF%%File2Copy%%CRLF%to%CRLF%%SharePath%\%CRLF%%CRLF%Regards%CRLF%Michael Allen © 2012
   SetDialogProperty>Dialog1,ProgressBar1,Position,0
   Let>MSG_CENTERED=0
   DeleteFile>%TEMP_DIR%users.txt
   SetDialogProperty>Dialog1,,Width,660
   SetDialogProperty>Dialog1,MSButton1,Enabled,True
   SetDialogProperty>Dialog1,MSButton2,Enabled,True
   SetDialogProperty>Dialog1,MSButton3,Enabled,True
   SetDialogProperty>Dialog1,MSButton1,Caption,Browse
   SetDialogProperty>Dialog1,MSButton2,Caption,Browse
   SetDialogProperty>Dialog1,MSButton3,Caption,Start Copy
 EndIf
END>StartCopy

Label>Exit
FIREFIGHTER

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Wed May 29, 2013 9:14 am

CyberCitizen,
Thanks for your sharing.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts