Solved

Run before Windows

Posted on 2001-08-04
17
220 Views
Last Modified: 2007-12-19
Hi,
I want to write a Visual C program that can run before Windows starts. That means, when you start your computer, before Windows starts, I want my program to start and change some configurations and delete some temp files (that will be locked by Windows)

Any ideas???

Regards
0
Comment
Question by:NBee
[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
  • 6
  • 4
  • 2
  • +4
17 Comments
 
LVL 8

Expert Comment

by:mnashadka
ID: 6351233
I think that what you really want to do is to use the MoveFile command with the MOVEFILE_DELAY_UNTIL_REBOOT flag set:
MoveFile(old_file, new_file, MOVEFILE_DELAY_UNTIL_REBOOT);

This will allow the copy to be done when the computer restarts the next time, so the files don't get locked.  Hope this helps.
0
 
LVL 22

Accepted Solution

by:
nietod earned 20 total points
ID: 6351327
Note that the flags like MOVEFIE_DELAY_UNTIL_REBOOT flag is only for MoveFilEx(), not MoveFile().   Also note that this flag only works on NT 4.0 and 2k.  Windows 95 and 98 force you to do this through a registery entry.
0
 
LVL 1

Expert Comment

by:kuchnaheen
ID: 6351328
listening...
0
Technology Partners: 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!

 
LVL 8

Expert Comment

by:mnashadka
ID: 6351362
Sorry about that.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6352446
I believe that commands in AUTOEXEC.BAT will execute before Windows starts.  

I recommend against doing anything in AUTOEXEC.BAT for any kind of release software, but for your own computer (or any easily maintainable on-site set of computers), it is a reasonable solution.

-- Dan
0
 
LVL 22

Expert Comment

by:nietod
ID: 6352497
>> I believe that commands in
>> AUTOEXEC.BAT will execute
>> before Windows starts.
Before the "windows" part of windows. that is, before the GUI stuff.  its Autoexec.nt in NT and win 2k though.
0
 
LVL 10

Expert Comment

by:makerp
ID: 6352824
surley MoveFile will not work before 'windows starts' ?, as this is a windows API call
0
 
LVL 22

Expert Comment

by:nietod
ID: 6352911
It works before most of windows has started.  it can be used to copy over (update) or delete most of the windows files.  The function itself, the API call works when windows is fully running.  But it does nothing at that time (if you specifu the delay until reboot flag)  It just records what needs to be done, then the actions are taken when the machine is rebooted during the early stages of windows startup.
0
 

Author Comment

by:NBee
ID: 6354386
nietod, you said on WIndows 9x, we must modify the registry entry. So what is it and how?
0
 
LVL 22

Expert Comment

by:nietod
ID: 6354397
The details are documented with MoveFileEx() function in the VC help.

I was wrong however, it is not a registry entry, its an entry in the wininit.ini file.
0
 

Author Comment

by:NBee
ID: 6354500
So, if i use the solution: edit wininit.ini, then can this be done on Windows 2000???

i want a single solution for many OS.

Thanks
0
 

Author Comment

by:NBee
ID: 6354653
Heys, it doesn't work on Windows 2000 Profressional.
I have a Explorer.exe of my own. I want to replace Windows 2000 explorer.exe with the solution of MoveFileEx("C:\\Explorer.exe","C:\\Winnt\\Explorer.exe",MOVEFILE_DELAY_UNTIL_REBOOT | MOVEFILE_REPLACE_EXISTING )

And it doesn't work any at all.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6355333
In win2k you can use MoveFileEx().  I know that it works.

What does MoveFileEx() return?
If it returns 0 (false) what does GetLastError() return?
0
 

Author Comment

by:NBee
ID: 6362354
I didn't check what MoveFileEx() returned, but I checked in registry and found that key PendingFileRenameOperations had been created.
I restarted win2k but nothing has happened.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6363599
Check the return values.

It is possible that you don't have sufficient access rights.
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6764282
NBee,

The following questions are open, and have been open for some time. Further, your profile indicates you logged in as recently as Jan 29, 2002. Please resolve them within the next seven (7) days; following that period of time, I or one of the other Moderators will take action to close this question. Additionally, this list has been forwarded to Administration; please expect an email from them regarding your account's status.

http://www.experts-exchange.com/jsp/qShow.jsp?qid=11516478
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11529339
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11585158
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11697479
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11744478
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11766758
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11818478
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11905339
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11938458
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20003831
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20038010
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20127372
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20135883
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20136023
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20142078
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20142830
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20143154
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20144259
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20144370
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20148973
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20150132
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20153238
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20160626
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20162000
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20163157
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20163178
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20163242
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20163142
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20163674
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20165141
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20174284
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20184042
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20242564
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20242585
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20252565
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20259368

Further, you should note that the guidelines for questions suggest that an "Easy" question is worth 50 points.

Thank you for your attention to the above questions.

Netminder
Community Support Moderator
Experts Exchange
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6804104
Admin notified of user neglect. Force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.
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.

724 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