REWard01 Posted January 24, 2014 Share Posted January 24, 2014 (edited) 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 January 26, 2014 by REWard01 Link to comment Share on other sites More sharing options...
JohnOne Posted January 24, 2014 Share Posted January 24, 2014 You'll need to run as administrator in Vista+ AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
l3ill Posted January 24, 2014 Share Posted January 24, 2014 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 My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
l3ill Posted January 24, 2014 Share Posted January 24, 2014 (edited) 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 January 24, 2014 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
REWard01 Posted January 24, 2014 Author Share Posted January 24, 2014 (edited) 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 January 25, 2014 by REWard01 Link to comment Share on other sites More sharing options...
REWard01 Posted January 25, 2014 Author Share Posted January 25, 2014 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 More sharing options...
l3ill Posted January 25, 2014 Share Posted January 25, 2014 (edited) Tested previous post (adding #RequireAdmin) on Win 8.1 64 bit.... works! BTW you can still go back and edit/fix your first post... nevermind *see below.. Edited January 25, 2014 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 25, 2014 Moderators Share Posted January 25, 2014 l3ill, BTW you can still go back and edit/fix your first postNot 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
REWard01 Posted January 26, 2014 Author Share Posted January 26, 2014 (edited) Tested previous post (adding #RequireAdmin) on Win 8.1 64 bit.... works! BTW you can still go back and edit/fix your first post... 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 January 26, 2014 by REWard01 Link to comment Share on other sites More sharing options...
l3ill Posted January 26, 2014 Share Posted January 26, 2014 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 My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
REWard01 Posted January 27, 2014 Author Share Posted January 27, 2014 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 More sharing options...
l3ill Posted January 27, 2014 Share Posted January 27, 2014 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. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
REWard01 Posted January 28, 2014 Author Share Posted January 28, 2014 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 More sharing options...
l3ill Posted January 28, 2014 Share Posted January 28, 2014 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 My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now