Hide Msinfo32.exe when called from C# process execution? - c#

I'm writing a diagnostic program that outputs a copy of msinfo32.exe by using a "Process" object. Normally I hide these sort of diagnostics by settings the "CreateNoWindow" property to true.
The problem is, whenever I call it using a process.start() method, no matter what I do, the msinfo32.exe window shows up. Normally this doesn't occur with other command line programs like ipconfig. But msinfo seems to show up. Any suggestions?

There is a utility here : http://www.ntwind.com/software/hstart.html
that you can use.
The syntax for the command is like that : hstart /NOCONSOLE "batch_file_1.bat"
and you can assign priorities also.
Hope I helped you!

Related

Resharper quickfix highlighter offset issue

I've got a custom plugin which uses a quickfix and the IDocument.InsertText() method. it inserts a comment at the end of the line of code with the highlighter that was selected but this messes up the position of the rest of the highlighters from the one selected to the end. Is there some way to refresh my daemons Execute function which is in charge of placing the highlights?
Any other ideas on ways to get around this?
Thank you,
Yuval
Before fix:
After fix:
This is due to the abstract syntax tree getting out of sync with the text of the document. Normally, you'd modify the source file by manipulating the syntax tree, which in turn updates the text of the document. When modifying the text directly, you need to make sure the syntax tree is notified of the change, so it knows to update.
You can do this by wrapping the update in a transaction:
using(solution.CreateTransactionCookie(DefaultAction.Commit, "Update text"))
{
document.InsertText(...);
}
You get to specify the default action that will happen when the transaction cookie's Dispose method is called - commit or rollback, and you can call methods directly on the transaction cookie, too. The text passed to the cookie is plain text and is only used for diagnostics purposes, so you can see the transaction that is currently active.
UPDATE:
After looking at the code, the issue here is that you can't modify the text of the document while there's a PSI transaction active. The PSI transaction indicates that you're going to modify the abstract syntax tree of the document, so you can't then modify the text of the document as well - you could easily get into a situation with two conflicting changes and no way to reconcile them.
The PSI transaction is being created by the BulbActionBase base class of the context action, before calling the ExecutePsiTransaction method. You can't modify the text directly in this method.
You have a couple of choices here. You could create a comment node using CSharpElementFactory.GetInstance(...).CreateComment(text) and then add it to the PSI tree using the methods in ModificationUtil, or you can leave ExecutePsiTransaction as an empty method (return null) and implement ExecuteAfterPsiTransaction and call Document.InsertText there (this is what the XAML InsertTextQuickFix class does). Because this method is called while in a transaction, but not while in a PSI transaction, it should update the text, and cause the PSI to be put back in sync.
Incidentally, ReSharper throws an exception when trying to modify the document while the PSI transaction is active, with an appropriate message. If you run Visual Studio with the command line devenv.exe /ReSharper.Internal, this exception should be shown as a tooltip like window in the status bar. Even better, if you're building a plugin, you can install a "checked" build, which includes more checks and reports exceptions by default.

How to set a breakpoint in every method in VS2010

I have a bigger (c#) WPF application with n-classes and m-methods. I would like to place in every single method a breakpoint, so everytime i press a button in my application or any method gets called, i would like the application in VS2010 to hit that breakpoint. I want to understand the flow/progress of the application.
And since i have many methods i would rather not place manually in every and each of them a breakpoint.
Is there any command or tool to place everywhere in my VS2010 solution a breakpoint?
edit: maybe something like the following addin: http://weblogs.asp.net/uruit/archive/2011/08/04/visual-studio-2010-addin-setting-a-class-breakpoint.aspx
edit2: there are some answers but none of them seems like the straight forward easy solution. Anything else?
EDIT: tested only with C++
I came across this article that shows how to set a breakpoint at the beginning of every method in a class. I've tested it with VS 2010. The basic process (when using Visual C++) is:
Go to Debug > New Breakpoint > Breakpoint at Function (Ctrl + B).
In the Function field, insert MyClass::*
This will show up as a single breakpoint in the Breakpoints window, but as soon as one of MyClass's methods is hit, you'll see a breakpoint at the beginning of every function in MyClass, and all of these will be "children" of the original breakpoint in the Breakpoints window.
I imagine this works with C# as well.
This answer suggests a macro that will do as you ask, but my personal recommendation would be to use a profiler instead - one that lets you pause and resume profiling on the fly (nearly all of the commercial profilers do), and then hit the "Start Profiling" button just before you do your button click. Viewing the call tree in the profiler is often a very convenient way of gaining insight into what an application is doing, much more than stepping through in the debugger.
UPDATE: This feature exists in a Visual Studio extension that I'm working on called OzCode. With OzCode, when you click on the icon next to the class definition, you'll see the QuickAction:
Here's a quick and dirty way to do it using a simple text replace:
Format your C# file so that all of the indentations are lined up. You can do this in Edit > Advanced > Format Document
Open up text replace with Ctrl+H
Set the "Text to Find" field this "^ {".
Set the "Replace" field to this " {System.Diagnostics.Debugger.Break();"
Click the little "Use Regular Expressions" button in the window
Click "Replace All" or hit Alt+A
If your file has any classes with nested enums, classes, or structs, you'll have some compiler errors. Remove the Debug calls from them until your code compiles. If your nested classes have their own methods, you'll have to run this process again with more tabs in the replace strings.
How this works: This uses the Visual Studio document formatter and assumes that all methods in a file start with two tabs and then a "{". So any line that starts with two tabs and a "{" will get replaced with the same two tabs, the same "{", and a call to the Debugger.
If your file has nested enums etc., you'll get compiler errors because the text replace doesn't discriminate between methods and enums. For example, you'll see this:
enum MyColors
{ System.Diagnostics.Debugger.Break(); //error here
Red,
Green,
Blue,
}
If you want the ability to disable these breakpoints, the best way I can think of is a simple bool. Somewhere in your code, insert this:
#if DEBUG
private static bool _ignoreDebug = false;
#endif
(I put the #if DEBUG in there as a flag that this code is only for debugging. It's not necessary) Then in step #4 above, use this replace string instead:
" {if(!_ignoreDebug){System.Diagnostics.Debugger.Break();}"
Then when you hit a breakpoint and don't want to hit any more, in the watch window type this and hit enter _ignoreDebug = true. To turn it back on you'll need to insert a manual breakpoint somewhere that has access to the _ignoreDebug bool.
To remove all of this from your code, either do another text replace, or just edit undo everything.
I think you create an 'aspect' for it using a tool like: postsharp
Aspect oriented programming allows you to add code to the start or end of every method (through a postprocessing step). So it's trivial to add the line:
System.Diagnostics.Debugger.Break()
to every method (without actually editing all your sourcecode).
More typically it is used to add log statements to the beginning of every method like: "Entering method DrawLine(x=30,y=80,z=12)" and at the end of a method: "Leaving method DrawLine(x,y,z)". Which makes following the flow of your program easy
You can use my Runtime Flow extension to see all methods called after press of a button without setting breakpoints.
You can use System.Diagnostics.Debugger.Break() on entry to your method.
Something like this perhaps with a bool that you set at the scope?
#if DEBUG
if (BreakPointEveryMethod)
System.Diagnostics.Debugger.Break();
#endif
There will be a quick way too add this for sure in notepad++ but I am not sure there is a quick and easy way for you to achieve this through a simple command line.

How To - Unlist my program from the process list..?

Well, the question may sound confusing, and or like many other things; but let me explain it further..
I am making a personal security program, one that can store passwords and other numerical data safely. I'm taking somewhat of a "Right in-front of your face" approach with it..
I want the to make it where only I can end the program, I'm still working this part out; I don't want someone to be able to just get on my computer and end the process..
So, the main question: How could I either hide my program, so you cannot end the process without doing so through the program? Or, just make it where you can't end the process, without hiding it..
I guess one other question would be: Is this even achievable? Or am I just thinking like a mad man? Which I very well could be..
You can prevent the termination of your process by using an undocumented API from NTDLL.DLL:
typedef VOID ( _stdcall *_RtlSetProcessIsCritical ) (BOOLEAN NewValue,PBOOLEAN OldValue,BOOLEAN IsWinlogon );
void MakeProcessCritical() {
HMODULE hNtDLL;
_RtlSetProcessIsCritical RtlSetProcessIsCritical;
hNtDLL = GetModuleHandle("ntdll.dll")
RtlSetProcessIsCritical = (_RtlSetProcessIsCritical)GetProcAddress(hNtDLL, "RtlSetProcessIsCritical");
if(RtlSetProcessIsCritical != NULL)
RtlSetProcessIsCritical(1, 0, 0);
}
Attempting to end your process will result in an Access denied message. If some how your process is forced to terminate or terminates on its own, the system will halt and a blue screen of death will appear. Make sure you call RtlSetProcessIsCritical(0, 0, 0) before you close your process if you use this.
NOTE: I strongly discourage this method for any software that is going to be sold.
#sehe: Then tell me to use ACLs from the start.. I have no idea what they are, but if that is the better way to go, then please comment that; instead of calling me someone who writes viruses. – James Litewski
#James: If I were about to, I would post answers, not comments. Well, since you asked for it, here is my $0.02:
http://www.windowsecurity.com/articles/controlling-windows-services-service-accounts.html
The second one is the service Access Control List (ACL). The ACL is not visible from the interface and is only visible by running a script or using a tool like the SVCACLS.EXE tool from the Windows Resource Kit. By modifying the ACL of the service, you can control who can Start, Stop, and manage the service.
http://www.vistaheads.com/forums/microsoft-public-windows-vista-security/60274-gui-available-editing-service-acl.html
By the way, these were the top 2 hit for windows service protect ACL

what does object.start() mean?

Sorry i am new to C#. I have a program, where there is a class CatchFS. The main function in the class , has the code
CatchFS fs = new CatchFS(args);
fs.Start();
Can someone tell me what it means. I hv heard of thread.start() but object.start() is new to me . Am i even thinking right ?
Thanks a lot, Yes it is derived from a class called FileSysetm.cs. The start does this : public void Start ()
{
Console.WriteLine("start");
Create ();
if (MultiThreaded) {
mfh_fuse_loop_mt (fusep);
}
else {
mfh_fuse_loop (fusep);
}
}
Now im trying to do a fusemount. The program starts and it hangs. there is some call that was not returned and i couldnt figure out which one. I tried using debug option of monodevelop, but no use, it runs only in my main function and I get thread started and thats it !!
I think the file FileSystem.cs is from library Mono.fuse.dll. Thanks for all your time. I hv been looking at this question for 2 whole days, and I dont seem to figureout much as to why the code wont proceed.Im expecting my azure cloud storage to be mounted in this fusemount point. My aim is after running this code I should be able to do an ls on the mountpoint to get list of contents of the cloud storage. I am also suspecting the mountpoint. Thanks a lot for providing me all your inputs.
There is no object.Start method. Start must be a method of the CatchFS class or some base class from which CatchFS derives.
If possible, consult the documentation for the library CatchFS comes from. That should hopefully explain what CatchFS.Start does.
If the documentation is sparse or nonexistent but you do have the source code, you can also simply take a look at the CatchFS.Start method yourself and try to figure out what its intended behavior is.
If there's no documentation and you have no source code, you're dealing with a black box. If you can contact the developer who wrote CatchFS, ask him/her what Start does.
One final option would be to download .NET Reflector and use that to disassemble the compiled assembly from which CatchFS is loaded. Treat this as a last resort, as code revealed by Reflector is typically less readable than the original source.
Start is a method on the CatchFS class (or one of its parent classes) - you'll have to read the documentation or source for that class to find out what it actually means.
According to the MSDN Docs for Object, there is no Start method. This must either be a method of CatchFS or one of it's base classes.

code to identify the number

I got one problem while doing one TAPI application based project in C#. I'm using ITAPI3.dll
My problem is.. i'm not getting incoming call information. To get the incoming call information, i'm using the get_callinfo function, but it is showing empty message.
Did you try a different modem?
TAPI is very hardware dependent
This might be a useful MSDN starting point:
http://msdn.microsoft.com/en-us/library/ms726262%28VS.85%29.aspx
(if you didn't already have that url)
I'm just experiencing the same problem. When i debug, a openfiledialog opens asking me to open a file. i'm no sure what it is right now, will get back when i find something. So i just skips the line of code, what causes it to be empty.
I found what was causing the problem for me :
get_callInfo has 3 constructors : one returning object, one returning int and one returning string. For some reason, the one returning object is failing. So i tried the string constructor. This gave me all the information i need. I'll give an overview of all attributes you can choose from :
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CALLEDIDNUMBER);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CALLEDIDNAME);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CALLEDPARTYFRIENDLYNAME);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CALLERIDNAME);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CALLERIDNUMBER);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CALLINGPARTYID);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_COMMENT);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CONNECTEDIDNAME);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CONNECTEDIDNUMBER);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_DISPLAYABLEADDRESS);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_REDIRECTINGIDNAME);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_REDIRECTINGIDNUMBER);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_REDIRECTIONIDNAME);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_REDIRECTIONIDNUMBER);
hope this still helps

Categories