Jump to content

UDF: Copy a file and launch it locally


emmanuel
 Share

Recommended Posts

I wrote this to replace a batch file the users have that copies files from the network and then launches them locally, to avoid locking the file on the network...

this is my first time putting SetError and Return in a script, and I haven't tested that part yet.

;copy file local, then launch with specified app

;get app path from registry

; $appname is the file.exe of the program to launch the copied file, 
; $source is the folder to copy from, no trailing backslash
; $filename is the name of the file to copy, 
; $target is the target folder to copy to, no trailing backslash
; $runmethod should either be Run or RunWait
; $overwrite is 1 to overwrite, 0 not to.

; errorlevel 0 if something didn't work right
; return value:
;   0 if error
;   1 if successful

;example use:
$SERVERPATH = "\\server\share\path to file"
$LOCALPATH = "C:\local_working_dir"
_copylaunch("msaccess.exe", $SERVERPATH, "AccessDB.mdb", $LOCALPATH, "RunWait", 1)

Func _copylaunch($APPNAME, $SOURCE, $FILENAME, $TARGET, $RUNMETHOD, $OVERWRITE) 
   If FileCopy($SOURCE & "\" & $FILENAME, $TARGET & "\" & $FILENAME, $OVERWRITE) = 0 Then 
      SetError(0)
   EndIf
   $_APPPATH = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" & $APPNAME, "")
   If $_APPPATH = 1 Then SetError(0)
   If $RUNMETHOD = "RunWait" Or $RUNMETHOD = "" Then 
      RunWait($_APPPATH & " " & '"' & $TARGET & "\" & $FILENAME & '"')
   ElseIf $RUNMETHOD = "Run" Then
      Run($_APPPATH & " " & '"' & $TARGET & "\" & $FILENAME & '"')
   Else
      SetError(0)
      Return (0)
   EndIf
   
EndFunc  ;==>_copylaunch

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

looks like psexec is not quite what I'm looking for... I'm not looking to push exe's to other computers (that's cool though) I'm looking to allow people to run a script to copy files locally then open them with the specified app. We've got some files that don't like to be open by multipule users at one time, yet we need multipule people to be able to open them...

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

looks like psexec is not quite what I'm looking for...  I'm not looking to push exe's to other computers (that's cool though) I'm looking to allow people to run a script to copy files locally then open them with the specified app.  We've got some files that don't like to be open by multipule users at one time, yet we need multipule people to be able to open them...

I'm trying that with a salesreportgenerator to speed stuff up. It takes forever over the network

Rick

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...