Link to home
Start Free TrialLog in
Avatar of Gopi
Gopi

asked on

writing an autorun.exe

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.
Avatar of jkr
jkr
Flag of Germany image

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
}
ASKER CERTIFIED SOLUTION
Avatar of mkprasad
mkprasad

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gopi
Gopi

ASKER

Thank u it serves my purpose.
Thank u Gopi.
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.
Does anyone know if this accepted answer was posted as a comment or as an answer?
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;

}
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.

Avatar of Gopi

ASKER

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