Solved

writing an autorun.exe

Posted on 2001-06-21
9
224 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

760 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

21 Experts available now in Live!

Get 1:1 Help Now