Setting the Default Printer in .NET

 
The following C# code shows how to use WMI to query printers information, set and get default printer.
public bool SetDefaultPrinter()
{
    System.Management.ManagementObjectSearcher search = 
default(System.Management.ManagementObjectSearcher); System.Management.ManagementObjectCollection results =
default(System.Management.ManagementObjectCollection); System.Management.ManagementObject printer =
default(System.Management.ManagementObject); search =
new System.Management.ManagementObjectSearcher("select * from win32_printer"); results = search.Get(); //Get Default Printer System.Management.ManagementObject defaultPrinter = null; foreach (System.Management.ManagementObject foundPrinter in results) { System.Management.PropertyDataCollection
propertyDataCollection = foundPrinter.Properties; if ((bool)foundPrinter["Default"]) // DEFAULT PRINTER { System.Diagnostics.Debug.WriteLine(foundPrinter["Name"]); System.Diagnostics.Debug.WriteLine(foundPrinter["Location"]); } } //Sets new default Printer foreach (System.Management.ManagementObject foundPrinter in results) { System.Diagnostics.Debug.Print(foundPrinter["Name"].ToString()); if (foundPrinter["Name"].Equals("PDFCreator")) { System.Management.ManagementBaseObject outParams =
foundPrinter.InvokeMethod("SetDefaultPrinter", null, null); if (outParams == null) System.Diagnostics.Debug.WriteLine("Unable to set default printer"); Int32 retVal = (int)(uint)outParams.Properties["ReturnValue"].Value; if (retVal == 0) return true; else return false; } } return false; }

AutoCAD VBA Migration to VB.NET or C#

AutoCAD 2010 will not be supporting VBA.

Quoting

“If you utilize VBA macros in your work environment, they will no longer work unless the VBA module is installed on your system. “
“When you run a command that requires VBA, a message dialog box will be displayed stating that VBA is no longer installed with AutoCAD and directing you to a website where you can download the VBA module. “

And also you can see that Autodesk states: “Autodesk is evaluating how long VBA will be supported in Autodesk products in the future. Though supported in the AutoCAD 2010-based products, it may or may not be supported in future releases. Therefore, it is strongly recommended that VB developers develop all new code using VB .NET.

VBA does not support 64bit systems in a native way.

But If you want some advice from the VB migration experts or help on your migration project from VBA to VB.NET or C# you can us contact Artinsoft Migration Services.

We build the VB Upgrade Wizard that shipped with Visual Studio and have been doing VB migrations for years.

ColdFusion 8 and JRockIt

15. June 2009 18:41 by Mrojas in General  //  Tags: , , , , , , ,   //   Comments (0)

JRockIt is an interesting Java Virtual Machine. I really admire the technology used in it. Well following Mike’s post about Memory Leaks in Coldfusion http://www.schierberl.com/cfblog/index.cfm/2006/10/12/ColdFusion_memoryLeak_profiler I was trying to configure the JRockit JVM to do some profiling on an important application.

But alas. Time just flies and things have change a lot since Mike wrote that post. So this is basically an update:

1) JRockit must be downloaded from: http://www.oracle.com/technology/software/products/jrockit/index.html You must accept the license and also have an OTN Account (this is a free process). Download the right version for your platform. I tried the x86 version on my 64 bit server and it didn;t work, so use the version that fits better to your platform. However there is no 64 bit client version of Memory Leak and all the other nice client tools. But dont worry. Download both version 64 and 32 bits versions. You will use the 64 version for your server and the 32 bit version for monitoring.

2) Stop coldfusion server

3) Modify the jvm.config file. In my case it was in: C:\ColdFusion8\runtime\bin\jvm.config

comment out old java.home and add a new line like:
java.home=C:/Program Files/Java/jrmc-3.1.0-1.6.0/jre

In the java.args setting, remove parameter –Xbatch (dont know why, it just didnt work)

add a parameter like:
-Xmanagement:ssl=false,authenticate=false,autodiscovery=true

*In my case I also had to disable security in C:\Program files\Java\jrmc-3.1.0-1.6.0\jre\management\management.properties with a line like:

com.sun.management.jmxremote.authenticate=false

4) Re start coldfusion

Migration to 64-bit: ODBC

5. December 2008 06:20 by Mrojas in General  //  Tags: , , , , , ,   //   Comments (0)

Most people migrating their application want to move ahead and take advantage of new technologies and new operating systems.

So if you had a VB6 application and you migrated it with us to .NET we will recommend and automate the process to use ADO.NET.

Why?

You can still use ODBC but i will list some compelling reasons:

* There a very fast ADO.NET drivers available. Using ODBC implies addind an interop overhead that can affect performance.
* Some vendors do not support and/or certify the use of ODBC drivers for .NET. So in those cases if you use ODBC your are on your own.
During my consulting experience I have seen several problems using ODBC drivers ranging from just poor performance, problems with some SQL statements, stored procedures calls, database specific features or complete system inestability.
* and also problems running in 64-bit.

This last one is very concerning. If you made all the effort to migrate an application to .NET and run it on for example on a Windows 2003 64 bit server it wont be able to use your 32-bit ODBC drivers unless you go to the the Build tab, and set Platform Target to "x86".

This is very sad because your application cannot take advantage of all the 64 bit resources.

If you are lucky enough you might find a 64 bit version of your ODBC driver but I will really recommend going straigth to 64-bit and use ADO.NET. And that's exactly what we can really help you to do specially in our version 2.2 of the VBUC.

 

Quoted by El Financiero on an article about moving to 64-bits

30. August 2007 10:45 by Jaguilar in General  //  Tags: , ,   //   Comments (0)

Some time ago I was interviewed (via email) by El Financiero, a weekly business-oriented newspaper from Costa Rica, regarding 64–bit technologies. A small quote from the interview was published a couple of weeks ago, along with some information I gave them on the advantages of moving to 64–bits.

The technical journalist from the newspaper did an article on how the Costa Rican Central Bank, BCCR, is moving their payments system (SINPE) from 32–bit to 64–bit servers, and the benefits they are getting from the move. These benefits include enhanced speed and database performance, given the large memory capacity of the new architecture. This is a fairly large system that handles over 3 million financial transactions per month.

ArtinSoft had some involvement in moving this system from Visual Basic 6.0 to Visual Basic .NET some time ago, in the dawn of the .NET era. There is even a published case study on the system – you can find it here.

Their plan currently is to slowly move all their systems to 64–bit over a period of 2 years.

You can check out the article here:  BCCR ajustó tecnologías (you may need to be registered with the site).

HP Integrity Developer Workshops next month in NJ

14. May 2007 10:31 by Jaguilar in General  //  Tags:   //   Comments (0)

Next month we’ll be at the last planned HP Integrity Developer Workshop, in East Rutherford, NJ, between June 12-14. We’ll be in charge of the Windows 64–bit track.

This is the last workshop planned for this year, so make sure you take this opportunity to get hands-on training with HP’s Integrity Servers using Dual-core Itanium CPUs. You can choose to receive training in either Windows, Linux, HP/UX or OpenVMS, and get help with your ports to the Itanium platform. Plus you get to take back home the server you worked on! Check out the benefits from the class (from the Workshop Overview):

  • your dual-core Itanium-based application porting efforts well underway or in many cases, completed.
  • The HP Integrity rx2620 server that you used in the classroom sent directly to you from the workshop for your continued porting and testing efforts.
  • free software development tools
  • membership in HP's Developer & Solution Partner Program that allows you to take advantage of GTM and lead generation programs once your port is completed.

Make sure you reserve your spot for the workshop!

HP Developer Workshops - Long Beach, CA

1. March 2007 04:58 by Jaguilar in General  //  Tags:   //   Comments (0)

The first HP Integrity Developer Workshop for 2007 is coming up in a couple of weeks. It will be held in Long Beach, CA, on March 13-15.

In this workshop you get 3 days of training in your OS of choice (HP/UX, OpenVMS, Linux or Windows), plus an HP Integrity rx2620 server with the new dual core “Montecito” Itanium chip. It is an excellent deal, so make sure to check out the Workshop overview and the agenda (PDF link) and reserve a space today!

HP and Intel Developer Workshops - Atlanta

12. October 2006 12:44 by Jaguilar in General  //  Tags:   //   Comments (0)

There’s going to be a new HP and Intel Developer Workshop in Atlanta in a couple of weeks, on Oct. 24–26. As with the previous workshops, we will do the classes for the 64–bit Windows track.

This is the last workshop for this year. That means that is the last oportunity this year to get this hands-on traning AND an Itanium machine!!

Multicore lab Thread Checker mystery error... solved!!

9. October 2006 04:08 by Jaguilar in General  //  Tags: ,   //   Comments (0)

Some of you may recall that on some events, we got an error message on Intel Thread Checker during the Multicore lab. No matter what we did, even if we solved all the concurrency issues related to our code, the Thread Checker would always log this message:

Write -> Read data-race Memory read at [PrimesInstrumented.exe, 0x2468] conflicts with a prior memory write at [PrimesInstrumented.exe, 0x16816] (flow dependence)

During the labs, we have said that we've been working out the solution with the Intel support people - and now we have an answer!!The thing is that you can work with Thread Checker in two ways:
  1. Use compiler based instrumentation. With this, you basically need to add the /Qtcheck flag to the compiler command line to instrument the binary. Once it is instrumented and you run it, it will create a file called "Threadchecker.thr", that you can then load in the VTune Thread Checker. To do this, you need to use the following command lines: (using the primes example from the lab)

    icl /c /Zi primes.cpp /Qopenmp /Qtcheck /Od
    link primes.obj /out:PrimesInstrumented.exe /fixed:no /DEBUG


  2. Use Thread Checker to intrument the application. In this scenario, you don't intrument the binary at compile time, but have Thread Checker intrument it when running the application. For this, you need to build the application with the following command lines:

    icl /c /Zi primes.cpp /Qopenmp /MD /Od
    link primes.obj /out:PrimesInstrumented.exe /fixed:no /DEBUG


    And then load it in Thread Checker.

The error we were doing on the lab is that we were using both compiler and "Thread Checker" instrumentation, and that caused Thread Checker to report conflicts that are outside of the program and in the runtime libraries. Now, using either option (BUT not both at the same time) the strange error is gone!

Thanks to Vasanth Tovinkere at Intel who really helped us out with this problem!!

BTW, this is repeating an old blog post I did for the 64–bit Advantage Blog. The post was deleted for some reason. Since I consider this information to be important, I am re-posting it here.

OpenMP on Visual Studio

5. October 2006 08:57 by Jaguilar in General  //  Tags: ,   //   Comments (0)

You can create C++ application in Visual Studio that use OpenMP. When you run an application created with OpenMP and VS.NET, however, you may get this annoying error message: “This application has failed to start because vcompd.dll was not found. Re-installing the application may fix this problem.”:

omp-error

When we tried this, we were puzzled by this error message, especially since it works with the Intel Compiler flawlessly. Well, it turns out that you need to include omp.h in your files ALWAYS when you use OpenMP from Visual Studio. This is not required on other compilers if you’re only using the OpenMP pragmas, but it is an issue with Visual Studio.

Thanks to Kang Su for pointing this out in his blog – I was going crazy trying to figure out what was wrong.

Also remember to enable OpenMP support in the C++ Project properties. This setting is in Configuration Properties->C/C++->Language->OpenMP Support.

OpenMP is your friend

4. October 2006 08:42 by Jaguilar in General  //  Tags: ,   //   Comments (0)

OpenMP is very easy-to use API that you can use to very rapidly add multi-threading to your C/C++ applications. OpenMP allows you to parallelize the execution of a region of code by just adding a few pragmas to the code. For example, take this code:

   for(int i = 0;i<=100;i++){
       a[i] = a[i]*10;
       ...
   }

The code above performs a for loop sequentially. Since each iteration could be executed independently, we can easily add multi-threading to the application by adding these simple pragmas:

#pragma omp parallel for
   for(int i = 0;i<=100;i++){
       a[i] = a[i]*10;
       ...
   }

The omp pragmas tell the compiler to generate code to parallelize the execution of the for loop. That means that if you run this code on a 4 core machine, it will create 4 threads, and each one will execute 25 iterations of the loop. Just by adding those pragmas, you now have a multi-threaded application that takes advantage of multi-core systems.

Yes, it's that simple.

HP and Intel Developer Workshops - Boston

8. August 2006 18:14 by Jaguilar in General  //  Tags:   //   Comments (0)

There’s a new HP and Intel Developer Workshops coming up in a couple of weeks. This one is going to be in Peabody, MA (close to Boston), between August 22–24. We will be teaching some of the lectures in the 64–bit Windows track.

These workshops provide a great opportunity for you to get hands-on experience on Itanium machines. We will also have open lab time so you can start porting your application to the architecture – and remember that we are going to be around to help you with your efforts.

HP virtualization support for Itanium

27. July 2006 09:50 by Jaguilar in General  //  Tags: ,   //   Comments (0)

Last I week I posted about the Itanium 2 9000 Series being launched with hardware virtualization support (what was formerly known as Silvervale). I also mentioned that neither Windows 2003, Virtual Server, nor Longhorn will support virtualization on this platform. That much is true from Microsoft’s perspective, but HP is indeed planning to support Windows 2003 Server through its Virtual Server Environment.

The Virtual Server Environment has been available for a while, and also has an enterprise-class management tool in the HP Integrity Essentials Virtualization Manager. This is currently available for HP-UX, but will also be available for Linux and Windows in the near future. The Virtualization Manager has some interesting features, and is also integrated with HP’s Serviceguard product. From last month’s press release:

... For example, customers can use the capability to automatically allocate additional server capacity to financial applications during the month-end close.

For customers that are concerned about the availability of their mission-critical UNIX® environments when they consolidate using virtualization, HP has further integrated HP Serviceguard for HP-UX 11i with HP Integrity Virtual Machines. Available now with the latest release of HP Serviceguard, this functionality helps guard against failure by automatically moving the virtual machines between servers in a VSE. HP Integrity Virtual Machines also now enables easy manual migration of virtual machines, accelerating application qualification and deployment....

 Keep in mind that HP also offer Node Partitions (nPars) and Virtual Partitions (vPars) options on the high-end Integrity and 9000 lines of servers, with Instant Capacity on Demand (iCOD) capabilities. Depending on your requirements, these may be even better options than virtual machines pure virtual machines.

A post on Virtualization

20. July 2006 12:19 by Jaguilar in General  //  Tags: ,   //   Comments (0)

This is a post from several months ago that I made on the 64–bit Advantage blog. Since now we’re working with virtualization (at the time it was only an interest of mine), I think it is worth it to re-post it here: 

I wanted to make a brief mention of the Virtualization Technology that is being introduced in the latest generation of Intel CPUs (known as VT-x). This technology was formerly known as "Vanderpool", and it is already available on some Pentium 4, Pentium D, Xeon and Core Duo CPUs. Later this year it will also be available on the next generation Itanium CPUs, using a technology known as "Silvervale".

I was talking with a coworker the other day about this technology, and our main question was "What is it exactly that it does? What advantage would it have over traditional software virtualization?" Well, to answer these two questions:

On a virtualization environment, there's the Virtual Machine Monitor (VMM), which handles the processor and physical resources of the machine, and the Guest Software, which operate inside a Virtual Machine handled by the VMM. VT-x introduces 10 new intructions to the architecture for facilitating the tasks of the VMM. Some of them, such as VMLAUNCH and VMRESUME, allow the VMM to start/enter running VMs, or VMON/VMOFF, turns the Virtualization functionality on and off.

The main reasons for using VT-x over software virtualization are speed and reliability. With hardware support, you are pretty much creating the equivalent of a hardware partition for the Guest Software, which improves both the performance and the robustness of the VM - and this is vital for consolidated server environments, one of the areas where VT-x is expected to be heavily used.

Now, one thing- why mention Intel's VT-x on this site? Well, one of the strenghts of 64-bit computing is that with more resources available on a single box, it is easier to to consolidate servers. With the new support for virtualization on the CPUs, you can use Virtual Machines for consolidation, so each software server has its own isolated environment without sacrificing performance.

 More information here.

Montecito... err, Dual-Core Itanium 2 9000 series finally released

19. July 2006 16:25 by Jaguilar in General  //  Tags: , ,   //   Comments (0)

After several years of delays, the Dual-core Itanium 2, formerly known as Montecito, was unveiled by Intel. According to the press release:

They double the performance and lower energy requirements, improving performance per watt by 2.5 times compared to existing, single-core versions.
The Dual-Core Intel® Itanium® 2 processor 9000 series delivers performance at a system scale unmatched by competing RISC architectures. It set world record results in several key server benchmarks including a score of 4230 SPEC_int_rate_base_20001, nearly triple the previous record.

The CPU incorporates virtualization features, similar to the ones found on current-generation Intel x86 CPUs. My understanding is that neither Windows 2003 Server nor Viridian will support VT on the Itaniums, but my guess is that other vendors will, especially with the enhanced CPU horsepower and memory capability of this boxes.
Also, according to the press release, the Itanium Solutions Alliance is working on new system and applications that will leverage the power of this new CPU. We've worked with the ISA in the past, for the Developer Days events,  in which we showed ISV how to port and optimize their applications for 64-bit Windows.

Link to the press release: New Dual-Core Intel® Itanium® 2 Processor Doubles Performance, Reduces Power Consumption 

64-bit Windows Server migration stories

3. July 2006 09:57 by Jaguilar in General  //  Tags: ,   //   Comments (0)

We’ve been working during the past two years on 64–bit awareness and helping customers move to the platform. I posted some time ago, on the 64–bit Advantage blog, about the migration of MySpace to 64–bit Windows Servers. Well, I just noticed that there is another story out (has been out for a few months, actually) about the migration of microsoft.com to x64 servers. Pretty interesting read. Take a look at the performance improvements they saw – they were impressive, especially the improvement in the response time.

You can read check it out here.

Pictures from the Santiago Event

29. June 2006 11:28 by Jaguilar in General  //  Tags:   //   Comments (0)

Here are some pictures of the event last week in Santiago.

Asistentes al Evento 4 Asistentes al Evento 2

 Asistentes al Evento 1 Jose presentando 2

 BTW, this is my first post with BlogJet. Nice tool.

Santiago, Chile, 64-bit Advantage event

29. June 2006 08:10 by Jaguilar in General  //  Tags: ,   //   Comments (0)

Last week we had the final scheduled 64-bit Advantage event in Santiago, Chile. It was an incredible success. The people and organization were really happy with the results. It is a shame that there are very few events like it in Latin America

One of the things that really caught my attention was the fact that there was a well-known (not to us) Linux user/advocate in the audience. The good thing is that he gave us a very positive review for the event, and mentioned that he was surprised of the professionalism we displayed when confronted with cross-platform questions, and how we even address the availability of certain technologies on other platforms (such as POSIX Threads, polymorphic types, etc).

By the way, if you have a chance, go and visit Santiago. It is a beautiful city, the people are amazing, and I can't even start talking about the food, especially seafood. Just remeber to visit Costa Rica first, of course. :-)

Thanks to Christian, Wilson, José, Katina, and the rest of the organization for the hard work and dedication that went into making this event happen!!

HP and Intel Developer Workshop in Seattle

29. May 2006 05:29 by Jaguilar in General  //  Tags: ,   //   Comments (0)

In a couple of weeks I'll be teaching some of the lessons at the HP and Intel Developer Workshop in Seattle, WA. The workshop will take place on June 13-15. As with the previous workshop, in Dallas, this is a great oppotunity to port your code to 64-bit windows on the Itanium platform. You'll be surprised that it may be easier to port your source code than it looks - in Dallas we had a guy that ported his code in about an hour! Then again, we've been working with a company for about two years on the port - can't tell you who it is, but if you knew, you'll see why it is taking so long.

The Workshop has all sorts of nice perks. In addition to the quality training given by yours truly and my coworkers, you can also also take with you the Itanium server that you use during the class. You can read all the benefits about it on the Workshop's web page.

Dallas Workshop Wrapup

13. April 2006 00:55 by Jaguilar in General  //  Tags:   //   Comments (0)

The 64-bit workshop in Dallas last week was a great success. We had 7 people porting their applications to Itanium systems. Of the seven, three managed to port their apps - one was a C# application that was ported in 15 minutes!! Another participant ported his C++ application to Visual Studio .NET 2005, but didn't have the Itanium compilers installed. So let's make it 3.5 ports. :o)

So we can say we had a 50% success rate. Great workshop, can't wait for the next one!!

Categories