I have created a small game in C#. The players' location is saved into an external text file called:
GAME_FILE.txt
This file is located in the same folder as the main EXE.
The game loads fine but when the player moves from Location 1 to Location 2, it then writes that to the text file. But as soon as it writes it, Norton Antivirus flags up the following message:
Suspicious process attempted to open a file protected by Data Protector
Target: GAME_FILE.txt
Now, I need to try and fix this because I want to share my game with others and don't want to worry about antivirus warnings appearing on other users PC's.
The code I am using to write to the file, is as follows:
File.WriteAllLines(Application.StartupPath + "/" + "GAME_FILE.txt", PlayerLocation);
(where PlayerLocation is a string representing the players' location in the game).
Now, this works fine when run inside Visual Studio, but flags up the warning when trying to play the game via the EXE file.
Any help here would be much appreciated, as I want to be able to share my game with others.
Try to make sure you are writing in 'safe' paths. Try to write in public documents or temporary folders.
Also, take a look on this thread.
My C# app is getting flagged by anti-virus apps. How do I figure out why?
Related
I have a small problem that it took me sometime to found out what should i do.
The scenario goes like this.
I created a software that I already burn to a dvd-rw and installed an autorun to it.
When my software run. It will copy all files from that dvd and will paste it to the user designated drive. But I inserted a Flexible variable to some sort of textfile.
After the copying is complete. The next step of my software is to find all the Flexible variable and change it to its final output. for example the flexible varialble is <##COMPUTER_NAME> then my software will change it to its final data. But when i do it. my system in dvd-rw says access denied.
I also tried it in my Flash Drive and it works fine. But when i tried it in DVD it says access denied.
What should i do?
P.S. my system always running as administator.
Ok I found out that my problem is the dvd-r. Because it is nature that whenever you burn a file to it, the file will become read only always. So when my system try to write the specific file after copying it says denied due to the attribute of the file.
So I made a small changes in my installer.
I added to my code the function
Checking and changing the attribute of specific file
before executing the second command.
That's all and it work again perfectly. attribute is the key.
EDIT: I'm new to c#, I'm completely lost on this.
I have a program that is supposed to start every time windows starts up. I have it set it up so when you click a check box, it writes / deletes a regedit, code:
private void SetStartUp()
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (LaunchCheckBox.Checked)
{
rk.SetValue("SystemStartupProgram", (defaultDirectory + "\\SystemStartupProgram.exe"));
}
else
{
rk.DeleteValue("SystemStartupProgram", false);
}
}
Where "defaultDirectory" is a custom set path. It's set up to be the directory in which the program itself is in, for example "c:\MyProgram\bin\Debug". The .exe file for this program is located in there.
This code works as far as I can tell, since if I go to task manager's start up section, it shows my program, it's location, and it's state, which is enabled. However, the program doesn't run on system start up.
I have a hunch it might be something to do with a .txt file my application uses. The file is located in the same directory. If I remove the .txt file and run my program manually, it tries to launch it but nothing happens. Maybe the windows start up doesn't find the .txt file, and thus can't start it? Is there any way around that?
EDIT 2: The program is a Windows Forms application. When run, it opens up a form. However, it doesn't show up when windows starts.
EDIT 3: Problem fixed, see answer below for details
After a long bug hunt, I found what the reason was. It was indeed what I suspected, when the program starts it tries to look for the .txt file located in the same directory as my .exe. Turns out when you start a program upon system startup, the directory it looks from is something like "Microsoft\windows32", which is not where my file is located at.
I set my program's directory to it's own folder (my case: bin\debug) whenever the program starts, and only then try to read the file.
The bug being fixed, I'm still going to make a windows service application version of it, since that seems to be the correct way to do things from what I managed to google. Thanks to everyone who helped :)
We have an app we wrote deployed onto our terminal servers at work, and keeping it up-to-date is a bit of a pain.
What update mechanisms do people use for app on terminal servers? At the moment we manually copy the new exe + dependencies on witch is just rubbish.
I'm a bit concerned about files being locked by users when trying to update, i cant really just kill the process in case someone is in the middle of doing something. We would like to be able to handle the odd fat client update as well.
Ideally we'd plug something into teamcity/octopus but are open to suggestions
Create a script that copies the exe file to a user specific temp folder, then launches the copied exe. To make the script more efficient, you can have it check the dates of the files. If they are different, then you copy the file over the old one located in the temp folder, else you just launch it.
I am relatively new to C#, however I do have some basic knowledge of code from courses in high school and university. However, there is one thing I have not been able to figure out over the years. I am currently making a Form Application for a database system that stores information in a List using Visual Studios 2010.
On my main form; when the save button is pressed, the information is then serialized into an XML file. When the information is loaded, the information is then deserialized and put into the List for use in the code. All this is working correctly.
This process of saving and loading is done based on a string which contains the file path. This string is the location of a folder on my desktop (I put it there for easy access), and I am able to change the string in the code to basically move where the information is stored.
However, I have a separate "Admin" form which is able to change this file path string. When the user clicks the button to change the file path, I get the input from a text box, check its formatting, move the current file to the new location and update the location for the save method so changes can be saved before the program is closed. From there, the program reacts the same way as if I had changed the string from inside the code.
The problem occurs when I close the program. I do not know how to tell the program when it runs again that the location has been changed from the default and look for the file in the new location. The program reacts just like the file was missing (like it should) when it looks in the default location.
So basically, how do I tell the program that the save location was changed from when it was last run so it knows to load the info from a new location?
I have tried looking for an answer since high school (about 2 years ago) and have not found a solution. As a result I usually just keep the save location as the default (which I set it to) and don't try to change it. But this time, its important that the save location can be customized. My experience with Visual Studios is limited, as everything I know is from messing around with the program and looking up stuff when needed.
If needed, I can post snippets of my code. Thank you in advance!
It seems like what you really want is to save some user-defined settings for recall at run-time. Here is a MSDN link describing some basic conventions for storing / retrieving these settings.
https://msdn.microsoft.com/en-us/library/bb397750(v=vs.110).aspx
A *.config file would suffice (depending on the scale of the application).
Otherwise, you may want to go down the route of storing these settings in a database (if the scale is rather large, or if user-authentication is required for the application).
Here is another previous question dealing with this same subject (regarding App.config files):
What is App.config in C#.NET? How to use it?
I recommend using a config file where the .exe is, and write the location there, then read it in on program startup.
In particular .net provides this class which can manage your config file for you (assuming you have an app.config in your solution, otherwise create one)
https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings(v=vs.110).aspx
I'm very new to Visual Studio 2010. I decided to create a simple WFA with C#.
Everything work fine with Images and Audio playback. My intention is to create a standalone application and send it to my friend as a gift. Problem I facing now is that when I tried to publish the application, the Images / Audio is still using the same location in my PC. So it won't play nor display any images.
Any comment on this or guide for me? I did try search for solution but doesn't seems to have any luck.
This is the code that I used to play Audio :
SoundPlayer ply = new SoundPlayer(#"C:\Users\Liam619\Documents\Visual Studio 2010\Projects\BirthdayApp\BirthdayApp\Resources\BirthdaySong.wav");
If I remove or change the path, the Application will hit error for locating the Audio file.
There may be several solutions to your problem.
a) embed the sound into a resource. As a beginner, resources may be a bit tricky to get it right the first time. But I want to encourage you reading something about it. You'll need resources when you want to translate your first program.
b) create an installer which copies the sound file to the installation directory. Try InnoSetup. If you're a programmer, sooner or later, you'll need to create a Setup anyway. Always worth knowing how to do that.
In that case, you still need the path to the sound file, but if you install your EXE into the same path as the sound file, see getting the application's executable directory.
everything in the database whether images or audio refers to your own server database.you have to send the database too with the app and the correct version .NET framework needs to be installed on the target PC.