ct253704 Posted September 16, 2014 Share Posted September 16, 2014 (edited) I know this is going to make advanced users cringe, so I apologize in advance. Can anyone show me how to fix this code? Func Java () $JavaSecurity = FileCopy ("\\fileserver01\disks\java\deployment.properties", @UserProfileDir & "\appdata\locallow\sun\java\deployment", $FC_OVERWRITE) If @ERROR Then $Verify = MsgBox (0, "Verify", "Verify your Java and then run the script again!") If $Verify = 1 Then Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://www.java.com/verify","") If $Verify = 1 Then FileDelete (@UserProfileDir & "\appdata\locallow\sun\java\deployment") ShellExecuteWait (@UserProfileDir & "\appdata\locallow\sun\java\deployment") EndFunc I am just copying a modified deployment file to client machines to deal with a security issue. If the deployment folder doesn't exist yet (no java instance has ever ran on client profile) then I want a message box to pop up to tell them to verify and when they click OK it opens the verify page @ java so they can run an instance and create the deployment file before doing a copy. However, it keeps telling me $verify isn't declared. If I try and set it as a Local variable first, it still gives me an error. I have tried using the IF AND IF THEN functions for when msgbox is clicked and can't seem to work out how to get those 2 lines into one. Everything else in the code works. The messagebox pops up if the folder doesn't exist, and the webpage will pop up as well as long as i use F5 with the script open. However, running not in edit mode or as a compiled it will give me the declaration error. I am SURE this is somewhere in the help file or forums, but I don't think I'm searching for the right things. Also, can someone tell me why I can't use this line even if $verify is declared. $verify = MsgBox (0, "Verify", "Verify your Java and then run the script again!") If @error=1 Then $Verify I know you can't just use $verify by itself, but how would you write that in a different way? YES I know these are simple questions I really have looked for the answers promise. Edit: I also see $MB_Systemmodal used a lot in the help file for msgbox function. Is there a link to a list where I can see all of the available microsoft boxes already pre-coded in autoit? Edited September 16, 2014 by ct253704 Link to comment Share on other sites More sharing options...
JohnOne Posted September 16, 2014 Share Posted September 16, 2014 Func Java() Local $Verify = 0 $JavaSecurity = FileCopy("\\fileserver01\disks\cody\java\deployment.properties", @UserProfileDir & "\appdata\locallow\sun\java\deployment", $FC_OVERWRITE) If @error Then $Verify = MsgBox(0, "Verify", "Verify your Java and then run the script again!") If $Verify = 1 Then Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://www.java.com/verify", "") If $Verify = 1 Then FileDelete(@UserProfileDir & "\appdata\locallow\sun\java\deployment") ShellExecuteWait(@UserProfileDir & "\appdata\locallow\sun\java\deployment") EndFunc ;==>Java You are saying you get an error that $verify has not been declared with above? 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...
MikahS Posted September 16, 2014 Share Posted September 16, 2014 (edited) For one, MsgBox returns a value of the button pressed, which is why you can't call the $Verify variable to bring up a MsgBox. If @error never gets set, then $verify is never declared with a value, essentially when you are asking if it equals 1 and there is nothing there, so that is why it is giving you an error and saying you need to declare it. Edited September 16, 2014 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
ct253704 Posted September 16, 2014 Author Share Posted September 16, 2014 (edited) Ok JohnOne so that worked using Local $Verify = 0. I saw in the Best Coding practices about setting variables to default, but maybe i'm confused as to why I would set to 0 rather than Local $Verify = Msgbox (etc..) And MikahS that makes sense. In this instance could you give me an example on how to set the @error to represent the file not copying specifically? You're not saying that I could use that line by setting @error, though, right? Edited September 16, 2014 by ct253704 Link to comment Share on other sites More sharing options...
MikahS Posted September 16, 2014 Share Posted September 16, 2014 (edited) Well for one, The way to see if FileCopy worked is not with @error Success: 1. Failure: 0. If $JavaSecurity = 0 Then MsgBox(0, "Verify", "Verify your Java and then run the script again!") EndIf Edited September 16, 2014 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
JohnOne Posted September 16, 2014 Share Posted September 16, 2014 (edited) Func Java() Local $Verify = 0 If FileCopy("\\fileserver01\disks\cody\java\deployment.properties", @UserProfileDir & "\appdata\locallow\sun\java\deployment", $FC_OVERWRITE) Then $Verify = MsgBox(0, "Verify", "Verify your Java and then run the script again!") If $Verify = 1 Then Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://www.java.com/verify", "") If $Verify = 1 Then FileDelete(@UserProfileDir & "\appdata\locallow\sun\java\deployment") ShellExecuteWait(@UserProfileDir & "\appdata\locallow\sun\java\deployment") Else Exit MsgBox(0, 0, "Failed to copy file") EndIf EndFunc ;==>Java Edited September 16, 2014 by JohnOne MikahS 1 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...
ct253704 Posted September 16, 2014 Author Share Posted September 16, 2014 Thanks to both of you. I know this was trivial but it cleared up a world of questions in my brain. Thanks again for all your help! Link to comment Share on other sites More sharing options...
Solution MikahS Posted September 16, 2014 Solution Share Posted September 16, 2014 (edited) Func Java() Local $Verify = 0 If FileCopy("\\fileserver01\disks\cody\java\deployment.properties", @UserProfileDir & "\appdata\locallow\sun\java\deployment", $FC_OVERWRITE) Then $Verify = MsgBox(0, "Verify", "Verify your Java and then run the script again!") If $Verify = 1 Then Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://www.java.com/verify", "") FileDelete(@UserProfileDir & "\appdata\locallow\sun\java\deployment") ShellExecuteWait(@UserProfileDir & "\appdata\locallow\sun\java\deployment") EndIf Else Exit MsgBox(0, 0, "Failed to copy file") EndIf EndFunc ;==>Java Modified JohnOne's. EDIT: anytime Edited September 16, 2014 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
ct253704 Posted September 16, 2014 Author Share Posted September 16, 2014 Alright so using what you guys gave me I finally have a working script. I had to modify some things as it was copying a decoy file to a directory that didn't exist and I only wanted the messagebox to appear if the directory didn't copy properly so here's what I ended up with. Func Java() Local $Verify = 0 $JavaExists = FileExists (@UserProfileDir & "\appdata\locallow\sun\java\deployment\deployment.properties") If $JavaExists = 0 Then $Verify = MsgBox(0, "Verify", "Verify your Java and then run the script again!") If $Verify = 1 Then Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://www.java.com/verify", "") EndIf Else $JavaSecurity = FileCopy("\\fileserver01\disks\cody\java\deployment.properties", @UserProfileDir & "\appdata\locallow\sun\java\deployment", $FC_OVERWRITE) ShellExecuteWait(@UserProfileDir & "\appdata\locallow\sun\java\deployment") Exit MsgBox(0, 0, "File Copied") EndIf EndFunc ;==>Java Now it just checks to see if the directory exists first, if it doesn't it gives me the messagebox to verify. If it does it copies and gives me the successful message box. Again, thank you guys it made this so much easier. Link to comment Share on other sites More sharing options...
MikahS Posted September 16, 2014 Share Posted September 16, 2014 Glad to help Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ 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