my task:
I want to display entries from the windows eventlog from my printjobs.
I found various tutorials from msdn and different sites, but I cannot get access to my preferred protocol/service name.
Microsoft-Windows-PrintService
my Code ( c#):
string lists = EventLog.LogNameFromSourceName("Microsoft-Windows-PrintService/Operational", ".");
but this code is not working. Did somebody know a solution or a workaround for my problem.
This is my first project in c#.
Thanks in Advance!
Your syntax for the call is correct. I think the source you are specifying in the call probably doesn't exist.
If you call EventLog.SourcesExists("Microsoft-Windows-PrintService/Operational") does it return false? If so, then the source string you are passing is incorrect and you need to find the correct source from Event Viewer.
Edit: In response to your later post, I don't think permissions have anything to do with it. I was able to access "Application and Services Logs" sources without doing anything special.
According to this previous post event log sources cannot be listed from the API but must be mined from the registry. However, I did find an application EventLogSourcesView that can generate a list of all event sources. It may be helpful in finding the source you are looking for.
Good luck!
thanks for your reply.
Yes, the SourceExist Method return false.
Hmm.. I have no idea how to find the correct Service name.
The SoruceExist Method returns true, for all protocols which are listed under the "Windows Protocols"-section, only. The other protocols which are located under the section "Anwendungs- und Dienstprotokolle" ( I use a german windows version - maybe translate to "Application-and Serviceprotocols"), the method returns false.
In this location, the log will be saved at
%SystemRoot%\System32\Winevt\Logs\Microsoft-Windows-PrintService%4Operational.evtx
Did I need special permissons to "enter" these logs ( Currently, Visual Studio is started as Administrator, only .. enough?)
Thanks!
Related
I am working on a simple C# project that calls for me to launch a program, pointing it at a custom configuration file. Specifically, I'm launching DOSBox with a custom config file that tells it what to do upon starting. I've used shortcuts before, and essentially this is what I put in the shortcut and it works perfectly.
"D:\Video Game Emulation\DOSBox\DOSBox.exe" "D:\Video Game Emulation\DOS Windows\GAMES\CUSTOM.CONF"
Now the program I'm writing is just a prettier way of launching a bunch of old DOS games through DOSBox, each with their own custom config. So in my button code, here's what I have.
Process.Start("D:\\Video Game Emulation\\DOSBox\\DOSBox.exe", "D:\\Video Game Emulation\\DOS Windows\\GAMES\\CUSTOM.CONF");
According to my understanding that is the proper way to start an executable and give it a custom option. However, that launches just fine, but doesn't pass in the config file properly. I also tried this.
Process.Start("D:\\Video Game Emulation\\DOSBox\\DOSBox.exe", -conf "D:\\Video Game Emulation\\DOS Windows\\GAMES\\CUSTOM.CONF");
With no luck either. Anyone know what I need to change in order for it to give DOSBox the custom configuration file properly?
Pass in the path as a string, so put your quotation marks in and test it.
Basically the reason is when checking Intellisense (spelling?), it shows an overload for Start(string fileName, string arguments).
So it wouldn't hurt to make sure you are passing strings into both.
Edit: I think I may have seen it before you edited your post. Did you have the quotation marks in the code?
OK, sorry it has taken so long to get back to this thread, but I've been quite busy. Thanks to help from dakre18, StarPilot, and Bearcat9428 I figured it out. It seems that the working directory has to be specified in the StartInfo in order for it to work. Things seem to work now. Thanks for all your help everyone!
I work for an IT company where we all carry around flash drives that have our most used programs on them.In my spare time I am hoping to create a "main menu" item that is kind of a fun and convenient way to access these files. I am working on creating this using Visual Studio 2013 and using visual C# windows forms. I have come across a snag however that I can't seem to find a workaround for. I am by no means fluent in C#, but I need to have a button on the windows form open a file without specifying what drive it comes from. I understand that I have to specify a path, but as these will be stored on the flash drives of myself and my coworkers I cannot foresee that the path will always begin with E:. Depending on what USB slot the drive is plugged into it could be N: or F: or the like. I have provided an example below:
Using what I currently know I am opening files using this line of code:
System.Diagnostics.Process.Start("C:/Users/Myname/Desktop/Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
Is there any way possible I can have the file open simply from
System.Diagnostics.Process.Start("Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
or something of that nature?
Thanks in advance.
There must have been some mis-communication when I asked my question previously. what I am looking to do is open an executable file via a button click on the windows form using a relative path. I am not able to specify the absolute path because the application will be run from a flash drive and therefore will change depending on what USB slot it is currently inserted into.
What I am hoping to accomplish is insert a line of code that will allow me to open an executable file that is located in the \bin\debug folder along with the application itself. I have a picture for clarification but apparently do not have enough reputation to post it. Thank you and sorry for the earlier confusion.
Usually you can just use Environment.GetFolderPath (MSDN) to give you what you need. It doesn't do absolutely everything, but if you need Desktop and the like, that is plenty.
Depending on the target version of .Net, the SpecialFolders exposed are not all there. It may turn out that you need more than they provide, but in your case it doesn't sound like it.
If there is more you need that is not covered in the default, check out this project. I'm sure there are others like it, but it does a little more than the default BCL version, using the API directly. It is at least something to read and learn (and translate from vb.. use an online translator, very quick). I haven't looked at it, but it seems like you are learning this c#/.net thingy, so it might be helpful
This article is about accessing Windows special folders.
These folders include your “Favorites”, “Cookies”, system libraries and the like.
Here is code, including a large number of constant definitions, plus documentation,
allowing access to and creation of these folders.
I believe this is going to be a big question but I searched the web for at least an hour for an answer and I hope here I'll get the answer.
So the thing is I want to create my own file extension that will essentially be a binary file that my program will obviously will know how to interpret.
I know how to create a binary file and read from it, I understood that all I need is to change the extension and check it before I start reading the file.
The question is even if I create my own extension and check for it before start reading, I can't know that the file was really created by my application, someone could just change the extension and my application won't get the data it needs (of course I'll put everything in a try and catch so the application won't crush).
Is there a way to sign a binary file before opening it so people that get the file can know that my application created that file and not something that someone changed to look like my file type?
It's more of an idea I have so I don't have any code to show or any example other than this scenario.
All I need is something that people will know came from me and not something that every other person can generate on his own (not talking about programmers, I'm talking about regular people).
If you know anything about this subject please direct me to the answer or if you know post it here.
One way could be to encrypt the contents of the file, then have your application decrypt it.
Anyone opening the file in your application would immediately know if that application generated it.
I would create a special sequence at the beginning of the file (a file header)
I am using the Office Integration Pack
After following instruction correctly I am still not able to get the Excel to Import working
My Visual Studio Lightswitch 2011 application is configured to host on IIS Server and use's Easy Shell (so its the default Shell provided by MS).
So far I have tried is calling the
OfficeIntegration.Excel.Import(
this.States,
#"C:\Users\Mr_Mia_Gie\My Documents\ExcelSheet.xls",
"Sheet1",
"A1:C3");
on _Execute event of a button (the button does not live on the Shell Command Bar)
The exception I get back is "Object variable or With block variable not set."
Any solution or suggestion will be highly appreciated
Cheers
I agree with Nevyn (& I'd vote up his answer, but it's embedded in the question as an edit so I can't).
As Nevyn has pointed out, there are really only three objects in that particular line of code that can be causing a null exception:
the OfficeIntegration object
the OfficeIntegration.Excel object
or, the this.States collection (unlikely though)
As was also pointed out for you, it's most likely that one of those objects isn't correctly initialised. You need to check what the value of those three objects are by putting a break point on that line & checking what their values actually are at that point.
You could also put a guard clause in your code (just above that line):
if (OfficeIntegration == null) || (OfficeIntegration.Excel == null) return;
It won't neccesarily "fix" the problem, but it will stop the null exception from occuring (but this shouldn't be a problem in an Execute method). But it's good programing practice to put a guard clause any time you're referencing an object whose value could be null.
Failing that, the only other advice any of us can give you is to post a question in the questions section of the gallery page, where you downloaded the extension from. The autor of the extension should be able to help you.
Is this a web application, if so I dont think it supports it. It requires an extenstion. I dug up an article for you, try it out:
http://blogs.msdn.com/b/lightswitch/archive/2011/04/13/how-to-import-data-from-excel.aspx
The office integration Pack is for Visual Studio LightSwitch windows application and does work for application that are hosted on IIS hence the below code throws exception
OfficeIntegration.Excel.Import(
this.States,
#"C:\Users\Mr_Mia_Gie\My Documents\ExcelSheet.xls",
"Sheet1",
"A1:C3");
The link show that the extension does not support LS WebBrowser application http://officeintegration.codeplex.com/discussions/374585
Also the extension Import data from Excel does work for IIS hosted LS application that runs in webbrowser
I want to get the fullname from a file on Silverlight OpenFileDialog, when I try that, Silverlight throws me an error.
I saw there is an attribute on FullName saying it is [SECURITY CRITICAL], but I need to display the full path, is it really no way I can do that?
OpenFileDialog won't provide the full name simply because it doesn't want you to alter those files. With Silverlight, you only have access to the isolated storage and the file could be located outside this storage.
But you could just open the file and copy it to the isolated storage, and modify it there.Just discovered that bassfriend found this link too and posted it above. My mistake. Then again, the link is in the top-20 of Google. :-)
Another reason why you won't get the full filename is because that filename could contain sensitive information. For example, a file in the "My Documents" folder could expose the user login name.
Basically, it's a security restriction. You're not supposed to bypass it, even if it would be possible. If you would find a way around this, MS would probably release a security update to close that leak again...
Well, yes, Silverlight will not allow you to retrieve the full path information. Your topic seems to be closely related to this question. Maybe the answers there will shed more light on your question.
Try to use the File property as documented here:
Example,
MSDN
The Silverlight OpenFileDialog behaves differently to the standard forms OFD for security reasons. If you retrieve the SelectedFile, it actually returns a FileDialogFileInfo object which contains the Name of the file, rather than a path to the file. When you think about it, this makes perfect sense - you don't want somebody writing a piece of malicious code that can get a handle into your filesystem.