Hello There, Guest!
View New Posts  |  View Today's Posts
Win7 setup.exe launcher [C++]

  • 0 Vote(s) - 0 Average


05-15-2012, 02:09 AM #1
far.in.out
Junior Member
**
Posts: 9 Threads:1 Joined: Dec 2011 Reputation: 3

Question  Win7 setup.exe launcher [C++]
Hi. I've been working on some simple app that let's you launch Win7 setup.exe with command line parameters, for example to specify explicitly the image you want to use for an installation and/or an unattended file (including path and name of the file).

This app may be helpful in cases when you have lots of images and unattended files and/or when your files are not located in default location.
Also may help you if you are using a customized PE for deploying different images and get an error about missing storage drivers when in fact the problem is with the PE and image versions (editions) mismatch.

As I'm not really a programmer, for now I'm stuck at these two functions
- load parameters from .ini file (commented out, not finished)
- add WIM/XML paths and file names to CreateProcess() function

Both problems are a result of my poor knowledge of working with text in C++.
It's C++ native Win32 API. No .Net or MFC.

HERE IS THE SOURCE AND EXECUTABLE AND MSVC++ 2010 proj files
http://www.mediafire.com/?5w7q2c13f93xa
This post was last modified: 05-22-2012, 04:01 PM by far.in.out.

05-15-2012, 12:25 PM #2
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

RE: Win7 setup.exe launcher [C++]
I'd take a look. I don't program in C++ personally but I might be of some assistance.

05-21-2012, 01:12 AM #3
far.in.out
Junior Member
**
Posts: 9 Threads:1 Joined: Dec 2011 Reputation: 3

RE: Win7 setup.exe launcher [C++]
I uploaded the source code, link is in the first post...
Have you looked at it?

05-21-2012, 01:25 AM #4
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: Win7 setup.exe launcher [C++]
Code:
CreateProcessW(const_cast<LPCWSTR>(PATH_TO_EXE_HERE.c_str()),
                            pParam, 0, 0, false,
                            CREATE_DEFAULT_ERROR_MODE, 0, 0,
                            &siStartupInfo, &piProcessInfo)

pParam would be wchar_t pointer, but you need to allocate memory for that yourself, also CreateProcessW returns a bool value, regarding whether or not the CreateProcessW function was successfull or not... so you could check to make sure the function returned true or false as well to avoid any future conflictions if it encountered any problems.

If you're retrieving a list of applications to use CreateProcess with, then you'd need to parse that data out of the file and assign it to a variable to place in where PATH_TO_EXE_HERE is.

Can't give you a full example, I haven't opened C++ in a little while... CreateProcess is a pretty standard function though, and one which i've used before a while back (there's a few other similar ones/aliases which do somewhat the same thing too)

Edit: I would recommend this:
http://msdn.microsoft.com/en-us/library/aa908775.aspx

This is what helped me out initially...

Edit: Actually that wasn't the original page I had to look at, but this still helps out with the params...
This post was last modified: 05-21-2012, 01:29 AM by AceInfinity.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

05-21-2012, 02:11 AM #5
far.in.out
Junior Member
**
Posts: 9 Threads:1 Joined: Dec 2011 Reputation: 3

RE: Win7 setup.exe launcher [C++]
Well, not exactly.
My app first

- reads previously stored file paths from .ini (now it's commented out and not finished)
- sends those values from .ini to edit boxes and variables
- waits for user to input (browse for) files
- after each browse operation completion it dumps paths to .ini file
- and finally GO button launches the process

Application path is a constant - X:\sources\setup.exe

It's the command line parameters, the WIM and XML paths that a variable. These need to be added to lpCommandLine parameter so in the end it looks like this:

X:\sources\setup.exe /installfrom:WIM_PATH_VAR /unattend:XML_PATH_VAR

Also I use CreateProcess and not CreateProcessW.

05-21-2012, 05:47 AM #6
Shintaro
Member
**
Posts: 248 Threads:58 Joined: Jan 2012 Reputation: 8

RE: Win7 setup.exe launcher [C++]
What are you using to compile it with? Watcom? Borland?
Does it compile without errors/warnings?

Ace,
Why do you favor the unicode version of CreateProcess?? I have watched you posts, you usually don't suggest something without a reason.
This post was last modified: 05-21-2012, 05:54 AM by Shintaro.
Thoughts create realities.


To be old and wise,
You must first be young and stupid.

Try to live an ordinary life,
in a non-ordinary way.

05-21-2012, 06:56 AM #7
far.in.out
Junior Member
**
Posts: 9 Threads:1 Joined: Dec 2011 Reputation: 3

RE: Win7 setup.exe launcher [C++]
MS Visual Studio 2010. Yes it compiles OK as it is now.
I just don't know how to pass text from ini to a var of proper type and how to pass var to CreateProcess's parameter.

05-21-2012, 11:25 AM #8
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: Win7 setup.exe launcher [C++]
Quote:Also I use CreateProcess and not CreateProcessW.

There's no significant difference between these functions really.

Quote:Ace,
Why do you favor the unicode version of CreateProcess?? I have watched you posts, you usually don't suggest something without a reason.

It's really just more explicit. If you use CreateProcess it will automatically call CreateProcessW or CreateProcessA anyways, depending on your application.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

05-21-2012, 12:41 PM #9
far.in.out
Junior Member
**
Posts: 9 Threads:1 Joined: Dec 2011 Reputation: 3

RE: Win7 setup.exe launcher [C++]
So, can anyone provide a working solution at least for passing vars to CreateProcess function.
I think I understand now what needs to be done but I really just have no time...
Guess this will have to wait some more...

05-21-2012, 12:51 PM #10
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: Win7 setup.exe launcher [C++]
I showed you an example of CreateProcessW... Really CreateProcess is just a universalized version of the params for the more explicit version of the same function which i've posted. CreateProcess turns into CreateProcessW or CreateProcessA accordingly, therefore you don't have to convert it's parameters to the more exact types that are required if you go with CreateProcess.

cheers
This post was last modified: 05-21-2012, 12:51 PM by AceInfinity.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲




Forum Jump:



Users browsing this thread: 1 Guest(s)