Jump to content

My Brain Hurts Can't Figure Out How...*SOLVED*


Recommended Posts

I'm attempting to create a script that imports a registry file and then executes a program

What I would like ultimately is for the script to only install the registry file once

So the next time the user executes the script it skips importing the registry and just start the program

As you can tell by the script below, something just isn't right and I can't figure out how to get this going!

#Include <File.au3>

If Not FileExists ( 'C:\scripts\' & @UserName ) Then 
    _FileCreate ( 'C:\Scripts\' & @UserName )
    MsgBox ( 0, '', 'Import Registry' )
    MsgBox ( 0, '', 'Run Program' )
EndIf

If FileExists ( 'C:\Scripts\' & @UserName ) Then
        MsgBox ( 0, '', 'Run program II' )
    EndIf

Edit:

I solved this to my liking, please read on though!

Edited by Elephant007
Link to comment
Share on other sites

K lets break this down.

So you want:

Program to install reg file on startup on first execution.

Program to not install reg file after that.

So, we need to find a way to remember if you have already installed a file.

So out program will now loook like:

-> Check if reg install has been done before.

If no -> install reg file and run program.

If yes -> run program.

There are a handful of ways you can make your program 'remember' things between runs, like remembering if it has installed the registry file.

The easiest and best suited for your uses is to use the 'Iniwrite' and 'iniread' functions. Look at the help pages for documentation.

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

I don't see that the script snippet you posted had anything to do with importing the registry file. You're talking about importing a file to the Windows registry, yes?

If so, it should be simple: Use IF and RegRead to look for a key you know to be in the import file. If RegRead returns nothing or sets an error, you know it hasn't been imported, so the IF block then does the import. If you don't know the contents of the import file, use RegWrite to set another key saying the import has been done, and check for that at the beginning.

Link to comment
Share on other sites

... You could also write your own Registry key to store whether the files have been imported, if you do not wish to write INI files everywhere.

:)

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

As you can tell by the script below, something just isn't right and I can't figure out how to get this going!

Are you sure the directory scripts is already created?.

Try this:

#Include <File.au3>
$path = "c:\Scripts\"
If Not FileExists($path) Then DirCreate($path)

If FileExists($path & @UserName) Then
    MsgBox ( 0, '', 'Run program II' )
Else
    _FileCreate($path & @UserName)
    MsgBox ( 0, '', 'Import Registry' )
    MsgBox ( 0, '', 'Run Program' )
EndIf
Edited by sahsanu
Link to comment
Share on other sites

thank you everyone for the responses

The reason you don't see the import of the registry is because I was using MsgBox as a means to figure out how the script was running, so I would replace "Importing Registry" with Run ( 'cmd /c registry /s registryfile.reg', '', @SW_HIDE )

so this is the script I finally came up with to resolve my issue, I know it's probably not the cleanest script writing, it does solve my problem though..

#Include <File.au3>

AutoItSetOption ( 'TrayHideIcon', 1 )

If Not FileExists ( 'C:\Program Files\eInstructions\User\' & @UserName ) Then 
    _FileCreate ( 'C:\Progam Files\eInstruction\User\' & @UserName )
    RunWait ( 'cmd /c registry /s eInstruction.reg', '', @SW_HIDE )
    RunWait ( 'cmd /c copy /y WorkspaceGallery.iEW', '', @SW_HIDE )
EndIf

If FileExists ( 'C:\Program Files\eInstruction\User\' & @UserName ) Then
    Run ( 'C:\Program Files\eInstruction\Interwrite Workspace\IW.exe', '', @SW_SHOW )
EndIf

Exit

As you can see, this checks first to see if the user has already run the script by looking for a file @UserName

if the user hasn't run the script, it creates a file of their username

then imports the registry and another file required for the program for personal preferences

After running that part it again checks for a file matching the @UserName and then starts the Interwrite Workspace program (IW.exe)

I will use an install script to install the program (eInstruction Interwrite Workspace) and use the script to replace the shortcut icon on the desktop to actually point to the AutoIt script, the AutoIt script will then start the real executable (IW.exe) after checking for the users file, importing registry and personalized settings file.

When the user starts the program from then on, it skips creating the username file, importing registry and moving the personal preference file and just starts the desired program..

The actual script I have also shows the user the programs of the personal preferences being configured by using ProgressOn, ProgressSet, ProgressOff

Thank you again for everyone's help, this community is fantastic!

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