Solved

writing an autorun.exe

Posted on 2001-06-21
9
260 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

739 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