Monday, April 11, 2011

Visual Studio Addin Development - How to resolve the "The process cannot access the file" problem after exiting visual studio?

I'm currently developing a visual studio add-in, however when I close visual studio and shutdown my machine and come back the next day, I cannot build the add-in because it is currently loaded in visual studio. How do i fix this problem so I don't have to manually remove delete and reinstall the add-in every time I wish to debug or change my add-in?

From stackoverflow
  • You can set the behavior of the addin and how it loads, I'd set it to 'load on demand' which I'm currently trying to find you some information on.

    I can't find anything official but if you go to the Setup project, right click and select "View Registry" it'll show you all the registry keys that are created. Navigate down to the level for your addin and change the 'LoadBehavior' from '3' to '2'.

    From then on you should be able to load your add-in using the Addin Manager.

    I'll try and update with more information when I can get it, hope it helps.

    Tom J Nowell : I dont have a 'setup' project, I've just got a project with a C# addin which when launched spawns a second visual studio with the addin installed. But if I close both visual studios and start a fresh instance the original visual studio now has the addin loaded, preventing me from building
    PintSizedCat : I have to run now but I'll look in to it later for you.
  • AddIns are usually loaded by .AddIn file which is placed in one of these locations

    C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins\ C:\Documents and Settings\Computer.User\My Documents\Visual Studio 2008\Addins

    So when I do AddIn development, I start Visual Studio with special .bat file. I also use the AddIn when working on other projects, so there are additional complications. Here is an example of the file I use:

    :: My installed .AddIn file goes in All Users directory
    move "C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins\Sample.AddIn" "C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins\Sample.AddIn_"
    
    :: just in case it got left from the previous session
    del "C:\Documents and Settings\Computer.User\My Documents\Visual Studio 2008\Addins\Sample_dbg_.AddIn"
    
    :: start Visual Studio and open AddIn solution
    "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" D:\dev\Sample.sln /resetaddin Sample.Connect
    
    :: this will execute after Visual Studio is closed
    del "C:\Documents and Settings\Computer.User\My Documents\Visual Studio 2008\Addins\Sample_dbg_.AddIn"
    
    :: This is needed because my installed AddIn, and the one I'm developing are in different directories, yet have the same name. That confuses studio and this line sets things straight
    "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" /resetaddin Sample.Connect /Command File.Exit
    
    :: restore installed AddIn file
    move "C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins\Sample.AddIn_" "C:\Documents and Settings\All Users\Application Data\Microsoft\MSEnvShared\Addins\Sample.AddIn"
    
    exit
    

    I also do this on Prebuilt event in AddIn project:

    copy "$(ProjectDir)\Sample_dbg_.AddIn" "C:\Documents and Settings\Computer.User\My Documents\Visual Studio 2008\Addins\Sample_dbg_.AddIn"
    

    Also you could look into Visual Studio command line parameter /rootsuffix , but I wasn't able to find a solution around that.

  • This is what worked for me:
    Pre-build event that renames the target as target.locked

What is the difference between Decimal, Float and Double in C#?

What is the difference between Decimal, Float and Double in C#?

When would use use each of them?

From stackoverflow
  • Precision is the main difference.

    Float - 7 digits (32 bit)

    Double-15-16 digits (64 bit)

    Decimal -28-29 significant digits (128 bit)

    Decimals have much higher precession and are usually used within financial applications that require a high degree of accuracy. Decimals are much slower (up to 20X times in some tests) than a double\float.

    Decimals and Floats/Doubles cannot be compared without a cast whereas Floats and Doubles can. Decimals also allow the encoding or trailing zeros.

    Les : +1 for the link to performance considerations
  • float is a single precision (32 bit) floating point data type as defined by IEEE 754 (it is used mostly in graphic libraries).

    double is a double precision (64 bit) floating point data type as defined by IEEE 754 (probably the most normally used data type for real values).

    decimal is a 128-bit floating point data type, it should be used where precision is of extreme importance (monetary calculations).

    Tor Haugen : Actually, decimal is not a floating-point data type.
    Mehrdad Afshari : Technically, it *is* a floating point data type as it stores exponent and mantissa.
    Jon Skeet : +1 for Mehrdad's comment. It's a floating *decimal* point type rather than a float *binary* point type.
  • The thing to keep in mind is that both float and double are considered "approximations" of a floating point number. Some floating point numbers cannot be accurately represented by floats or doubles, and you can get weird rouding errors out at the extreme precisions.

    Decimal doesn't use IEEE floating point representation, it uses a decimal representation that is 100% accurate by doing decimal based math rather than base 2 based math.

    What this means is that you can trust math to within the accuracy of decimal precision whereas you can't fully trust floats or doubles unless you are very careful.

    Mehrdad Afshari : What do you mean of 100% accurate?! Theoretically, computers can't store 100% precision of many real numbers.
    Jon Skeet : +1 to Mehrdad's comment again. How exactly is 1m/3m "100% accurate" for example?
    cgreeno : @Mystere is right - float and doubles are not 100% accurate because it uses base 2 vs decimal that internally uses base 10
    Mehrdad Afshari : BtBh: I didn't dispute that. However, Decimal is not accurate either. Theoretically, computers can only store **finite representation** of things. This is not something anybody can change.
    Joachim Sauer : Decimal floating point numbers aren't any more (or any less!) accurate than binary floating point numbers. They just match our naive expectations better, because they use base-10 instead of base-2.
    Mystere Man : I said "to within the accuracy of the decimal precision"
  • float and double are floating binary point types. In other words, they represent a number like this:

    10001.10010110011
    

    The binary number and the location of the binary point are both encoded within the value.

    decimal is a floating decimal point type. In other words, they represent a number like this:

    12345.65789
    

    Again, the number and the location of the decimal point are both encoded within the value - that's what makes decimal still a floating point type instead of a fixed point type.

    The important thing to note is that humans are used to representing non-integers in a decimal form, and expect exact results in decimal representations. Not all decimal numbers are exactly representable in binary floating point - 0.1, for example - so if you use a binary floating point value you'll actually get an approximation to 0.1. You'll still get approximations when using a floating decimal point as well - the result of dividing 1 by 3 can't be exactly represented, for example.

    As for what to use when:

    • For values which are "naturally exact decimals" it's good to use decimal. This is usually suitable for any concepts invented by humans: financial values are the most obvious example, but there are others too. Consider the score given to divers or ice skaters, for example.

    • For values which are more artefacts of nature which can't really be measured exactly anyway, float/double are more appropriate. For example, scientific data would usually be represented in this form. Here, the original values won't be "decimally accurate" to start with, so it's not important for the expected results to maintain the "decimal accuracy". Floating binary point types are much faster to work with than decimals.

    Mehrdad Afshari : +1 Nice explanation. I think it's important to clarify the myth of decimal accuracy. Personally, I've never been a fan of school oriented CS stuff, but at least schools are good at teaching these things.
    cgreeno : This is a great answer.
    ydobonmai : Great explaination..
    Prakash Kalakoti : Nice explaination
    ionut bizau : Skeet explanation.
    1. Double and float can be divided by integer zero without an exception at both compilation and run time.
    2. Decimal cannot be divided by integer zero. Compilation will always fail if you do that.

FLASH AS3 spme External streams urls not working from my server

Some external streaming urls working from my server, some streams urls not working , what is the reason ?I am using as3 flash 9player. external urls like this http://38.96.174.38:9568 this is not working .

Please let me know.

thanks

From stackoverflow
  • It's dead simple: if the given server grants your player permission to access its contents via the default policy file (called /crossdomain.xml), then it works. If there is no default policy file, then it doesn't.

  • Thanks Mr David Hanak if you give more explain it will be helpfull please , Because corssdomain itseems very hard to follow please guide me more .

    thanks again

How to handle general exceptions in Asp.Net MVC?

I want to transfer all unhandled exceptions to an error page in Asp.Net MVC. What is the way to handle the unhandled exceptions in Asp.net MVC? Is there anything like application_error?

From stackoverflow
  • Hi, check out the HandleError attribute. There's a good write up here and here.

    yapiskan : That's what I'm looking for. Thanks!
  • If you are using the standard setup, your controller(s) can do this by overriding one of the methods (proabably OnException, but I don't have it handy to check). If you want all your controllers to share this logic, you can use a base-controller.

    Alternatively, you can do this via filters (for example [HandleError]). I don't know if there is a single global place for such logic, though.

    yapiskan : I have a base controller. I guess it is enough to put this filter to base class. Am I right?
    Kieron : It should be, give it a go...

What is my problem with tab-selecting in JQuery?

I want to create a webpage in which I can use the JQuey tabs both by a side-bar and by the upper button-bar of the Jquery tabs itself.

My code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type"
          content="text/html; charset=ISO-8859-1" />
  <title>title here</title>
  <script type="text/javascript" src="jquery.js"></script>
  <script type="text/javascript" src="ui.core.js"></script>
  <script type="text/javascript" src="ui.datepicker.js"></script>
  <script type="text/javascript" src="ui.tabs.js"></script>
  <link rel="stylesheet" type="text/css" media="screen" href="local.css" />
  <script type="text/javascript">
    $(document).ready(function(){
    $("#datepicker").datepicker();
    });
  </script>
  <script type="text/javascript">
    $(document).ready(function() {
      $("#tabs").tabs();
    });
    $("select2").click(function() { // bind click event to link
        $("$tabs").tabs("select", 1); // switch to third tab
        return false;
    });
  </script>
</head>
<body>
  <div id="container">
    <div id="row">
      <div id="leftsubcontainer"><div class="column-in">
        <h4>rev0.1</h4>
        <p>medewerkernaam</p>
        <br/>
        <div type="text" id="datepicker"></div>
        <br/><br/>
        <br/><br/>
        <p>log out</p>
        <button id="select2">kies derde</button>
        <br/><br/>
      </div></div>
      <div id="rightsubcontainer"><div class="column-in">
        <div id="tabs">
          <ul>
            <li><a href="#tabs-1">Nunc tincidunt</a></li>
            <li><a href="#tabs-2">Proin dolor</a></li>
            <li><a href="#tabs-3">Aenean lacinia</a></li>
          </ul>
          <div id="tabs-1">
            <p>tekst1</p>
          </div>
          <div id="tabs-2">
            <p>tekst 2</p>
          </div>
          <div id="tabs-3">
            <p>tekst 3</p>
          </div>
        </div>

      </div></div>
    </div>
  </div>
</body>
</html>

The problem is, that, whenever I click on the button, the tabs are not changing (i.e. it does not select the right tab).

Does anyone know what I have been doing wrong?

From stackoverflow
  • You have a problem here :

    $("$tabs").tabs("select", 1);
    

    You should use a # instead of $ :

    $("#tabs").tabs("select", 1);
    

    And passing 1 as second parameter will select second tab, not third.

  • Minor detail but:

        $(document).ready(function(){
        $("#datepicker").datepicker();
        });
        </script>
        <script type="text/javascript">
                $(document).ready(function() {
                        $("#tabs").tabs();
                });
    

    could be merged into:

        $(document).ready(function(){
                      $("#datepicker").datepicker();
                      $("#tabs").tabs();
                });
    

MonoDevelop on Windows

My google-fu has failed me - can MonoDevelop be used on Windows? Preferably without having to compile from source?

It works well on my home Ubuntu box, and while I have Visual Studio at work, it seems there might be some advantages to having MonoDevelop too.

EDIT: I'm aware of SharpDevelop; I'd prefer to have MonoDevelop if possible, just because I've started to get familiar with the interface, and I believe the SharpDevelop and MonoDevelop are not so closely related any more.


Woohoo! MonoDevelop for Windows now has a preview installer which can be downloaded here


MonoDevelop 2.2 beta is out, with official support for Windows. (Thanks Sergio DomingoHernando)

From stackoverflow
  • Try SharpDevelop . MonoDevelop is built on SharpDevelop's code base.

    Colin Pickard : I'd prefer to have MonoDevelop if possible, just because I've started to get familiar with the interface, and I believe the SharpDevelop and MonoDevelop are not so closely related any more.
    Mehrdad Afshari : It seems you should build it from source: http://www.monodevelop.com/MonoDevelopWin32
  • It's possible, but not easy. There's certainly not an installer.

    This is pretty much the only guide to getting it to work: http://lists.ximian.com/pipermail/monodevelop-list/2006-September/004442.html

  • It seems that MonoDevelop on Windows still has a number of outstanding problems, even when built from source (and can only be built on .NET, not on Mono). So obviously there is no installer yet either.

    The answer to my question then is No, MonoDevelop on Windows is not ready for normal use.

    I guess I'll make do with Visual Studio and SharpDevelop on windows and wait patiently (or maybe even have a look at the outstanding bugs...!)


    UPDATE: MonoDevelop for Windows now has a preview installer which can be downloaded here

  • There was a recent blog entry about MonoDevelop on Windows. Now is probably the time to try it out.

    Update: MonoDevelop have just been released for Windows and Mac. More from Miguel's blog.

  • MonoDevelop 2.2 has official support for Windows:

    Windows Support

    Windows now Officially Supported

    Windows is now an officially supported platform for running MonoDevelop. Many Windows specific issues have been fixed, and some add-ins such as debugging and subversion support have been written specifically for Windows.

    Windows Installer

    We are releasing a new Windows Installer which includes almost all you need to run MonoDevelop. The only external dependency is gtk#, which is provided in a separate installer.

    You can download Beta 1.

    Colin Pickard : thanks !

IE7 Defaults Elements to 100% Width

I've got a really frustrating problem with a web application I work on (I didn't originally write it). It uses frames for the layout scarily enough. The problem I'm having is that all elements with a background colour and border set via CSS default to 100% width. I've just tested div elements, paragraph elements etc.

I removed the stylesheet completely and then tested it and I had the same problem, so it's not the stylesheet causing the problem.

I wrote a quick test to make sure it wasn't conflicting code and used the same doctype and xmlns as ours - I get the same problem. Here's the example code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
    #test {
        border:1px solid #ccc;
        background-color:#ddd;
    }
</style>
</head>
<body>
    <div id="test">
        Test information!
    </div>
</body>
</html>

Any ideas?

From stackoverflow
  • I think this is required by HTML/CSS. Block elements extend the full width unless there is something to stop them.

    (FF has the same behaviour.)

    Kezzer : I hadn't realised this was default behaviour. I just tested it in FF and you're right, exactly the same.
  • Don't divs default to 100% (of parents size) because they're blocks? You could always try changing display to inline: #test {display:inline;}

    Kezzer : Yeah display:inline is a bit of a pain in this case as padding's get overlapped. Good idea though.
  • As Richard and BeafTurkey say, divs are block elements and will fill the width of the browser.

    You can either use an inline element, such as a span

    <span id="test">
        Test information!
    </span>
    

    or add some style to your div to force it to be inline

    div#test { display: inline; }
    
  • It's not because the element has a background or a border that it expands to the full with of the parent, it's because it's a block element. The background or border just makes you see how large the element really is.

    The default width is actually not "100%", but "auto". The practical difference is that the element including borders uses 100% of the width, instead of the width excluding the borders becoming 100% of the width (making the width including borders wider than it's parent).

    If you don't want the element to use the available width you can make it a floating element. Then it will adjust itself to it's content.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
     <title>Test</title>
     <style type="text/css">
     #test1 {
      float: left;
      border:1px solid #ccc;
      background-color: #ddd;
     }
     #test2 {
      float: left;
      clear: both;
      border:1px solid #000;
      background-color: #ccf;
     }
     </style>
    </head>
    <body>
     <div id="test1">
      Test information!
     </div>
     <div id="test2">
      Test information!
     </div>
    </body>
    </html>
    

problem with tab-selecting in JQuery

Hello all, I have the following problem:

I want to create a webpage in which I can use the JQuey tabs both by a side-bar and by the upper button-bar of the Jquery tabs itself. I am using the following code:

title here $(document).ready(function(){ $("#datepicker").datepicker(); }); $(document).ready(function() { $("#tabs").tabs(); }); $("select2").click(function() { // bind click event to link $("$tabs").tabs("select", 1); // switch to third tab return false; });

<body>
 <div id="container">
  <div id="row">
   <div id="leftsubcontainer"><div class="column-in">
    <h4>rev0.1</h4>
    <p>medewerkernaam</p>
    <br/>
    <div type="text" id="datepicker"></div>
    <br/><br/>
    <br/><br/>
    <p>log out</p>
    <button id="select2">kies derde</button>
    <br/><br/>
   </div></div>
   <div id="rightsubcontainer"><div class="column-in">
    <div id="tabs">
     <ul>
      <li><a href="#tabs-1">Nunc tincidunt</a></li>
      <li><a href="#tabs-2">Proin dolor</a></li>
      <li><a href="#tabs-3">Aenean lacinia</a></li>
     </ul>
     <div id="tabs-1">
      <p>tekst1</p>
     </div>
     <div id="tabs-2">
      <p>tekst 2</p>
     </div>
     <div id="tabs-3">
      <p>tekst 3</p>
     </div>
    </div>


   </div></div>
  </div>
 </div>
</body>

The problem is, that, whenever I click on the button, the tabs are not changing (i.e. it does not select the right tab). Does anyone of you know what I have been doing wrong?

Hope to hear from you all,

kind regards, Jeroen

From stackoverflow
  • You have a few typos and issues with your selectors that's getting in the way. Repalce your javascript code with the following

    $(document).ready(function() {
        var $tabs = $("#tabs").tabs();
        $("#select2").click(function() {
            // bind click event to link
            $tabs.tabs("select", 1); // switch to second tab
            return false;
        });
    });
    

    That should work fine.

Detecting change in two consecutive pictures

As a toy project i want to write an application that will take pictures from a web cam and then detect changes in them. I want to detect if someone walked in front of the webcam.

Can you guys, show me some pointers on how can i detect a major change in two consecutive shots?

From stackoverflow
  • Over at Code Project is a nice article explaining a possible solution.

  • Subtract the per pixel lightness values from one image to the other.

    This will give you high values per pixel where something is moved, and low values for where things are the same. Total these values and check to see if it's above a certain threshold number to see if a major change has occured.

    I took a photo of my hand from my laptop to show this:

    alt text

    Paul Tomblin : In natural light, this method generates false positives as the sun moves through the sky, changing light levels and moving shadows.
    idursun : @Paul, I think that wouldn't be much a problem because sun doesn't move suddenly and also a significant light level change is that should be tracked.
    Vladimir Dyuzhev : if sun moves suddenly, we'll have more important things to do O_O
    MSalters : Still is a good first filter, very low false negatives.
    James Burgess : This is pretty much the standard for a low-level filter: subtraction and thresholding. A large number of machine vision systems are built entirely upon this simple filter (and only sometimes, something more complex). Of course, reliable thresholding relies on consistent lighting ;)
  • I would start by scaling down the image to something like 30K to 60K pixels. This not only will speed up calculation, but also get rid of minute irrelevant changes. For instance you don't want to detect a curtain near an open window moved by the wind.

    Next, sum the squared differences of the pixel values. If you want to do it thoroughly, you can do it for R, G and B separately:

    Delta := 0;
    for y := 0 to Im1.Height do begin
      for x := 0 to Im1.Width do begin
        DeltaR := ( Im1[x,y].Red   - Im2[x,y].Red ) ^ 2;
        DeltaG := ( Im1[x,y].Green - Im2[x,y].Green ) ^ 2;
        DeltaB := ( Im1[x,y].Blue  - Im2[x,y].Blue ) ^ 2;
        Delta := Delta + DeltaR + DeltaG + DeltaB;
      end;
    end;
    
    if (Delta > Treshold) then
      Say( 'Hi Bob!' );
    

    (this is just pseudo-code and as code would process rather slowly, google for "scanline" if you want to process all pixels in an image quickly)

    You may want to define the treshold value empirically: walk slowly by the camera, preferably wearing clothes matching the background color and see what delta's you get.
    Skipping frames should increase sensitivity.

Does this custom DateTime format break in other cultures?

When displaying my DateTime values, I want them to be formatted like so: "February 9, 2009 7:00 AM"

I am using the following code, but am concerned that the date may display incorrectly in other cultures. Can anyone tell me if this is the case or not, and if it is how can I fix it?

Date.ToString("MMMM dd, yyyy hh:mm tt");

Thanks!

From stackoverflow
  • Why not simply use the user's long date/time format(s)?

  • the code

            DateTime now=DateTime.Now;
            foreach(CultureInfo inf in CultureInfo.GetCultures( CultureTypes.InstalledWin32Cultures))
            {
                Console.WriteLine(now.ToString("MMMM dd, yyyy hh:mm tt", inf.DateTimeFormat));
            }
    

    return
    Tlhakole 09, 2009 04:21 AM
    guovvamanu 09, 2009 04:21
    goevten 09, 2009 04:21
    veljaca 09, 2009 04:21
    kuovamaanu 09, 2009 04:21
    Hatun puquy 09, 2009 04:21 a.m.
    guovvamanu 09, 2009 04:21
    ta?lvvmannu 09, 2009 04:21
    Chwefror 09, 2009 04:21 a.m.
    februar 09, 2009 04:21
    guovvamano 09, 2009 04:21
    Hui-tanguru 09, 2009 04:21 a.m.
    Hatun puquy 09, 2009 04:21
    februar 09, 2009 04:21

    i mean, this is showing for each culture in his code

    epochwolf : You're up late :)
  • I am using the following code, but am concerned that the date may display incorrectly in other cultures.

    What exactly is ‘correct’? Are you a normal client-side app? If so, you'll get localised month names. Is that ‘incorrect’? Depends what you're looking for.

    If you do want locale-friendly times in a client-side app then using the default long date format will give you the smoothest results. In my locale I wouldn't want to see 12-hour clock or the month before the day, though I'd surely understand it.

    If you're a server-side app you don't want to use any default-localised anything, because the locale will be your server's rather than your users', and you'll have a weird portability problem. In this case you'll have to either allow the user to pick out their own locale, or use your own date formatting functions with built-in English month names.

    (Or, to avoid the problem, no month names. In which case ISO-8601 format “YYYY-mm-dd HH:MM:SS” would be the default choice.)

  • I prefer the ISO 8601 format (and yes without the "T") : you don't have to juggle among different representations depending on who is reading your data. Less code, less bugs.

    I keep finding documents originally written in english that get "translated" but with dates that stay "as is" and so become completely wrong.

    As an added bonus, ISO formatted dates sort just like ordinary strings !

close a particular command prompt

hi, I have opened a commnad prompt using java program and another command prompt manually. Now my requirement is that i need to close the command prompt that i have opened by java program using the program.

I tried to close this by giving rt.exec("taskkill /IM cmd.exe");

But the problem is that the command prompt that i have opened manually is aslo closed which i dont want.

Help needed. Thanks in advance

From stackoverflow
  • if you're using Runtime.getRuntime().exec(), it returns a Process object. You should hold on to that and call Process.destroy() when you're done.

How can I delete a service in Windows?

I have a couple old services that I want to completely uninstall. How can I do this?

From stackoverflow
  • this has nothing to do with programming. . .

    Eric Z Beard : System administration questions are Ok. Programmers constantly deal with these kinds of issues.
    Mostlyharmless : Not specifically the question, but whoever does a lot of windows programming will find the answer useful. I for one need to do those a lot when debugging / testing my COM+ app.
  • Click Start | Run and type regedit in the Open: line. Click OK.

    Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

    Scroll down the left pane, locate the service name, right click it and select Delete.

    Reboot the system

  • Remove the right key from HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\

  • Use the SC command, like this (you need to be on a command prompt to execute the commands in this post):

    SC STOP shortservicename
    SC DELETE shortservicename
    

    If you need to find the short service name of a service, use the following command to get a list of services and their status:

    SC QUERY
    

    For a more concise list, execute this command:

    SC QUERY | FIND "_NAME"
    

    The short service name will be listed just above the display name, like this:

    SERVICE_NAME: SSDPSRV
    DISPLAY_NAME: SSDP Discovery Service
    

    And thus to delete that service (it is not recommended to delete the SSDPSRV service btw):

    SC STOP SSDPSRV
    SC DELETE SSDPSRV
    
    sgwill : Why do you not recommend that?
    Lasse V. Karlsen : Deleting the SSDP Discovery Service? It is used for detecting and configuring UPnP devices on the local network, you should not delete it. It was just used as an example.
    sgwill : Oooh, I see, yes. I thought you meant deleting services wasn't recommended. Thanks for the answer!
  • sc delete name

  • Use services.msc or (Start > Control Panel > Administrative Tools > Services) to find the service in question. Double-click to see the service name and the path to the executable.

    Check the exe version information for a clue as to the owner of the service, and use Add/Remove programs to do a clean uninstall if possible.

    Failing that, from the command prompt:

    sc stop servicexyz
    sc delete servicexyz
    

    No restart should be required.

  • Here is a vbs script that was passed down to me:

    Set servicelist= GetObject("winmgmts:").InstancesOf ("Win32_Service")

    for each service in servicelist

    sname=lcase(service.name)

    If sname = "NameOfMyService" Then

        msgbox(sname)
        service.delete ' the internal name of your service
    

    end if

    next

  • If they are .NET created services you can use the installutil.exe with the /u switch its in the .net framework folder like C:\Windows\Microsoft.NET\Framework64\v2.0.50727

  • http://letmehelpyougeeks.blogspot.com/2009/01/deleting-windows-service.html

Determine the name of the local Administrators group in Vista

How can I determine the name of the local Administrators group in Vista? This can vary depending on the operating system language.

From stackoverflow
  • Look it up by the well known SID.

    In .NET you can use the enum value: System.Security.Principal.BuiltinAdministratorsSid

    In Win32 you can use the enum value: WELL_KNOWN_SID_TYPE.WinBuiltinAdministratorsSid and see MSDN for details.

  • As Richard proposes, use the wellknown sid to find the group.

    var adminGroupSid = new SecurityIdentifier("S-1-5-32-544");
    var adminGroup = (NTAccount)adminGroupSid.Translate(typeof(NTAccount));
    var adminGroupName = adminGroup.Value;
    

PDF wrong error in IE6 and IE7 with https

Response.Write("<script language=\"javascript\">window.open( with https and pdf

What we do in a Asp.Net 1.1.4332 application is the following:

a button triggers a server event that does some processing and puts the data in a session object after that the following code is executed :

string page = Request.ApplicationPath + "/ApkRapportPage.aspx";    
Response.Write("<script language=\"javascript\">window.open('" + page + "','_new');</script>");

this opens a page that streams a pdf to the new browser window

basically with the following code ( I know stuff is missing here, but that doesn't really mater for the question)

byte[] pdfbytes = Convert.FromBase64String(rapportB64);

Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
Response.ContentType = GetContentType(format);
string header = GetContentDispostionHeader(fileName, format, type);
Response.AddHeader("Content-Disposition", header);
Response.BinaryWrite(pdfbytes);   
Response.End();

Okay this code works !

Just not in IE6 and IE7 when using HTTPS

When using IE6 with HTTPS it results in a save-as dialog (not a pdf that opens in a browser) When using IE7 with HTTPS it results in a blank screen When using Firefox it works just fine

If I simulate the extra server side processing in the page_load to put the required data in the session and replace the button with a link that opens the same pdf generating page in a new window, the code works.

For the actual application it is not an option to get the required data before the button is clicked.

So I would really like to get the following code to work

string page = Request.ApplicationPath + "/ApkRapportPage.aspx";    
Response.Write("<script language=\"javascript\">window.open('" + page + "','_new');</script>");

Questions: Does anybody know why this code doesn't work in IE6 and IE7 when using HTTPS ? What is needed to get the code to work ?

Extra info:

  • I tried not using response.write but just a javascript window.open behind the button, this has the same effect
  • when googling for pdf streaming, you can find a lot of people having trouble with this, mostly they set header lengths or other properties or static file compression flags in IIS. I am pretty confident I tried them all.
  • Adobe acrobat reader settings, browser settings or any other client side settings don't seem to be the problem. Tested on different machines, with http works, with https it doesn't.
  • Switching between https and http might have something to do with this, but when I set IE to tell me when I am switching, no switching seems to occur during testing.
  • When replacing the window.open part with a response.redirect then the code also works, just not in a new window

Any help would be greatly appreciated !


As requested the headers, as shown by Fiddler:

   HTTP/1.1 200 OK
   Server: Microsoft-IIS/5.1
   Date: Thu, 05 Mar 2009 14:18:36 GMT
   X-Powered-By: ASP.NET
   X-AspNet-Version: 1.1.4322
   Content-Disposition: Inline;filename=APKrapport.pdf
   Cache-Control: private
   Content-Type: application/pdf; charset=utf-8
   Content-Length: 28307
From stackoverflow
  • Getting attachments to open the way you want has everything to do with the headers you send. If you locate to an .aspx page that you want to act as a dynamic PDF resource these HTTP headers become increasingly important.

    This website states a number of reasons why it might not work in IE.

    1. Set the content-type of the response to "application/pdf", ex. response.setContentType("application/pdf");
    2. Add a dummy parameter on the end of the url, like: http://x.y.z/DoGenCompStmt?filename=dummy.pdf because IE ignores content-types, so you need to give it a hint, and the ".pdf" extension is an easy way.
    3. Set the "content-length" on the response, otherwise the Acrobat Reader plugin may not work properly, ex. response.setContentLength(bos.size());
    4. An additional thing that seems to help some IE browsers is to also have : response.setHeader("Content-Disposition", "inline;filename=somepdf.pdf");

    EDIT: since you already tried all of the above i can only point you to the rfc for content disposition which to my knowledge is the only way to tell a browser how to deal with binary content.

    EDIT: what would really help is to see the HTTP Headers it currently returns when you try to open the pdf in the browser. Fiddler does a great job at catching traffic

    KeesDijk : Yep, thanks for the effort. But I tried all that.
  • You'd be better off using a generic handler (.ASHX) to serve this sort of content, rather than trying to force a web-page to serve content other than HTML.

    KeesDijk : Thanks for the suggestion. I just tried this and it looks like a cleaner solution. It doesn't solve my problem though. The result is the same.
  • After a lot of trial and error I found a working solution, still not sure why the other code doesn't work.

    This code works:

    StringBuilder js = new StringBuilder("<script language=\"javascript\">");
    js.Append("_window = window.open(\"\",'_new');");
    js.Append("_window.document.open(\"application/pdf\");");
    js.Append("_window.location.href = \"ApkRapportPage.aspx\";");  
    js.Append("_window.document.close();");
    js.Append("</script>");
    
    Response.Write(js.ToString());
    

    Must have something to do with the mime type.

    It has a problem though. When IE is set to show when you switch between HTTP and HTTPS this code will give that message twice. The following code doesn't switch but causes the page load of ApkRapportPage to be fired twice.

    StringBuilder js = new StringBuilder("<script language=\"javascript\">");
    js.Append("_window = window.open(\"ApkRapportPage.aspx\",'_new');");
    js.Append("_window.document.open(\"application/pdf\");");
    js.Append("_window.location.href = \"ApkRapportPage.aspx\";");  
    js.Append("_window.document.close();");
    js.Append("</script>");
    
    Response.Write(js.ToString());
    
  • If you are getting a blank page when trying to view a PDF inline in the IE7 browser and you are using Acrobat version 6. Update your Acrobat version to resolve problem.

  • Note that this problem is unrelated to HTTPS, the same problem (and the same fix) applies for HTTP.

    The fix works because the problem with IE is that it doesn't display PDF in a script-opened window if the PDF is loaded at once. (Unknown why, but this is the core of the problem, and the fix.)

    KeesDijk : No it is not. The specific sample in the question worked in HTTP and not in HTTPS. Maybe in some cases that with http you have a different problem that can be solved in the same way, but the original problem only occured with HTTPS.

how to pass an array of object (Users in my case) to jQuery script from controller

I can't understand how to use variables initialized in the controller, for example, to jQuery script (autocomplete in my case). So I'm using Rails and get my authors list. How can I refernce them in jQuery script where I' d like to use jQuery autocomplete plugin like that:

[code] $(document).ready(function() { $("#book_author").autocomplete(url or data, options ); }); [/code] So I should pass my authors array from the controler to the script. How to do that?

From stackoverflow
  • You can do it like this.

    <script type="text/javascript">
      var authors = <%= Author.find(:all).to_json -%>;
      $(document).ready(function() { 
          $("#book_author").autocomplete(authors, options ); });
    </script>
    

    The Json string will be evaluated directly in JavaScript as an object. The end result will in this case be something like

    var authors = [{"author": {"id": 1, "name": "John"}}, {"author": {"id": 2, "name": "Jack"}}];
    

    which will then be an array of objects easily handled in JavaScript. To get it to work with autocomplete you'll probably have to do some more processing though to get it in the format it wants.

    Just remember that the json string will include the model unless you've turned it off with

    ActiveRecord::Base.include_root_in_json = false
    

HTTP request with custom headers fields using Windows Scripts

Is it possible to perform a HTTP Request with specific header fields (like 'referer', 'cookies' or 'User-Agent') using Windows Script Host or any other Windows scripting technology??

Thanks.

From stackoverflow
  • Yes (VBScript) :-

    Dim oWinHTTP
    
    
    Set oWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
    
    oWinHTTP.Open "GET", "http://remoteserver/thing.ext", False
    oWinHTTP.SetRequestHeader "User-Agent", "My Agent String"
    oWinHTTP.Send
    

    Using WinHttp gives you the greatest level of control, you can use MSXML2.ServerXMLHTTP.3.0 if you want more effeciently access any XML DOM sent. Using the standard MSXML2.XMLHTTP.3.0 component goes throught WinINet at gives you the users proxy settings and cookie store etc, but reduces your control over the conversation.

    GetFree : Perfect, thanks.
  • Can we set the request header like Cache-control : 'max-age =10000' using jsp / java? Actually I want to see the previous page with old data on click of browser's back button only if user comes back to this page with in a specified time , say 10 minutes.

    Thanks, Anurag

Mono in linux & windows

Is there any difference in performance when running two executables with mono in linux, if:

1) the one executable has been compiled from c# source code previously in windows (e.g.VS).

2) the other executable has been compiled from the same source with gmcs in linux.

From stackoverflow
  • It shouldn't matter from mono runtime's perspective since they are both valid IL codes (assuming compilers are bug-free).

    There might be a performance difference which can be attributed to the level of optimization done by the C# compiler.

  • Which compiler on Windows?

    I believe gmcs on Windows or Linux will give you the same output.

    If you are using a different compiler (e.g. VS / csc) you will probably have subtle differences

    wilsonlarg : I would like to compare gmcs in linux and VS in windows. thanks
  • I don't think there is any direct performance difference when running same application on Mono in Linux and Windows. There is an indirect performance difference is possible. By indirect I mean performance difference of mono on Linux and Windows.

How do I find my program's main(...) function?

Hi,

I am currently porting a project with a few hundred code files and dependencies onto several third-party libraries to Mac Os. I've finally gotten to the point where the program compiles without warnings or errors, but it does not seem to execute my own main function.

Instead it seems to execute some other main function which seems to belong to a third party. This function writes some diagnostic-looking data to the console and exits afterwards:

(gdb) continue
Current language:  auto; currently c++
//
// This is an automatically generated file.
// Do not edit.
//

const unsigned short expTable[] =
{
    0x3c00, 0x3c00, 0x3c00, 0x3c00, 0x3c00, 0x3c00, 0x3c00, 0x3c00, 
...
    0x3c00, 0x3c00, 0x3c00, 0x3c00, 0x3c00, 0x3c00, 0x3c00, 0x3c00, 
};

Debugger stopped.
Program exited with status value:0.

I can't use the debugger to find out where this main function resides because, while the stack trace seems valid, gdb doesn't show me the correct line number and file name for each stack entry (See this unsolved question for details).

The search took several minutes to complete, but did not return any results.

My project is using SDL among other libraries, but I am award of SDL_Main() and the underlying problems and have built my project on top of a perfectly fine working SDL project template. So I am quite sure that my own main function is valid.

Do you have any idea what might be going wrong? I'm currently out of ideas on how to find and remove the rogue main function.

Thanks,

Adrian

EDIT: As I just found out, I made a mistake while searching file files with the string "This is an automatically generated". I just found several dozen files with the same string, all belonging to FreeImage, one of the third party libraries I am using. So, the problem seems to be related to FreeImage, but I am not still not sure how to proceed since I have compiled Freeimage as a library with the enclosed MacOs makefile and included only the library. I will try to rebuild a newer version of FreeImage and see it if that fixed my problem.

From stackoverflow
  • Did you try running your executable through nm? It might be able to give you some hints. I wouldn't think it'd be possible to link a program with more than one globally visible function named main(), not sure how that manages to happen.

    Adrian Grigore : I just did. There is only one main function defined. I also noticed that nm locates the main function at a different address than gdb. It might be the right address, but I am not sure how to verify.
  • Could it be an initializer for a static object that fails before your main() is called?

    Martin York : i.e. The constructor of a global object (to the uninitiated). +1
    Adrian Grigore : Very well possible, but with a few hundred code files, how can I tell?
    Martin York : Run it in the debugger. Put a break point in terminate(). See where terminate gets called from.
  • I'm not sure how to find the other one, but you can specify your own entry point explicitly and make the other one unused. You can use the GNU linker ld -e option to set your entry point.

    -e entry

    --entry=entry

    Use entry as the explicit symbol for beginning execution of your program, rather than the default entry point. If there is no sym- bol named entry, the linker will try to parse entry as a number, and use that as the entry address (the number will be interpreted in base 10; you may use a leading 0x for base 16, or a leading 0 for base 8).

    For future readers, if you have this problem in Windows. The equivalent linker option is /ENTRY.

  • Look through the header files that you include and see if there isn't a define that remaps main to something else. This is an old trick to ensure that a library's main function is called first to do some set up. Generally, it will eventually call your main function by referring to the redefined value.

    Adrian Grigore : I know that SDL does this (that's what I mean with SDL_Main(), and it would seem that FreeImage does so as well. I'll try to find something like this in the FreeImage sources.
  • A quick hack:

    readelf -s -w my_bin_file > temp.txt
    

    Open temp.txt, search for main (with FUNC in one column) Go up until you find the first FILE column - this is the file with the linked main.

    edit: This only works on GNU Unix flavors and friends. OS X uses the Mach-O format, not ELF.

    Adrian Grigore : This looks great, but I am using MacOS X and I could not find any readelf sources. I guess readelf usually comes preinstalled on with linux distros?
    Gilad Naor : Yes, it comes with linux distros. I don't have access to a Mac right now. You can probably install it with fink.
    claferri : with mac port, a port search readelf returns nothing.
    Gilad Naor : My mistake. OS X doesn't use ELF. You might check this article: http://0xfe.blogspot.com/2006/03/how-os-x-executes-applications.html I didn't read it yet, but it may have useful information.
    Craig S : FYI: On the Mac, you can use nm or otool, as epatel outlines in another answer here.
    Gilad Naor : Thanks for the tip. +1 for epatel
  • I know that in C, you can have a different entrypoint called before the main function, that could be an idea. The code usually looks like :

    void __attribute__ ((constructor)) my_main(void);
    

    Maybe you can search for something like that in your code.

    In C, there is also different ways to catch the main function and call it after the "real" main. Some threads library have this kind of hacks in order to "prepare" the environnement, scheduler and stuff like that.

    This is not really usefull but this may explain why your main isn't called at all.

    Hope this helps!

  • Do you have several main in the binary? Try using nm on it. (it shouldn't be possible as ld won't link with duplicates, but go into the dynamical libs and look for _main there)

    nm a.out | grep -5 _main
    

    This should give 5 lines before and after any _main found in the binary a.out

    If you have several, see the surrounding symbols for hints which parts they are in...

    Next step can be to do the same on each dynamic lib that is used. To get a list of the used dynamic libraries use otool

    otool -L a.out
    
  • Another note.

    WxWidgets do also define their own main

    From here

    As in all programs there must be a "main" function. Under wxWidgets main is implemented using this macro, which creates an application instance and starts the program.

    IMPLEMENT_APP(MyApp)

  • It looks like you can have a file called b44ExpLogTable.cpp compiled into your binary or some thirdpart library. It looks like that little program is to generate a exp() table but has somehow come to be imported into your project(s)

    See this and this in FreeImage sources

  • Generate a map file. Most programs don't actually start at main. A mapfile from GCC should tell you the address of __start or __executable_start, which you should be able to break in and step through to see what's causing your program to exit.

    Adrian Grigore : Unfortunately this doesn't work if the debugger is not working...
    epatel : I think he means that you add "-map my_map_file" to the final link command. If "c++" or similar is used you can use "-Xlinker -map -Xlinker my_map_file"
    Dan Olson : Even if you can't use GDB (which you can, it just doesn't line up with your source)... whenever you want to see what's in your executable you generate a map file. Whenever you want to see what's going on, you break on program entry and step through. Even if you have to do it in assembly.