Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Update exe, I need some clue

Hello guys.

I don't have any ideia how to start this task.

I need to create a function that read a .ini and gets the version update of my program. There will be a .ini in client computer and other in the netware, my program will read the .ini in the netware and will compare with its .ini in client, if the version is less than netware .ini, the program will run another application to update the exe.

I think the steps should be like this:

1) the program read the netware .ini
2) the program compares with .ini in client
3) the program run another application and the other application wait until the program finishes to start the update.
4) after the main program closes, the update program copies the program

is there any example of this? how could I start this?
0
hidrau
Asked:
hidrau
  • 2
3 Solutions
 
TheRealLokiSenior DeveloperCommented:
There are many ways to do this.
I will just demonstarate how to  upgrade your application with a later version on your network by using a batch file (that your application creates as needed)

put the new version in \\SOMESERVER\SOMESHARE\MyUpdateDir\


procedure TForm1.RunUpgrade;
    const
        upgradefilename = 'C:\temp\~upgrade.bat';
    var
        TextF: TextFile;
        drv: string;
       
        StartupInfo: TStartupInfo;
        ProcessInfo: TProcessInformation;
    begin
// #Note - check for authentication to server
        if FileExists('\\SOMESERVER\SOMESHARE\MyUpdateDir\' + ExtractFilename(Paramstr(0))) then
        begin
// create a temp directory to put the "batch file" that does the actual upgrading
            ForceDirectories('c:\Temp\');
            assignfile(TextF, UpgradeFilename);
            rewrite(TextF);
            writeln(TextF, '@echo off');
            writeln(TextF, 'mode con: lines=1');
            writeln(TextF, 'Title Upgrading This Program...');
//sleep.exe is partof the windows resource kit. it allows you to wait for "x" seconds.
// wait for 2 seconds for this application to close before trying to upgrade it
            writeln(TextF, 'sleep 2');
            writeln(TextF, 'echo y| copy "\\SOMESERVER\SOMESHARE\MyUpdateDir\' + ExtractFilename(Paramstr(0)) + '" "' +
            Paramstr(0) + '"');
//work out if we are installed in C:, D: or something else
            drv := Paramstr(0);
            if pos(':', drv) = 2 then
            begin
//change to the program directory and run the "now upgraded" application
                writeln(TextF, copy(drv, 1, 2));
                writeln(TextF, 'cd "' + ExtractFilePath(Paramstr(0)) + '"');
                writeln(TextF, 'start ' + ExtractFileName(Paramstr(0)));
            end
            else
            begin
                writeln(TextF, '"' + Paramstr(0) + '"');
            end;
            closefile(TextF);
//            WinExec(UpgradeFilename, sw_Hide);
            sleep(2000);
            if FileExists(UpgradeFilename) then
            begin
// now run our upgrade batch file
                fillChar( startupInfo, sizeof( startupInfo ), 0 );
                StartupInfo.cb := sizeof( startupInfo );
                StartupInfo.wShowWindow := SW_SHOWMINIMIZED;
                CreateProcess(nil, UpgradeFilename, nil, nil, False, 0, nil, 'c:\temp', StartupInfo, ProcessInfo);
                if ProcessInfo.hProcess <> 0 then
                  CloseHandle(ProcessInfo.hProcess);
                if ProcessInfo.hThread <> 0 then
                  CloseHandle(ProcessInfo.hThread);
            end;
//now close this application quickly so the upgrade will be able to upgrade
            Close;
        end
        else
          MessageDlg('A new version is required'+#13+#10+'please update manually'+#13+#10+'\\SOMESERVER\SOMESHARE\MyUpdateDir\' + ExtractFilename(Paramstr(0)), mtWarning, [mbAbort], 0);
0
 
newnobCommented:
You can use a component AutoUpgrader_v4.11_For_Delphi. It's a full solution for  Update.
It has a complete source code.
0
 
TheRealLokiSenior DeveloperCommented:
oh, btw, to compare the "version" (which you say is stored in an ini file) with the version on a server in the network, you could do the following

uses inifiles;


procedure TForm1.CheckIfUpgradeNeeded;
var
    thisver: integer // assuming version is a whole number, e.g. 1, 2, 3, 4 etc...
    serverver: integer;
begin
// assume ini is project1.ini ("current filename".ini)
    with TIniFile.create(ChangeFileExt(Paramstr(0), '.ini')) do  
    try
        thisver := ReadInteger('Settings', 'Version', 0);
    finally
        free;
    end;

    with TIniFile.create('\\SOMESERVER\SOMESHARE\MyUpdateDir\Version.ini') do  
    try
        serverver := ReadInteger('Settings', 'Version', 0);
    finally
        free;
    end;
// if we are a lower version than what is on the server, run the upgrade
    If (thisver < serverver) then
        RunUpgrade;
end;
0
 
hidrauAuthor Commented:
thanks
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now