Jump to content

Moving Files to Application Data


FaNtM
 Share

Recommended Posts

Hey folks, i've been tinkering with au3 for quite a while and i decided that i was going to make a small installer thingie to help some friends of mine get updates for a game installed. I'm simply trying to create a folder to move a couple .zip files to and i'm also trying to add a few folders to a .jar file. The destination of the .jar file and the folder that .zip files are going to is in the Application Data directory, and seeing as though the App Data directory is different for all of us (because of different usernames on different computers) i can't seem to get au3 to use @AppDataDir to access other folders within AppData. I thought about just having the script create a folder in there and then moving it from there to where it needs to go, but again i ran into identifying the path to AppData for different users. Because i'm very new to au3, i'm embarassed to post what i have so far here, but i guess it won't hurt to do it anyway:

;
; AutoIt Version: 3.0
; Author:        FaNtM, United States Department of the Navy
;
; Script Function:
;   Installs USNMC ModPackage for Minecraft 1.1
;
#include <GuiConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
;Draws and identifies GUI for installer.
Opt( 'MustDeclareVars', 1)
Install()
Func Install()
Local $Button_1, $Button_2, $msg
GuiCreate( "USNMC Mod Pack Installer", 600, 400)

Opt( "GuiCoordMode", 2)
$Button_1 = GuiCtrlCreateButton( "Install", 230, 375, 80)
$Button_2 = GuiCtrlCreateButton( "Cancel" , 0, -1)

GuiSetState()

While 1
  $msg= GUIGetMsg()
  Select
   Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
   Case $msg = $Button_1
     DirMove( "C:\USNMC Mod Pack\ModLoader", @AppDataDir & "\.minecraft\Backupmods" 1)
     Msgbox(0, "USNMC", "Mods installed! Run MineCraft to make sure it works!")
   Case $msg= $Button_2
     WinKill( "USNMC Mod Pack Installer")
    
   EndSelect
  WEnd
EndFunc

(yes i'm working on updating mods for Minecraft. laugh if you want)

I borrowed some code from the help guide to see if it would work, but it seems as if i can't get it to access the folder that i need it to within AppData. As soon as i figure out how to get it to find each user's AppData folder and point it to the subfolder i need, i'll do the rest myself. I also considered having an input box to have the user point the installer to the director themselves, but i'm having trouble doing that as well. Any help is greatly appreciated, and as i said, i'm rather embarassed to post my horribly noobish code, so go easy on me :)

Link to comment
Share on other sites

Try this:

$Source = "Path to source file" ;Declares the path to the source file you will be moving
$Destination = "Path to destination file" ;Declares the destination of the file you will be moving
;Please note $Source and $Destination must include both directory and file name, including extension
FileWrite($Destination, FileRead($Source)) ;Writes to the destination of the file, the data that is read from the source file
FileDelete($Source) ;Deletes the source file. If you remove this line then the file is copied not moved

I hope that works for you.

Link to comment
Share on other sites

I see the introduction of the new variables, but my problem again is accessing the Application data folder for an entirely different username. for example:

the folder i am modifying is in: C:Documents and Settings"User"Application Data.minecraft

where it says "User" is the username. since i don't think all my friends use the same username, each path to their AppData folder will be different. i saw the function @ApplicationDataDir that points to the current users Application data folder. this is nice, but i need to be able to go further than that, and i cannot do it with that function.

edit: also, the Application Data folder is hidden. And i will save that bit of code for an idea that i just had :) thanks alot!

Edited by FaNtM
Link to comment
Share on other sites

that may also be it, but theres the issue of identifying the Application Data folder for a different username.

edit: i ran a few tests with both snippets you suggested, and got syntax errors when using @AppDataDir

Edited by FaNtM
Link to comment
Share on other sites

Well you can try this script from BrewmanNH to list all of the user profiles in C:Users:

#Include <File.au3>
#include <Array.au3>
Global $aUserList[10], $UserList[10]
If @OSVersion == "WIN_7" Or @OSVersion == "WIN_VISTA" Or @OSVersion = "WIN_2008" Then
    $NewOS = True
ElseIf @OSVersion == "WIN_XP" Then
    $NewOS = False
Else
    MsgBox(48, "Error", "Wrong OS version")
    Exit
EndIf
Global $X = 0
If Not $NewOS Then
    $UserList = _FileListToArray("C:Documents and Settings", "*.*", 2)
    For $I = 1 To $UserList[0]
        Select
            Case $UserList[$I] = "All Users"
            Case $UserList[$I] = "Default User"
            Case $UserList[$I] = "NetworkService"
            Case $UserList[$I] = "LocalService"
            Case $UserList[$I] = "Administrator"
            Case Else
                $aUserList[$X] = $UserList[$I]
                $X += 1
                If $X >= UBound($aUserList) Then
                    ReDim $aUserList[UBound($aUserList) + 10]
                EndIf
        EndSelect
    Next
Else
    $UserList = _FileListToArray("C:Users", "*.*", 2)
    For $I = 1 To $UserList[0]
        Select
            Case $UserList[$I] = "All Users"
            Case $UserList[$I] = "Default"
            Case $UserList[$I] = "Default User"
            Case $UserList[$I] = "Public"
            Case Else
                $aUserList[$X] = $UserList[$I]
                $X += 1
                If $X >= UBound($aUserList) Then
                    ReDim $aUserList[UBound($aUserList) + 10]
                EndIf
        EndSelect
    Next
EndIf
ReDim [size=4][font=arial,helvetica,sans-serif]$aUs[/font][/size]erList[$X]
_ArrayDisplay($aUserList)

Which is found here:

From there, you can do this:

$Source = "Path to source file" ;Declares the path to the source file you will be moving
For $repeat = 0 to Ubound($aUserList)-1 ;For each user in the list
    $Destination = $aUserList&"AppDataRoaming" ;Declares the destination of the file you will be moving
    ;Please note $Source and $Destination must include both directory and file name, including extension
    FileWrite($Destination, FileRead($Source)) ;Writes to the destination of the file, the data that is read from the source file
Next
FileDelete($Source) ;Deletes the source file. If you remove this line then the file is copied not moved

That should copy the file for each user and then delete the file after.

Also, @AppDataDir points towards the current user's appdata directory. It cannot be used to point towards that of another.

Edited by Mikeman27294
Link to comment
Share on other sites

i figured that when it said the current user's AppData Directory, it meant the user running the script. im thinking i might just have an input box to choose a filepath to the directory themselves. also, should this be before or after the GUI?

Link to comment
Share on other sites

Ok, well it is not finished yet but it will give you a head start.

#include <EditConstants.au3>
#include <GUIConstantsEX.au3>
#include <String.au3>
#include <WindowsConstants.au3>
;#include "EncodedFile.au3"
Opt("GuiOnEventMode", 1)
$Product = "ABC123"
Global $GuiArray[30]
$GuiArray[0]    =       GUICreate("Instert Licence Key", 300, 120)
                        GUISetBkColor(0x353535, $GuiArray[0])
$GuiArray[1]    =       GUICtrlCreateTab(-10, -10, 5, 5)
;INSERT LICENCE KEY TAB
$GuiArray[2]    =       GUICtrlCreateTabItem("InsertLicenceKey")
$GuiArray[3]    =       GUICtrlCreateLabel("Please insert your 16 digit license key", 20, 15, 260, 25)
                        GUICtrlSetColor($GuiArray[3], 0xFFFFFF)
                        GUICtrlSetFont($GuiArray[3], 10, 551, -1, "Arial")
$GuiArray[4]    =       GUICtrlCreateInput("", 20, 40, 50, 21, 0x0008)
                        GUICtrlSetLimit($GuiArray[4], 4, 0)
$GuiArray[5]    =       GUICtrlCreateLabel("-", 70, 40, 20, -1, 0x01)
$GuiArray[6]    =       GUICtrlCreateInput("", 90, 40, 50, 21, 0x0008)
                        GUICtrlSetLimit($GuiArray[6], 4, 0)
$GuiArray[7]    =       GUICtrlCreateLabel("-", 140, 40, 20, -1, 0x01)
$GuiArray[8]    =       GUICtrlCreateInput("", 160, 40, 50, 21, 0x0008)
                        GUICtrlSetLimit($GuiArray[8], 4, 0)
$GuiArray[9]    =       GUICtrlCreateLabel("-", 210, 40, 20, -1, 0x01)
$GuiArray[10]   =       GUICtrlCreateInput("", 230, 40, 50, 21, 0x0008)
                        GUICtrlSetLimit($GuiArray[10], 4, 0)
$GuiArray[11]   =       GUICtrlCreateLabel("", 20, 70, 260, 21, 0x01)
$GuiArray[12]   =       GUICtrlCreateDummy()
$GuiArray[13]   =       GUICtrlCreateButton("Cancel", 5, 90, 75, 25)
                        GUICtrlSetBkColor($GuiArray[13], 0x202020)
                        GUICtrlSetColor($GuiArray[13], 0xFFFFFF)
                        GUICtrlSetOnEvent($GuiArray[13], "_Exit")
$GuiArray[14]   =       GUICtrlCreateButton("Install Trial", 150, 90, 70, 25)
                        GUICtrlSetBkColor($GuiArray[14], 0x202020)
                        GUICtrlSetColor($GuiArray[14], 0xFFFFFF)
                        GUICtrlSetOnEvent($GuiArray[14], "_TrialTab")
$GuiArray[15]   =       GUICtrlCreateButton("Next", 225, 90, 70, 25)
                        GUICtrlSetState($GuiArray[15], $GUI_DISABLE)
                        GUICtrlSetBkColor($GuiArray[15], 0x202020)
                        GUICtrlSetColor($GuiArray[15], 0xFFFFFF)
                        GUICtrlSetOnEvent($GuiArray[15], "_Install")
                        GUIRegisterMsg($WM_COMMAND, "On_WM_COMMAND");USED FOR SWITCHING TO NEXT TEXT BOX
;INSTALL TRIAL OPTIONS TAB
$GuiArray[16]   =       GUICtrlCreateTabItem("InstallTrial")
$GuiArray[17]   =       GUICtrlCreateLabel("Where would you like to install?", 20, 15, 260, 25)
                        GUICtrlSetColor($GuiArray[17], 0xFFFFFF)
                        GUICtrlSetFont($GuiArray[17], 10, 551, -1, "Arial")
$GuiArray[18]   =       GUICtrlCreateInput("", 20, 40, 190, 21, 0x0080)
                        GUICtrlSetState($GuiArray[18], $GUI_DISABLE)
$GuiArray[19]   =       GUICtrlCreateButton("Browse", 220, 39, 70, 24)
                        GUICtrlSetBkColor($GuiArray[19], 0x202020)
                        GUICtrlSetColor($GuiArray[19], 0xFFFFFF)
                        GUICtrlSetOnEvent($GuiArray[19], "_Browse")
$GuiArray[20]   =       GUICtrlCreateButton("Cancel", 5, 90, 75, 25)
                        GUICtrlSetBkColor($GuiArray[20], 0x202020)
                        GUICtrlSetColor($GuiArray[20], 0xFFFFFF)
                        GUICtrlSetOnEvent($GuiArray[20], "_Exit")
$GuiArray[21]   =       GUICtrlCreateButton("Insert Serial", 150, 90, 70, 25)
                        GUICtrlSetBkColor($GuiArray[21], 0x202020)
                        GUICtrlSetColor($GuiArray[21], 0xFFFFFF)
                        GUICtrlSetOnEvent($GuiArray[21], "_InstallSerialTab")
$GuiArray[22]   =       GUICtrlCreateButton("Next", 225, 90, 70, 25)
                        GUICtrlSetState($GuiArray[22], $GUI_DISABLE)
                        GUICtrlSetBkColor($GuiArray[22], 0x202020)
                        GUICtrlSetColor($GuiArray[22], 0xFFFFFF)
                        GUICtrlSetOnEvent($GuiArray[22], "_Install")
;INSTALLING TRIAL TAB
$GuiArray[23]   =       GUICtrlCreateTabItem("InstallTrial")
$GuiArray[24]   =       GUICtrlCreateLabel("Installing.", 20, 15, 260, 25)
                        GUICtrlSetColor($GuiArray[24], 0xFFFFFF)
                        GUICtrlSetFont($GuiArray[24], 10, 551, -1, "Arial")
$GuiArray[25]   =       GUICtrlCreateProgress(20, 40, 260, 21)
$GuiArray[29]   =       GUICtrlCreateTabItem("")
GUISetOnEvent(-3, "_Exit")
GUISetState(@SW_SHOW, $GuiArray[0])
While 1
    For $Repeat = 2 to 6 Step 2
        $hasFocus = (GUICtrlGetState($GuiArray[$Repeat]) < 512) AND (GUICtrlGetState($GuiArray[$Repeat]) > 255)
        If $hasFocus And StringLen(GUICtrlRead($GuiArray[$Repeat])) = 4 Then
            GUICtrlSetState($GuiArray[$Repeat+2], 256)
        EndIf
    Next
    $ProductKey = GUICtrlRead($GuiArray[4])&GUICtrlRead($GuiArray[6])&GUICtrlRead($GuiArray[8])&GUICtrlRead($GuiArray[10])
    If StringLen($ProductKey) > 0 And Not StringIsAlNum($ProductKey) And GUICtrlRead($GuiArray[11]) <> "Product Key can only contain A-Z and 0-9" Then
        GUICtrlSetColor($GuiArray[11], 0xFF0000)
        GUICtrlSetData($GuiArray[11], "Product Key can only contain A-Z and 0-9")
        GUICtrlSetState($GuiArray[15], $GUI_DISABLE)
    EndIf
    If StringLen($ProductKey) < 16 And GUICtrlRead($GuiArray[11]) <> "Product Key is Incomplete" Then
        If StringIsAlNum($ProductKey) Then
            GUICtrlSetColor($GuiArray[11], 0xFFFF00)
            GUICtrlSetData($GuiArray[11], "Product Key is Incomplete")
            GUICtrlSetState($GuiArray[15], $GUI_DISABLE)
        EndIf
    EndIf
    If StringLen($ProductKey) = 0 And GUICtrlRead($GuiArray[11]) <> "Product Key is Incomplete" Then
        GUICtrlSetColor($GuiArray[11], 0xFFFF00)
        GUICtrlSetData($GuiArray[11], "Product Key is Incomplete")
        GUICtrlSetState($GuiArray[15], $GUI_DISABLE)
    EndIf
WEnd

Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $iCode = BitShift($wParam, 16)
    $iID = BitAND($wParam, 0x0000FFFF)
    Switch $iCode
        Case $EN_UPDATE
            If StringLen(GUICtrlRead($iID)) = 4 Then
                GUICtrlSetState($iID + 2, $GUI_ENABLE)
                GUICtrlSetState($iID + 2, $GUI_FOCUS)
                GUICtrlSetData($iID, StringUpper(GUICtrlRead($iID)))
                _CheckValidity()
            EndIf
    EndSwitch
EndFunc   ;==>On_WM_COMMAND

Func _CheckValidity()
    $ProductKey = GUICtrlRead($GuiArray[4])&GUICtrlRead($GuiArray[6])&GUICtrlRead($GuiArray[8])&GUICtrlRead($GuiArray[10])
    If StringLen($ProductKey) = 16 Then
        $matches = StringRegExp($ProductKey, "([ADHQ79][AT013][HJ579][42GH][09HJKP][1STVX][632WUV][YTU186][16ABZ][H347][DHA456][63CUY][12ANU][D075][1736ADGJNP][AGT0123])", 1)
        If IsArray($matches) AND $matches[0] = $ProductKey Then
            GUICtrlSetColor($GuiArray[11], 0x2FFF2F)
            GUICtrlSetData($GuiArray[11], "Product Key is Valid")
            GUICtrlSetState($GuiArray[15], $GUI_ENABLE)
        Else
            GUICtrlSetColor($GuiArray[11], 0xFF0000)
            GUICtrlSetData($GuiArray[11], "Product Key is Invalid")
            GUICtrlSetState($GuiArray[15], $GUI_DISABLE)
        EndIf
    EndIf
    Return
EndFunc

Func _InstallSerialTab()
    GUICtrlSendMsg($GuiArray[1], 4912, 0, 0)
EndFunc

Func _TrialTab()
    GUICtrlSendMsg($GuiArray[1], 4912, 1, 0)
EndFunc

Func _Browse()
    Global $TrialLocation = FileSelectFolder("Browse...", -1)
    While StringStripWS(StringUpper($TrialLocation), 8) = "COMPUTER" Or StringStripWS(StringUpper($TrialLocation), 8) = "MYCOMPUTER" Or StringStripWS(StringUpper($TrialLocation), 8) = "CONTROL" Or StringStripWS(StringUpper($TrialLocation), 8) = "CONTROLPANEL" Or StringStripWS(StringUpper($TrialLocation), 8) = "RECYCLE" Or StringStripWS(StringUpper($TrialLocation), 8) = "BIN" Or StringStripWS(StringUpper($TrialLocation), 8) = "RECYCLEBIN" Or StringStripWS(StringUpper($TrialLocation), 8) = "NETWORK" Or StringStripWS(StringUpper($TrialLocation), 8) = "HOMEGROUP"
        MsgBox(0,"Error", "Cannot install to this directory.")
        Global $TrialLocation = FileSelectFolder("Browse...", -1)
    WEnd
    If $TrialLocation <> "" And StringRight($TrialLocation, 1) = "" Then
        $TrialLocation &= $Product&""
    ElseIf $TrialLocation <> "" Then
        $TrialLocation &= ""&$Product&""
    EndIf
    GUICtrlSetData($GuiArray[18], $TrialLocation)
    GUICtrlSetState($GuiArray[22], $GUI_ENABLE)
EndFunc

Func _Exit()
    Exit
EndFunc

Func _Install()
    GUICtrlSendMsg($GuiArray[1], 4912, 2, 0)
    Switch @GUI_CtrlId
        Case $GuiArray[15]
            ;Install Full
        Case $GuiArray[22]
            ;Install Trial
    EndSwitch
EndFunc

And here is a key generator for it. It isn't required, because you can generate your own based on the Regular Expresion in the previously included script, but it will just make it all faster for you.

Global $ProductKeyCombinations[16][11] = [["6","A","D","H","Q","7","9"],["5","A","T","0","1","3"],["5","H","J","5","7","9"],["4","4","2","G","H"],["6","0","9","H","J","K","P"],["1","S","T","V","X"],["6","3","2","W","U","V"],["Y","T","U","1","8","6"],["1","6","A","B","Z"],["H","3","4","7"],["D","H","A","4","5","6"],["6","3","C","U","Y"],["5","1","2","A","N","U"],["4","D","0","7","5"],["10","1","7","3","6","A","D","G","J","N","P"],["7","A","G","T","0","1","2","3"]]
Global $GeneratedKey = ""
For $Repeat = 0 to 3
    $GeneratedKey = $GeneratedKey & $ProductKeyCombinations[$Repeat][Random(1, $ProductKeyCombinations[$Repeat][0])]
Next
$GeneratedKey = $GeneratedKey & "-"
For $Repeat = 4 to 7
    $GeneratedKey = $GeneratedKey & $ProductKeyCombinations[$Repeat][Random(1, $ProductKeyCombinations[$Repeat][0])]
Next
$GeneratedKey = $GeneratedKey & "-"
For $Repeat = 8 to 11
    $GeneratedKey = $GeneratedKey & $ProductKeyCombinations[$Repeat][Random(1, $ProductKeyCombinations[$Repeat][0])]
Next
$GeneratedKey = $GeneratedKey & "-"
For $Repeat = 12 to 15
    $GeneratedKey = $GeneratedKey & $ProductKeyCombinations[$Repeat][Random(1, $ProductKeyCombinations[$Repeat][0])]
Next
FileDelete(@DesktopDir&"Licence Key.txt")
FileWrite(@DesktopDir&"Licence Key.txt", $GeneratedKey)

I am also tinkering with making a script to convert the source read from a file into hex, and then the executable can hold it, and write from that.

Edited by Mikeman27294
Link to comment
Share on other sites

oh dear. that looks..... very complex. im assuming what ive been cracking at is going to end up like that isn't it? even if it does, it would make me feel awsome for writing something that looks as mad as that does. i think ill just look into making the path selection input and then telling it where it all goes. if i did that, i'd need the script to check for a certain folder (namely the .minecraft folder) and to travel inside and create a mods folder. again, i will put the above code into my snippet box, as this looks very promising. you are indeed talented my friend, and i wish to be as good as you one day.

Link to comment
Share on other sites

No. Mine is more complex than it needs to be, and when you ran it you should have noticed that it is because it is more about looking good than anything. So you want to create the mod in c:UsersUsernameAppdataRoamingMinecraft ?

And hahah thanks for the complement. I just pride myself with my presentation. Anybody can do it if they stick to autoit for long enough.

Link to comment
Share on other sites

Let me ask you something so I am clear.

You are writing this script to add/alter files for multiple users on the same computer, and they are not allowed to run the script themselves when they are logged on?

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

no, i am trying to identify the AppData folder of users on different computers. because each computer has a unique username, the path to the AppData folder will never be the same, so ive been trying to figure out how to get the script to find it.

Link to comment
Share on other sites

  • Moderators

Hi, FaNtM. I'm confused as to why @AppData is not working for you. The code you posted in your initial entry works fine for me on XP and Windows 7 systems, with only one typo found. In your DirMove line, you forgot the comma before the final flag:

DirMove( "C:USNMC Mod PackModLoader", @AppDataDir & ".minecraftBackupmods", 1)

Other than this, it works flawlessly for me.

Edit: flawlessly without having to stipulate #RequireAdmin, even

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

no, i am trying to identify the AppData folder of users on different computers. because each computer has a unique username, the path to the AppData folder will never be the same, so ive been trying to figure out how to get the script to find it.

I don't get it, @AppDataDir will return the correct dir for whatever computer it runs on for whatever user is logged on.

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

so you mean my initial code was right? if thats the case, then i must be doing something wrong elsewhere. ill have a look again and see what might be wrong.

edit: added the comma in and it seems to be working. looks like i just noobed the hell out of my own code. thanks for all the replies folks, it was alot of help. i also will be looking into how to have the user specify the directory to copy the files to as well as a working progress bar and checkbox system for which files to install.

edit#2: i also just realized that i need to move files inside folders to where they're supposed to go. the only issue is, i don't know if i have to define each file to copy (which will take hours) or if i can have it just copy everything in the folder and move it in 1 go.

Edited by FaNtM
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...