5 Replies - 5161 Views - Last Post: 24 February 2012 - 12:16 PM Rate Topic: -----

#1 ricardosms  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 73
  • View blog
  • Posts: 301
  • Joined: 02-April 10

Side Effects Of Running A Program From The IDE

Posted 21 February 2012 - 09:25 PM

Side Effects Os Running A Program From The IDE.

Last week I got a PM from another user:

Quote

I came across your forum post regarding running a program with elevated privileges and downloaded your Hosts code, but I need a little help getting it running.

As you said in one of the responses, it seems to call svchost.exe and immediately closes. I've tinkered around with it for awhile but I can't seem to make heads or tails of the code. Which line of the code must I edit to get it to open up my program with elevated privileges after entering my credentials?



Here is the link:
http://www.dreaminco...1&#entry1047649


After replying to him with my idea of what was happening I haven't hear from him again, so I guess he solved his problem.

Anyway, and I noticed this when I was debugging that program, running the program from the IDE is not always the same than running it as standalone. There must be more, but 3 side effects that I know of are these:

1. Your program delays at the beginning and runs slower.
2. It uses more memory.
3. Some programs won't run on it.

This is mostly gess work, but I believe this is how it happens:

When you run your program from the visual studio environment, you are actually running vshost.exe that is the integrated environment debugger, or connected to it, and your program runs as a or argument parameter of it. If you check your \Bin\Debug folder you will see these files myProgram.vshost.exe, myProgram.vshost.manifest.

myProgram.vshost.exe can not be deleted when you have Visual Studio running. This is the actual program running when you debug. If it is successful it will produce myProgram.exe.

My program was an editor for the host file on "C:\Windows\System32\drivers\etc" that is a system folder. It would start and then you would elevate it privileges and it would try to run another instance of itself, and if successful, the first instance was killed, so you second instance could edit and write to the system folder. Probably you wouldn't see even a flicker when one is starting and the other stopping.

Running it standalone was ok, but in the environment it would just exit after getting the credentials. What was happenning was that it was starting another instance of vshost.exe that was running empty and exiting. So the program would compile, but not do what it was supossed to do. I guess this is an odd situation that most programs wont confront. But mine did.

Please comment on this.

Thank you,
ricardosms

Is This A Good Question/Topic? 0
  • +

Replies To: Side Effects Of Running A Program From The IDE

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5583
  • View blog
  • Posts: 11,942
  • Joined: 02-June 10

Re: Side Effects Of Running A Program From The IDE

Posted 23 February 2012 - 09:51 AM

View Postricardosms, on 21 February 2012 - 10:25 PM, said:

1. Your program delays at the beginning and runs slower.
2. It uses more memory.
3. Some programs won't run on it.


1. Well, yah if you have it debugging there is of course going to be some speed hit for the interaction and monitoring taking place. Running without debugging should show a speed increase.
Attached Image

2. Really? Is it your program using more memory, or are you seeing more memory being used overall? Remember that Visual Studio is still running and recording all the debugging taking place. So is that memory being taken up by the application being debugged, or by the debugger in Visual Studio?

3. I've never had a program refuse to run from the IDE but successfully run as a stand alone. But I have had the reverse because of my own fault: Not including DLLs in the distribution etc. After all when you compile and debug it builds an EXE, then attaches a debugger to it. The exe either runs or it doesn't. - The exception to this being that my RELEASE applications will shutdown if a debugger is attached, as part of anti-hacking efforts.
Was This Post Helpful? 0
  • +
  • -

#3 ricardosms  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 73
  • View blog
  • Posts: 301
  • Joined: 02-April 10

Re: Side Effects Of Running A Program From The IDE

Posted 23 February 2012 - 06:33 PM

Hello tlhIn`toq.

Thank you for commenting, I don't get too much feedback on my posts.

This program runs in the IDE, but when the second instance starts, it kills the first one )as it should), but nothing happens after, it just exits. If I run it standalone, it will kill the first instance and keep running, so I can use it to edit my hosts file, actually, append to it.
Was This Post Helpful? 0
  • +
  • -

#4 ricardosms  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 73
  • View blog
  • Posts: 301
  • Joined: 02-April 10

Re: Side Effects Of Running A Program From The IDE

Posted 24 February 2012 - 03:26 AM

View PosttlhIn`toq, on 23 February 2012 - 11:51 AM, said:

- The exception to this being that my RELEASE applications will shutdown if a debugger is attached, as part of anti-hacking efforts.


I maybe have used a similar code:
        'Running From The IDE?
        If Diagnostics.Debugger.IsAttached() Then  
        'code here
          Else
        'Alternate code here
          End If



Regarding this:

View PosttlhIn`toq, on 23 February 2012 - 11:51 AM, said:

2. Really? Is it your program using more memory, or are you seeing more memory being used overall? Remember that Visual Studio is still running and recording all the debugging taking place. So is that memory being taken up by the application being debugged, or by the debugger in Visual Studio?


I have a program that works on two images simultaneosly and have 4 levels of undo for each one, besides the reload image and the images on the 2 pictureboxes.

I may have 11 copies of my image at one time and some other temporary bitmaps. When I have the same large image (7000x5000 pixels) loaded and in the lockbits loop process and the IDE running on edit mode, I don't get running out of memory exception with the standalone whereas with the IDE I do.
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5583
  • View blog
  • Posts: 11,942
  • Joined: 02-June 10

Re: Side Effects Of Running A Program From The IDE

Posted 24 February 2012 - 07:34 AM

Quote

I don't get running out of memory exception with the standalone whereas with the IDE I do.


Out of memory exception is also thrown when you try to load a bitmap from HDD and it is corrupt or still being written. Its a bad error for that I know, but that's MS for ya.

But what you're saying is you run out of memory when you are running in debug... That doesn't have to mean your program is using more memory. That might just means you don't have enough memory for both the program, and the IDE tracking process at the same time.

Quote

This program runs in the IDE, but when the second instance starts, it kills the first one )as it should), but nothing happens after, it just exits. If I run it standalone, it will kill the first instance and keep running,


This is different than how most people deal with single instance. The second instance usually doesn't kill the first. Instead, if there is already an instance running, the second instance is closed.

Quote

and the images on the 2 pictureboxes.

I may have 11 copies of my image at one time and some other temporary bitmaps.


You don't have full size images in the pictureboxes do you? That would be a waste. If the picturebox is only 1000x800 and the image is 7000x5000 that's a massive waste. I would make a scaled version of the image to send to the picturebox.

Also, you don't have to keep 8 copies of the photo in memory for undo. That's where HDD temp files come in handy. Maybe just the most recent in memory, and the last 4-10 steps on HDD. That would have the most recent 'undo' being quick, and then you load the next level of undo from HDD so it is ready.
Was This Post Helpful? 0
  • +
  • -

#6 ricardosms  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 73
  • View blog
  • Posts: 301
  • Joined: 02-April 10

Re: Side Effects Of Running A Program From The IDE

Posted 24 February 2012 - 12:16 PM

Hello tlhIn`toq

Quote

This is different than how most people deal with single instance. The second instance usually doesn't kill the first. Instead, if there is already an instance running, the second instance is closed.


I coded it that way, the second instance should run with elevated privileges. If it is succesfull on starting, I don't need the first one anymore, so it is killed. It works!

Attached Image

Regarding the Images. I usually reduce the size, but some times you need the detais. Regarding swapping images to disk, I think I will do that. I usually need only the last one, and in due case I could reload the original.

Thank you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1