Jump to content

FileCopy with System Folder not working


REWard01
 Share

Recommended Posts

I have written a script that is used to copy one of two files, depending on which button is selected, in to the System Folder;

C:WINDOWSSystem32GroupPolicyMachine

I can run a batch file and the copy runs fine, in to the system folder mentioned above.

I have tested my script using some test folders in the root of my c drive and it works fine.

Does anyone know of any problems writing to System Folders or a possible workaround?

Here is my script:

#include <Constants.au3>

#include <MsgBoxConstants.au3>

#include <FileConstants.au3>

Dim $iMsgBoxAnswer

$iMsgBoxAnswer = MsgBox ($MB_YESNOCANCEL, "Temp Folder Allow/Disallow Install Selector","Allow installation from Temp Folder Select Yes" & @CRLF & "" & @CRLF & "Disallow installation from Temp Folder Select No")

If $iMsgBoxAnswer == $IDYES Then ; 6 Yes

FileCopy ('"C:\WINDOWS\System32\GroupPolicy\Machine\Enable-TempInstall\Registry.pol", "C:\WINDOWS\System32\GroupPolicy\Machine\"', $FC_OVERWRITE)

ElseIf $iMsgBoxAnswer == $IDNO Then ; 7 No

FileCopy ("C:\WINDOWS\System32\GroupPolicy\Machine\Disable-TempInstall\Registry.pol", "C:\WINDOWS\System32\GroupPolicy\Machine\", $FC_OVERWRITE)

ElseIf $iMsgBoxAnswer == $IDCANCEL Then ; 2 Cancel

MsgBox(0,"Cancel","You Pressed the Cancel button!")

EndIf

Thanks for the help!

Edited by REWard01
Link to comment
Share on other sites

Hi REWard01,

  Welcome to the Forums!

please use the [A] button when posting code (see my sig)

Also those are read only folders so you will have to workaround that, try Johns suggestion or change them manually.

Bill

Link to comment
Share on other sites

Okay I just tested this without either of the above and it worked:

FileCopy ("C:\WINDOWS\System32\GroupPolicy\Machine\Disable-TempInstall\R\Registry.pol", "C:\WINDOWS\System32\GroupPolicy\Machine\", $FC_OVERWRITE)

Win7 32Bit

Might be a problem with the way you are calling it (GUI) (buttons)

Almost definitely your MsgBox I used this to test and it is working:

Clicking "Retry" should copy Registry.Pol from R dir to Machine dir

#include <Constants.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
_msgBox()

Func _msgBox()
$msg = MsgBox(4133, "SYSTEMMODAL", "This is a Test Message Box")
;$MB_ICONQUESTION 32 Question-mark icon
;$MB_RETRYCANCEL 5 Retry and Cancel

If $msg = $IDRETRY Then
                        MsgBox(0, "Test", "Retry was Clicked", 1)
                        FileCopy ("C:\WINDOWS\System32\GroupPolicy\Machine\Disable-TempInstall\R\Registry.pol", "C:\WINDOWS\System32\GroupPolicy\Machine\", $FC_OVERWRITE)
                EndIf

If $msg = $IDCANCEL Then
                        MsgBox(0, "Test", "Cancel was Clicked", 1)

                EndIf
EndFunc
Edited by l3ill
Link to comment
Share on other sites

First, thanks for the quick responses.

I am running Windows 8.1 Pro 64-bit, sorry did not mention that previously!

Sorry about the Code Post, will make sure to do that in future!

I have tried compiling & then running .exe as Administrator, did not work.

I have also added the two following lines to the beginning of script:

#RequireAdmin
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
Did not help.

Also, as mentioned I can run a batch file and the files will copy just fine, so the Read Only thing is not the issue.

I did take ownership of the folder and gave full rights to administrators & authenticated users, which I believe is what allowed the batch file to work.

Edited by REWard01
Link to comment
Share on other sites

I tried rewriting using your ideas below, but still not working.  Maybe something with 64-bit os!?! I will try on a 32-bit system, when I can find/get to one!

 

Okay I just tested this without either of the above and it worked:

FileCopy ("C:\WINDOWS\System32\GroupPolicy\Machine\Disable-TempInstall\R\Registry.pol", "C:\WINDOWS\System32\GroupPolicy\Machine\", $FC_OVERWRITE)

Win7 32Bit

Might be a problem with the way you are calling it (GUI) (buttons)

Almost definitely your MsgBox I used this to test and it is working:

Clicking "Retry" should copy Registry.Pol from R dir to Machine dir

#include <Constants.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
_msgBox()

Func _msgBox()
$msg = MsgBox(4133, "SYSTEMMODAL", "This is a Test Message Box")
;$MB_ICONQUESTION 32 Question-mark icon
;$MB_RETRYCANCEL 5 Retry and Cancel

If $msg = $IDRETRY Then
                        MsgBox(0, "Test", "Retry was Clicked", 1)
                        FileCopy ("C:\WINDOWS\System32\GroupPolicy\Machine\Disable-TempInstall\R\Registry.pol", "C:\WINDOWS\System32\GroupPolicy\Machine\", $FC_OVERWRITE)
                EndIf

If $msg = $IDCANCEL Then
                        MsgBox(0, "Test", "Cancel was Clicked", 1)

                EndIf
EndFunc
Link to comment
Share on other sites

Tested previous post (adding #RequireAdmin)  on Win 8.1 64 bit.... :thumbsup:  works!

BTW you can still go back and edit/fix your first post... o:)  nevermind *see below..

Edited by l3ill
Link to comment
Share on other sites

  • Moderators

l3ill,

 

BTW you can still go back and edit/fix your first post

Not until the OP has ~10 posts. It is one of the "New Member" restrictions - they can only edit a post for a few minutes after initial posting. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Tested previous post (adding #RequireAdmin)  on Win 8.1 64 bit.... :thumbsup:  works!

BTW you can still go back and edit/fix your first post... o:)  nevermind *see below..

Thanks for the help.  I run the script and it goes to the correct place in code, like it is supposed to, but the FileCopy does not copy the file to the Destination for some reason!?!

it is some odd stuff. I originally wrote this in a command/batch file that works fine. I used a batch file add-in (WSelect) that pops up a GUI Window with selections. It I run the command file with the WSelect everything works perfectly.  I used a Bat2EXE Compiler to make my command file an .exe file, when I run the exe file I get errors that it cannot find the path specified (the exact same path as what is in the command file, that works!?!).

I have a feeling that for some reason the FileCopy command is having the same issues as the Bat2EXE converted exe file...

I was hoping to use AutoIt because it is much cleaner & can be edited/adjusted more completely for the best interface. And harder for anyone to go in and make changes to my original code, which could cause some system problems in the long run.

I wish I could echo  the command lines in my script to be able to see exactly what is happening  (or have the output go to a file I could review after running the script)!

Edited by REWard01
Link to comment
Share on other sites

Try this and let us know what you get

#include <FileConstants.au3>
#include <File.au3>
#RequireAdmin
$tFile = "C:\WINDOWS\System32\GroupPolicy\Machine\Disable-TempInstall\R\Registry_test.pol" ; intentionally changed for testing
_FileCreate($tFile)
If @error = 1 Then
    MsgBox(0, "", "Error opening specified file")
EndIf
If @error = 2 Then
    MsgBox(0, "", "File could not be written to")
EndIf

If FileCopy($tFile, "C:\WINDOWS\System32\GroupPolicy\Machine\", $FC_OVERWRITE) = 1 Then

    MsgBox(0, "", "Success")
Else
    MsgBox(0, "", "Failed to Copy")
EndIf
Link to comment
Share on other sites

 

Try this and let us know what you get

#include <FileConstants.au3>
#include <File.au3>
#RequireAdmin
$tFile = "C:\WINDOWS\System32\GroupPolicy\Machine\Disable-TempInstall\R\Registry_test.pol" ; intentionally changed for testing
_FileCreate($tFile)
If @error = 1 Then
    MsgBox(0, "", "Error opening specified file")
EndIf
If @error = 2 Then
    MsgBox(0, "", "File could not be written to")
EndIf

If FileCopy($tFile, "C:\WINDOWS\System32\GroupPolicy\Machine\", $FC_OVERWRITE) = 1 Then

    MsgBox(0, "", "Success")
Else
    MsgBox(0, "", "Failed to Copy")
EndIf

 

I get the "Error opening specified file" message and of course followed by "Failed to Copy" message.

Link to comment
Share on other sites

Two other things I did that I assumed you had tried:

Make all hidden folders visible (default is system folders hidden)

And I turned the UAC all the way down for testing.

 

UAC I turn off on any system I setup immediately, slows down installing applications & updates!

I tried Unchecking "Hide protected operating system files",  which still did not allow the copying of the files!

Of course even if it did, I do not think I would want to change that setting on client/users systems.

I appreciate all the help. For the time being I will just stick with the command/batch file with WSelect & just keep chipping away at this with AutoIt.

Link to comment
Share on other sites

I figured you had...

No problem. Sorry we couldnt find the problem...

I am testing on an almost fresh out of the box laptop with 64 bit Win 8.1 and had no problems except the ones mentioned.

So, no idea where its hanging.

cya,

Bill

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...