Solved

writing an autorun.exe

Posted on 2001-06-21
9
267 Views
Last Modified: 2010-04-02
I have a setup.exe which i will run through autorun.inf.
But before running setup.exe i have to run one more exe which will check whether a specified file exists, if exists skip setup, otherwise installation should run.

Tell me in detail how do i check the file existence before running setup.exe.
0
Comment
Question by:Gopi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6214595
The easiest way to check the existance of a file is 'GetFileAttributes()':

if ( -1 == GetFileAttributes ( "drive:\\path\\file.ext"))
{
  // does not exist
}
else
{
  // does exist
}
0
 

Accepted Solution

by:
mkprasad earned 100 total points
ID: 6215859
[autorun]
OPEN=Check.exe

in Check.exe,

_finddata_t  _file;//defined in IO.H;
                   //Pls refer the documentation for more
                   //details
char filename[] =  "<Drive>:\\path\\file.ext";
if(_findfirst( filename, &_file ) == -1)
  return;          // do nothing
else
  CreateProcess(".\\Setup.exe");
0
 

Author Comment

by:Gopi
ID: 6217011
Thank u it serves my purpose.
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Expert Comment

by:mkprasad
ID: 6217188
Thank u Gopi.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6221193
I would strongly recommend you look at jkr's suggestion.    It will be faster and far simpler.

mkprasad's code is slower and causes a resource leak.  By the time you fix that leak it will be signficantly more complex again.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6222828
Does anyone know if this accepted answer was posted as a comment or as an answer?
0
 

Expert Comment

by:mkprasad
ID: 6223388
Yeah,
  i posted it as a comment.
and about the leak,
  u can write a simple function which takes care of every thing.

BOOL FileExists(const char * filename)
{
     struct _finddata_t _file;
     long hFile;

     if( (hFile = _findfirst( filename, &_file )) == -1L )
        return FALSE;
      _findclose( hFile );
      return  TRUE;

}
0
 
LVL 22

Expert Comment

by:nietod
ID: 6224208
You are missing the point.    GetFileAttributes is not only simpler and more direct, its likely to be 100s of times faster.  Yes, you can remove the bug in your code, but that only made it slower and more complex.

0
 

Author Comment

by:Gopi
ID: 6224354
but i want to run check.exe which checks for a particular file existence. This check has to be done with our opening cmd window. If u can give me the code for this it will be helpful
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question