Solved

writing an autorun.exe

Posted on 2001-06-21
9
234 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
  • 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
 

Expert Comment

by:mkprasad
ID: 6217188
Thank u Gopi.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now