开发者

Determine when my Application is run for the very first time

开发者 https://www.devze.com 2023-03-30 22:58 出处:网络
I have a Native WinApi C++ Application that finds media(.wmv, .mp3 etc.) files in a specified directory & creates random playlists. The first time the application is run(& only the first time)

I have a Native WinApi C++ Application that finds media(.wmv, .mp3 etc.) files in a specified directory & creates random playlists. The first time the application is run(& only the first time) I want to prompt the user to specify a 'home' directory that the Application will always check for media files & create a playlist from.

My Problem: I dont know of a way how I could determine when the Application is run for the 1st time?

开发者_JAVA百科

Is there a standard way, maybe a Win32 function that I can use to detect when the Application is run for the 1st time?

Some ideas I have come up with are: (but they seem like hacks or overkill(installer idea))

  • The application .exe is 322kb(which is tiny & doesn't require an installer right?) in size so I could create an installer (I was thinking if someone is installing the application then I know its the first run & I can prompt them then).
  • I could have a text file(or xml) called appData.txt & have the 1st line where I store the home path directory. So "home_path=undefined", on application run, I look in the text file, if the home_path == undefined then I prompt them to specify a home path if its not undefined then I read that directory for media files.

Any ideas of how I can determine when my Application is run for the very first time?


In the installer you could create a registry value for your program.

Then when you start your program, check the registry value.
When you run the program for the first time update that value to so you know it's been run already.


I would use the text file because you are going to have to store the user's directory somewhere anyway, might as well use it for first run detection as well. It has the added bonus that if the file is deleted, you will know that you have to prompt the user again since you no longer know what their home directory is.


You can set some registry value when your App runs for first time and check it on every run. If it is already set then App was already run. If not - set it.


Create a log file on first run. If it exists, then it's not the first time.

try
{
  // open log.txt
  // do second time run logic here
}
catch(file does not exist)
{
  // create log.txt
  // first run logic here
}
0

精彩评论

暂无评论...
验证码 换一张
取 消