How to copyfile to a Vista's program files sub directory?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Kenley
Newbie
Posts: 10
Joined: Sun Mar 14, 2004 11:10 am

How to copyfile to a Vista's program files sub directory?

Post by Kenley » Wed Jan 28, 2009 9:19 am

The program files directory in Vista is protected by default with UAC. Files can't be copied to a program files subdir without elevation of privelage.

I'm attempting to use copyfile and it silently fails to copy a file from source directory (happens to be desktop) to a folder in the program files directory.

I'm looking for a solution to get this work. [b]It is okay if the user is prompted for administrative elevation in order to get the file copy to work.[/b]

Installers write files to program files.... and Macro Scheduler is compatible with Vista... How can I put a file in the program files directory using MacroScheduler'?

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Jan 28, 2009 9:40 am

You can do one of:

a) Set Macro Scheduler to run as admin on startup

b) Run Macro Scheduler as admin when required.

c) Have Macro Scheduler run as normal but run an elevated script/exe/bat to do the copy, e.g.:

Code: Select all

Let>RP_ADMIN=1
Let>RP_WAIT=1
Run>"c:\program files\macro scheduler 11\msched.exe" "%SCRIPT_DIR%\do_copy.scp"
If you have Pro you can compile the copy script to an exe and simplify the above Run line.

In either case you can pass parms to the called .scp/.exe as usual, e.g.:

...do_copy.scp /SOURCEFILE=c:\whatever.txt /DEST=d:\

Of course if you're just doing a copy then you may just as well call the COPY command:

Code: Select all

Let>RP_ADMIN=1
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run>cmd.exe /c copy "%sourcefile%" "%destfile%"
Using this final option means the bulk of your script can run as normal and only the part that needs to be run as admin is elevated. Which IMO is the correct way to do it.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Kenley
Newbie
Posts: 10
Joined: Sun Mar 14, 2004 11:10 am

copy to %programfiles% - resolved

Post by Kenley » Wed Jan 28, 2009 10:38 am

I was missing RP_ADMIN=1. This option didn't exist in version 9.
On version 11 it works brilliantly.

Thank you!

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