Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Calling an .exe file and suspending the program which called it

another_paulanother_paul Member Posts: 2
Hi,

I'm very new to Windows programming (I've done a little VC++ debugging, but not written anything from scratch - most of my experience is Pascal), so please bear with me.

I'm trying to write a progam which detects the operation system version and then installs a series of microsoft patches (different ones depending on the OS).

Detecting the OS is fine and I can call external .exe programs (so far, just notepad) using CreateProcess(). The problem is that the I don't seem to be able to cause the make my program go into the background while the microsoft patch is running (the term modal comes to mind but this might be something unrelated).

Could someone point me in the right direction? Alternatively, comments along the lines of "Why on Earth would you want to do it using VC++? XXX would be much easier" would be helpful.

BTW, does anyone know if there are restrictions on redistributing (unmodified) microsoft patches?

Kind regards,
Paul

Comments

  • pingpongpingpong Member Posts: 937
    Paul,

    : I'm very new to Windows programming (I've done a little VC++ debugging, but not written anything from scratch - most of my experience is Pascal), so please bear with me.
    :

    Welcome aboard!

    : I'm trying to write a progam which detects the operation system version and then installs a series of microsoft patches (different ones depending on the OS).
    :
    : Detecting the OS is fine and I can call external .exe programs (so far, just notepad) using CreateProcess(). The problem is that the I don't seem to be able to cause the make my program go into the background while the microsoft patch is running (the term modal comes to mind but this might be something unrelated).
    :

    First off, you can stop your program with code like this:
    [code]
    PROCESS_INFORMATION pi;
    CreateProcess(..., &pi);

    // halt till that process is no more
    WaitForSingleObject(pi.hProcess, INFINITE);
    [/code]
    Now, I had the same problem you are talking about when writing my setup scripts with InstallShield, a mixture of the above and putting flags in the registry solved it for me. It all depends on your exact procedure, we had tons of cases to worry about (what if the script we are waiting for is trying to reboot?, etc).

    : Could someone point me in the right direction? Alternatively, comments along the lines of "Why on Earth would you want to do it using VC++? XXX would be much easier" would be helpful.

    Any of the setup creators (InstallShield, Wise, etc) lets you low level modify the scripts. You can access API's, read/write the registry. Do whatever you want, the above problem (waiting till some process is done) is a flag to the ShellExecute API in InstallShield (or whatever its called, cant remember the exact name, and I'm sure Wise has the same functionality).

    :
    : BTW, does anyone know if there are restrictions on redistributing (unmodified) microsoft patches?
    :

    Can't help there.

    Best of luck.
  • another_paulanother_paul Member Posts: 2
    : : Detecting the OS is fine and I can call external .exe programs (so far, just notepad) using CreateProcess(). The problem is that the I don't seem to be able to cause the make my program go into the background while the microsoft patch is running (the term modal comes to mind but this might be something unrelated).
    : :
    :
    : First off, you can stop your program with code like this:
    : [code]
    : PROCESS_INFORMATION pi;
    : CreateProcess(..., &pi);
    :
    : // halt till that process is no more
    : WaitForSingleObject(pi.hProcess, INFINITE);
    : [/code]

    Yep. That worked. Thanks. How do you find these commands? I've tried looking on MSDN but, as is generally the case with programming, you need to have to know the name of the command before you can find it.

    : Now, I had the same problem you are talking about when writing my setup scripts with InstallShield, a mixture of the above and putting flags in the registry solved it for me. It all depends on your exact procedure, we had tons of cases to worry about (what if the script we are waiting for is trying to reboot?, etc).
    :

    Hmm. I hadn't considered reboots. It's possible that all the patches are .msi files, so I might be able to postpone the reboots til the end. Otherwise things are likely to get complicated. :(

    : : Could someone point me in the right direction? Alternatively, comments along the lines of "Why on Earth would you want to do it using VC++? XXX would be much easier" would be helpful.
    :
    : Any of the setup creators (InstallShield, Wise, etc) lets you low level modify the scripts. You can access API's, read/write the registry. Do whatever you want, the above problem (waiting till some process is done) is a flag to the ShellExecute API in InstallShield (or whatever its called, cant remember the exact name, and I'm sure Wise has the same functionality).
    :

    I guess I should really be using InstallShield or something similar, but they seemed rather expensive when I looked at them.

    Cheers

    Paul
  • pingpongpingpong Member Posts: 937
    : Yep. That worked. Thanks. How do you find these commands? I've tried looking on MSDN but, as is generally the case with programming, you need to have to know the name of the command before you can find it.

    I've used it a few times. MSDN that comes on CD's or DVD(the online one is too slow) is a very good source of information about anything Windows related. Highly recommmend you get a copy if you want to do Win32 programming. Searching MSDN is not an easy task, but in time, you'd know how to get the information you want quickly, dont know what the magic trick is... But you will get a hang of it in no time.

    :
    : Hmm. I hadn't considered reboots. It's possible that all the patches are .msi files, so I might be able to postpone the reboots til the end. Otherwise things are likely to get complicated. :(

    Good luck! The reboot business drove me crazy, I solved it by constantly putting my setup EXE's in the RunOnce or Run keys in the registry, keeping state information in a private key over there as well.

    :
    : I guess I should really be using InstallShield or something similar, but they seemed rather expensive when I looked at them.
    :

    InstallShield (we use ver. 6 over here) is perfect for straight installations, hardly ever need to use the built-in script language and can probably do it all through the wizards. But, it has a few problems of its own, mainly, you can only run one instance of an InstallShield created setup program at one time. So for a more complicated setup routine that involves setups spawning setups you could face some major headaches. From a couple of hours testing with their newest, InstallShield Developer 7, it seems the problem still exists. I havent had the time to mess around with Wise, but their tech support guy told me they dont have that problem. Bottom line, if you are to go and get InstallShield or Wise, better off downloading the evalutations first and messing around with them for a few days.

  • Andre YoungAndre Young USAMember Posts: 0

    _ < http://forcoder.org /> free video tutorials and ebooks about ( Ruby PHP PL/SQL C++ C Java Go R Scratch JavaScript Visual Basic .NET Objective-C Swift Delphi MATLAB C# Perl Assembly Python Visual Basic Lua Bash LabVIEW Dart Prolog VBScript Clojure FoxPro Logo Kotlin Transact-SQL Erlang Crystal COBOL Julia D Fortran F# Apex Scheme Ada Lisp SAS Hack Alice Rust Awk Scala ML ABAP ) ____

Sign In or Register to comment.