Link to home
Start Free TrialLog in
Avatar of NBee
NBee

asked on

Run before Windows

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
Avatar of mnashadka
mnashadka

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.
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

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
listening...
Sorry about that.
Avatar of DanRollins
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
>> 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.
surley MoveFile will not work before 'windows starts' ?, as this is a windows API call
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.
Avatar of NBee

ASKER

nietod, you said on WIndows 9x, we must modify the registry entry. So what is it and how?
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.
Avatar of NBee

ASKER

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
Avatar of NBee

ASKER

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.
In win2k you can use MoveFileEx().  I know that it works.

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

ASKER

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.
Check the return values.

It is possible that you don't have sufficient access rights.
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.

https://www.experts-exchange.com/jsp/qShow.jsp?qid=11516478
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11529339
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11585158
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11697479
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11744478
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11766758
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11818478
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11905339
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11938458
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20003831
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20038010
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20127372
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20135883
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20136023
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20142078
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20142830
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20143154
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20144259
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20144370
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20148973
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20150132
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20153238
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20160626
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20162000
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163157
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163178
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163242
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163142
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163674
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20165141
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20174284
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20184042
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20242564
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20242585
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20252565
https://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
Admin notified of user neglect. Force/accepted by

Netminder
Community Support Moderator
Experts Exchange