Sweeny
(Fresh Scripter)
2017-03-02 10:27 PM
Copy to local drive then remove

To the good people of the Kixtart forum,
I have a script which resides on a file share. For unrelated reasons that script needs to be run locally on the machine and can't be run from the file share. Could someone point me in the right direction to how I'd go about automatically copying the script to a temporary location on the local drive, letting it run then removing the script from the local machine
Many thanks in advance,
Tom


AllenAdministrator
(KiX Supporter)
2017-03-03 12:04 AM
Re: Copy to local drive then remove

If you are running it from the logon script it would be nothing more than something like the following.
Copy the file to the %temp% directory.
shell "%temp%\filename.exe"

if you need to run it at a later time, scheduling it with Task Scheduler would be the way to go. Search the board.


Sweeny
(Fresh Scripter)
2017-03-03 10:44 AM
Re: Copy to local drive then remove

Thank you for the advice Allen, I will see what I can get working. The script isn't run from a logon script, it is a standalone script that a technician has to manually run. The issue I am having is the technician not copying the script from the file server onto the local drive before instigating the script. To get round the issue I hoped I'd be able to code in the ability for the script to copy itself and run from the local version then delete itself.
Or am I making this harder than it should be? (not unusual ;\) )
Many thanks,
Tom


Mart
(KiX Supporter)
2017-03-03 11:38 AM
Re: Copy to local drive then remove

What if you put the script in a folder with only read access for the people that need to run the script, copy it from there to a local drive, start it and afterwards delete it?

Something like this?
Completely untested but I am just trying to push you in the right direction.

 Code:
Break on

? "Copying script to local drive and starting it. Standby...."

$source = "\\server\share\script.kix"
$destination = "C:\Folder\"

Copy $source $destination

$Shellline = "Kix32.exe " + $destination + "Script.kix"
Shell $shellline

Del $destination + "Script.kix"


AllenAdministrator
(KiX Supporter)
2017-03-03 03:54 PM
Re: Copy to local drive then remove

If you have sensitive information in the script you could also tokenize it. This would at least obscure the code from prying eyes.

ShaneEP
(MM club member)
2017-03-03 04:05 PM
Re: Copy to local drive then remove

Maybe something like this?
 Code:
If Left(@ScriptDir, 3) <> "C:\"		; NOT RUNNING FROM C:\
	If Exist("%temp%\TempScript.kix")
		Del "%temp%\TempScript.kix"
	EndIf
	Copy @ScriptDir+"\"+@ScriptName "%temp%\TempScript.kix"
	Shell '\\server\share\path\to\wkix32.exe "%temp%\TempScript.kix"'
	Del "%temp%\TempScript.kix"
	Exit 0
EndIf


Sweeny
(Fresh Scripter)
2017-03-03 04:27 PM
Re: Copy to local drive then remove

Thank you everyone for the advice, I will test and hope for the best \:\)