Issue restarting a Windows service - c#

Hi I made some changes in a windows service coding side(some class files related to that),,means i did coding to fetch version value from registry in that class files,,,,After

Your OnStart method is most probably hanging. Did you recently add any of that threading/timer code.
Is your tracer logging any information?
Can you write some debug code to log where you are getting to and what exceptions are being thrown?

So it looks like OnStart is throwing an exception (in SpoER.Init()?, and it has permissions problem as well), this is causing the service to try and stop straight away.
I would suggest following the exception information you have given to try and locate the problem. It would be even better to move the bulk of this code into a separate class so you can write a console app which shares the same code as the service. By using the console app you can easily debug it.

Now i got the mistake,,What actually i was doing is i am copying DLL created in the debug mode and copying into the Installer path..Actually what i need is i have to copy DLL obtained from the release mode and copy into the installer side

Related

Looking to launch a local exe on a remote machine without having the resurces on the remote machine

So I have built some code, it's quite simple basically it stops all active input from keyboard and mouse until a text file of a certain name appears in the C:\Temp directory. It also has a manifest file to run it as administrator on start up.
So I found something that on the surface looks like it fulfils my needs of being able to do this task however upon running it I found out that the project has been compiled in x86 and does not run on my x64 machine. Here is the reference to the project if anyone would like to look into it, it's a very smartly designed piece of code that does an interesting objective. It also explains clearly enough what I am trying to accomplish.
So after implementing this (and failing) I have setup a couple other avenues to try, one is VBA through excel with the VBA copying itself to and from the machines in a list and running itself, then there is using VBS to write the entire code as a txt file on the target machine change the extension and then execute it remotely. I have just started researching these but I imagine the problems of running as an administrator amongst other things will crop up again to be dealt with. To be honest though I would really prefer to do this in C# only as that is the language I'm trying to go further in so I'm interested in this challenge. If anybody knows of a similar library of code or application I could look into to achieve what I'm trying I would appreciate being pointed in the right direction.
I would try and be more specific about what libraires/API's im trying to implement but the truth is I don't know what libraries I need to even interact with to get what I want. My goal is to have C# executable code on my machine and a tool that can run that executable on another machine.
Thanks
Thanks to the help in comments from #Nick.McDermaid I was able to correctly open and build the project I was trying to download. Unsure what caused the issue previously with me not being able to open and interact with the code but now I have it I shall pursue this avenue further to accomplish my goal.
As an addendum one other avenue I tried for executing code remotely was through VBS where I used
set svcproc=getobject("winmgmts:{impersonationLevel=impersonate}!\\"&MachineName & "\root\cimv2:win32_process")
scmd="""C:\Program Files\Internet Explorer\iexplore.exe"" -framemerging ""https://gifyu.com/images/Boo-Ghost-Gif.gif"""
'scmd="C:\Windows\notepad.exe"
iret=svcproc.create(scmd,null,null,pid)
set svcproc=nothing
to execute something that existed on the remote machine but I ran into a LOT of security policy issues where I could launch the process but I couldn't bring it to the foreground as the Malware tracker on the machine thought it was an attack and quashed it immediately.

Running a C# FileSystemWatcher Service forever

I've developed a service that watches one directory and then if a file is created or changed it will spin up another small c# script that will determine what to do with that file. I need this to be constantly listening to the directory at all times(even on start up of the server) because a file could be generated in this directory at literally any time.
I've searched and tried a few things but each time. The service will run then a file will be generated...then it launches the other C# script and does what it needs to with that file and then the service stops. So next time something happens in that directory nothing happens. Is there something I'm missing? How would I go about doing this?
So, your C# service will be stopped working after the first time that it runs your C# script?
I think it should related to your service configuration.
Checkout these links to see how you should create a service through C# :
http://www.codeproject.com/Articles/3938/Creating-a-C-Service-Step-by-Step-Lesson-I
http://www.codeproject.com/Articles/106742/Creating-a-simple-Windows-Service
http://www.codeproject.com/Articles/400697/WCF-Service-Creation-With-Csharp
I hope it helps you to find your mistake.
(If there's sth else, tell in comment)

Windows Phone 8 UnauthorizedAccessException when opening file

I am having a very strange error when trying to access a ".stl" file in the "Stl" folder of my application when the app is downloaded from the Windows Phone Marketplace. It does not exhibit this behavior when it is launched from Visual Studio 2012 Express in either debug or release mode. Once I try loading a file it gives me an "System.UnauthorizedAccessException Access to path 'C:\Data\Programs\APPUID\Install\Stl\test.stl' is denied" exception while accessing a ".gcode" file in an almost exactly the same fashion from the "GCode" causes no error what so ever.
I have no idea what could be causing this or how to debug this because I don't know if I can somehow attach the debugger to an instance of the store downloaded app.
I also have no idea what could possibly be different between deploying the exact same app from the store and from Visual Studio. The Visual Studio installed app also does not give any troubles if the app is launched from the phone without the debugger being attached.
Any ideas?
PS. The file is being opened by a filestream which is then used by a binarreader. I am not sure if the source code is really needed and for which part but the important line is just:
FileStream fileStream = new FileStream(filePath, FileMode.Open);
Where "filePath" in this case is "Stl\test.stl".
Without seeing your actual code it is hard to say what the problem is. So instead of attempting to read your mind I will offer an alternative solution.
I have worked extensively with Isolated Storage on the Windows Phone and I have learned this.
There is no library, no API, no SDK, no Web service, in the world, that has worse error reporting than the Isolated Storage on windows phone.
EVERYTHING is Invalid Access or Unauthorized Access with ZERO further information.
To remedy this I created a DLL that serializes objects to the Isolated Storage for you.
All you have to do is put [DataContractAttribute] above your class name and [DataMemeber] above any variable you want saved. Then you just pass your object and unique name into the savefile method. That's it! Instant save
You can find my free DLL EZ_Iso.dll for download here. With example code and instructions
The code is open source so if you wish you may also decompile the dll and see how it all works.
Feel free to reach out to me here or on twitter if you have any questions or enhancements.
Ok I figured it out. The "install" directory is actually restricted access but for some reason the Visual Studio signing process leaves the app with enough permissions to access this folder. The correct procedure of determining a relative directory is not to use "Directory.GetCurrentDirectory()" but rather to use "ApplicationData.Current.LocalFolder". Hope this helps!

windows phone 8, applicationsettings not persisted

I have the following strange behaviour in my Windows phone 8, C# App.
I am saving a Setting with:
private void SaveProperty<T>(T property, string propertyName)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains(propertyName))
IsolatedStorageSettings.ApplicationSettings[propertyName] = property;
else
IsolatedStorageSettings.ApplicationSettings.Add(propertyName, property);
IsolatedStorageSettings.ApplicationSettings.Save();
}
When the app runs, I can read all settings I stored in IsolatedStorageSettings.ApplicationSettings.
But when I re-open my app (open it from the app list), the IsolatedStorageSettings.ApplicationSettings-Dictionary contains Zero (0) Keys and Values.
Am I missing something?
I used the ISETool.exe to take snapshots of the IsolatedStorage of my app (thanks to chepene).
I saw this behaviour: when I wrote the Settings (that means after the SaveProperty<T>() function finished), and the app is still running, I have the Settings saved in _ApplicationSettings. This agrees with my Observation that I can read from the IsolatedStorageSettings.ApplicationSettings when the app is running.
The _ApplicationSettings-file also exists when the is tombstoned or not running (when I can Access it by Holding the back-button of the phone and when the app is closed with the back-button).
But when the app is opened again (via the app list), the _ApplicationSettings-file is gone...
I also see that, when I'm writing a file into the IsolatedStorage with:
SharedStorageAccessManager.CopySharedFileAsync(
Windows.Storage.ApplicationData.Current.LocalFolder, fileName+"orig",
Windows.Storage.NameCollisionOption.ReplaceExisting, fileID);
and when I then don't read this file, it is gone when I open the app the next time.
By the way, to avoid confusion: I am not reinstalling the app each time I open it.
If you need more Information please ask.
Any help appreciated.
With AppSettings, I've seen something similar on WP7/7.5, but it happened only when my property-value's type was a class that was not known to the serializer.
Are you sure that there were no exceptions:
during Save
during App Exit (since the App may dump the settings at that point)
during the time that App loads the settings for the first time after launch?
Note that this doesn't necessarily must mean the app crashing. I mean, any exceptions, those internally silenced or user-handled too. Please check the VisualStudio's Output panel for "first chance exceptions" log. If any I/O or security or serialization exception shows up, then investigate there. If i remember well, there's even a whole set of isolated-storage exceptions that are easily interceptable from debug/exceptions menu.
However, the issues I had with unknown or nonserializable types does not explain at all why your extra non-appsettings files would evaporate.
Another thought: maybe some additional tool performs something like 'clean deploy' for you? I don't remember exactly, but I think that VisualStudio's deployment cycle was quite plain:
rebuild
remove/uninstall old app from device -- so probably purges isolatedstorage
install new app onto device
So, maybe that's the cause? Hm.. on afterthought and re-reading your question again, you've said about running the app from the applist, so that rather is not the case. Be sure to check firstchance exceptions then!
Thanks to quetzalcoatl I found the solution:
I am storing all my files in the root Folder of my app. At the start I am then reading all my files (via a DataContractSerializer) and casting it to my model. Since it happens sometimes that my files get corrupt, I delete every file which throws a SerialzationException. But as I read every file, and since _ApplicationSettings is not castable to my model, I am deleting _ApplicationSettings automatically.... So I learned that the ApplicationSettings are,just a file in the root folder, which I am allowed to read and delete. So the quintessence is to never write into the root Folder.

How to do debug output in Azure roles code?

Suppose I write a console C# application - I can just use Console.WriteLine() to print whatever status messages and they can be read when the program is started in the console.
Now I have a Windows Azure role that runs somewhere in the cloud so that there's no console anymore. How do I do debug output to spot role current state and debug problems using debug output easily?
Sometimes I resort to something really low-tech (but instantaneous instead of waiting for diagnostics to transfer stuff): http://blog.smarx.com/posts/printf-here-in-the-cloud
You can use System.Diagnostics.Trace - and can then set up the TraceListener to write these to Azure Diagnostics.
This won't give you real time trace, but will help to debug some situations.
For one description on this, see http://oakleafblog.blogspot.com/2010/11/adding-trace-event-counter-and-error.html - uses Cerebrata's tool for viewing output
Try using IntelliTrace.
I guess you have already seen the other msdn suggestions.

Categories