Jump to content

Failing at Variables


ct253704
 Share

Go to solution Solved by MikahS,

Recommended Posts

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 by ct253704
Link to comment
Share on other sites

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

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 by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

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 by ct253704
Link to comment
Share on other sites

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 by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

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 by JohnOne

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

  • Solution

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 by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

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

Glad to help :D

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

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