Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Wednesday, April 17, 2013

Tips on using Microsoft Office

Here are two tips on using Microsoft Office. I use Microsoft Office at work on various works, including support and development documentations. Office documentations are common way to communicate at work.

The first tip is a simple one. In many cases, we need to copy content of an Excel cell as text. If you use normal copy by control+C key, actually you will get some extra information. This results in formats or extra carriage return be pasted. To copy text only, you can select text in the top input area next to toolbar items. Copy the text there will only get plain text only.

The second tip is about Word file. I like to use style to format text in word documentation. The style is something like css classes. You change one style, and all the text assigned with the style will be changed automatically. The second advantage is to layout the documentation by styles, such as title, heading 1, heading 2 and so on.

In the toolbar area, there one dropdown box for existing or current used styles. This list does not list all the predefined styles there. It is tedious to enable all the styles. One thing I noticed is that the dropdown box is editable. You can type in a style name. If it exists, it will be loaded. For example, Title is not normally in the list, but you can type it to bring it out. This is very handy way to use styles you remember.

Those are two very simple ones, but I use them very often.

Read More...

Wednesday, November 28, 2012

OPC and DCOM/COM Issues

My working experience with OPC and DCOM/COM can be tracked back to more than 10 years ago. I remember that when I was working at a SCADA software company in Calgary, I was assigned to a project to write OPC Client app. OPC technology is based on Microsoft Windows DCOM/COM infrastructure to provide automation for industries. At that time, it was very advanced technology and has been quickly adopted by many industry companies, specially in SCADNA system.

Since then, I have been on and off on OPC development and support. Even COM was very nice library based design infrastructure, it has it is drawbacks. Microsoft has been moved to .Net based infrastructure, COM and DCOM becomes old technology. However, so many software and applications have been developed and they are in use in various systems, it is really hard to cut it off.

Recently I have been working on a project to build a new historian system. The system is based OPC technology. In the past week, I have been working to set up a new historian system. I expected OPC configuration being the hardest task. Basically, an OPC client application has be set up to communicate with a remote OPC server. I have been struggled for almost a week on the project. I almost reached the point to make them to talk. The OPC client could talk to the remote OPC server by using local Administrator, but not a domain user. The DCOM settings on the OPC server side should be OK since we have a production OPC Client collecting data. It is just a new Windows 2008 Server not being able to collect data. Windows 2008 Server is a kind of Windows Vista, which is based on a more complicated secure framework, such as firewall, network configuration and system security configurations, in addition to OPC configurations.

My past experience and my knowledge in this area still benefit me a lot for my current work. I have changed my careers in a wide range of areas. Never know what you have done may continue to impact your future.

Read More...

Wednesday, October 03, 2012

VIM Tips

Recently I was working on a project to set up a new server. The new server is a replacement of existing one. One of issues I tried to resolve is to migrate permissions from the existing server to the new server. The problem is that there are too many folders to be checked, 4k folders. I need to find a way to export permissions for each folder to a text file.

Quickly I found a command to get permissions:

cacls.exe folderName

It was very nice to find out this command. Then I use Tree to export folders to text file and edited the text file as a batch file. This is a simple batch file, but a long list of folders.

@cacls folder1 > perm.txt
@cacls folder2 >> perm.txt
...
@cacls folder4000 >> perm.txt

I encountered a problem. Some of path was wrong. I think I may missed some parts of their paths. To find out which one is not valid is a challenge. I need to find a productive way to do that. I knew the following command is a convenient way to detect valid path:

@IF NOT EXIST %folder1 ECHO %folder1

I used VIM to help me to create another batch file based on my above batch file. I used the following VIM replacement command to trim my batch file:

:%s/@cacls //g
:%s/ > perm.txt//g
:%s/ >> perm.txt//g

Those are simple VIM find and replace commands. Now I have a list of paths left:

folder1
folder2
...
folder4000

Then I use find and replace with group command to repeat folders with ECHO command:

:%s/\(.*\)/\1 ECHO \1/g

where \(xxx\) is a group. Finally I insert prefixing IF command at each line the the command:

:%s/^/@IF NOT EXIST /g

where ^ is the beginning of line. With above commands, my new batch file was created.

@IF NOT EXIST folder1 ECHO folder1
@IF NOT EXIST folder2 ECHO folder2
...
@IF NOT EXIST folder4000 ECHO folder4000

Soon I found invalid folders and quickly I fixed my scripts.

Read More...

Friday, September 28, 2012

Open Excel File by Double Click

Recently I had experience a problem at work. I cannot open Excel files by double click them. I tried to open from Excel Open menu and it works fine. I have no problems to open other files such as word or txt files.

I checked my other colleagues and they don't have the issue. One of my friend recommended me to find solution from web by googling. Soon I found a solution. This is something related to Excel registry settings. Since the complexity of Windows registry, it is not recommended to directly edit or change settings there. I found that there is file association from File Explorer. Here is what I did.

First, open File Type from Tools menu, locate the XLS (notice the upper case):



Click Advanced button, the following dialog is displayed.



Select Open in Action list. Click on Edit button:



Make sure to clear Use DDE, then click OK. Apply changes. This will be double click on Excel default behavior back.

Reference


Read More...

Saturday, August 18, 2012

Scrollbar in Mac OS

Since 2007, my interest has been shift to iOS and Mac. One thing interesting UI is scroll bar. Apple has changed the behaviour of scrollbar in iOS. The purpose of this change is to utilize the maximum territory space in a scrollable view. The scrollbar will disappear after the view stays static within seconds. To bring it back, you can user touch gestures to swipe the view. All these are handled by OS. This has been in iOS devices for long time.

Since Lion OS,  Apple introduced the similar support in Mac OS. It is a very interesting design. Here is my understanding. The scrollbars (horizontal and vertical ones) are two UI components. When they are visible, they are UI elements with two main purpose:

  1. They provide visual vision of positions of its content, and
  2. They respond to user interaction, moving or scroll to a position when they are clicked or dragged.
When scrollbars are invisible, not only cannot users see content positions or if content is scrollable, users also have no way to interact with scrollbars. In iOS and Mac native applications, this normally does not present any issue. Users can user touch like swipe to check or move content positions.

However, I had a case recently that invisible scrollbars do cause me some trouble. I use web based RDC to connect to Windows. The RDC window was developed in Java, which is based on Java UI component. It does not support swipe gesture. When I saw a blue window, I had no way to scroll its contents even I knew the Start menu there on the bottom behind the window.


What I found there are two solutions to resolve the issue. The first method method is limit to Mountain Lion OS. Windows in ML are resizable by dragging any boarders. By dragging boarders, the scrollbar will appear for a short period of time. With that period, just quickly touch the scrollbar to make a move.


The second solution is to make scrollbars always visible. This can be set in System Preference | General.



Actually, the scrollbar-always-visible looks really ugly after I am getting used to the new-and-clearn views. However, this solution is the only solution when a window is not sizable.

Read More...

Sunday, May 22, 2011

Create Shortcut in C#

Last week I was working on a case to provide support for an application users. The application has two executables: one is app's main exe like app.exe and another one is for app's update like appUpdate.exe. For this update, we need to add a shortcut on clients machine desktop pointed to appUpdate.exe.

Like a typical shortcut, the one I need to put on client PCs has several settings: target, start in, run mode, icon and comments.



I tried to create a shortcut on my box first. Aftert that, I tried to copy this shortcut file (lnk) to a remote PC. It did not work. It seems that the lnk file some information are embedded in the file. When it is not in the machine where it was created. The machine name appears in the target.

I need a way to create a shortcut on fly. That's why I went to .net to create a simple console app do the job. This time SO helped me with an excellent open source library from a QA: ShellLink.cs. Within the source codes, there are actually two files I need: ShellLink.cs and FileIcon.cs. The library contains a wrapper class for Windows APIs. It is very straight forward.

The only change I made is to add a class level flag for any changes in shortcut properties. If any setter changes a value, this flag is true. Then I'll only save chances for the shortcut if any of properties are changed.

public class ShellLink : IDisposable {
private bool mChanged = false;
....
public string Target {
get { .... }
set { if (!value.Equals(Target)) {
mChanged = true;
....
}
....
}

Read More...

Saturday, August 21, 2010

App Installation as Admin in Windows Server 2008

Today at work, I tried to get help from Capstone on their application work in Windows Server 2008. The application is a 32-based application as a VBS script host with ability to communicate with their ParcView suite. The application has a configuration setting for data connection, by using UDL connection string.

The issue I encountered was that the UDL is a connection to an Oracle database, and it seems that the UDL string cannot be accepted by the application. To cut the story short, Captone's tech support guru finally identified that the issue was caused by Oracle drive installed on this Windows box. The network team at work installed 64-bit oracle driver (Oracle g10), while the application requires the 32-bit driver. Unfortunately, the person who is responsible for the installation is on vacation this week. Therefore, Capstone person helped me to install the Oracle g11 client, 64-version first and then 32-version next.

The 64-version installation went OK. However, we had trouble to install the 32-version. There were several failures during the preparing stage. He finally figured out that he has to run the installation oui as administrator. I saw it so simple to run installer as administrator. Since my log-in name is a member of Administrators group, in Windows Server 2008 (VISA-like Windows), just right click on oui and run it as administrator:



to my surprise, no password was requested. I think it might be Windows Server 2008 and my log-in is in Administrators. Anyway, that reminded me a case I did before: to configure PowerShell Execution settings.

By default, the execution policy for PS is Restricted. I needed to change it to RemoteSigned. However, I could not do it even my log-in name is in Administrators. It seems Windows Server 2008 has strong security. What I did was to make a request to the network team to log in as administrator to run Set-ExecutionPolicy command with RemoteSigned.


When I realized that it was so simple to run installation as admin, I tried PS right afterward.


Now, after I run the PS as admin and I can set policy. That's pretty cool!

Read More...

Saturday, June 19, 2010

Detect Window Form Application Status

notesLast month, I was working, actually fixing bugs to resolve exceptions, and to improve performance, on an application which is a Windows Form application. One feature client wants is to query data from a SQL server periodically and refresh the UI with the retrieved data. The data may not be changed, but there was no inelegance to know if there was change. Therefore, the UI refresh was enforced because clients want to get the most recent data.

During the process to refactory codes to enhance/optimize SQL queries, I realized that clients wants the more recent data because they want to see any changes when the application is in running. There are many cases this kind of refreshing is actually not necessary. For example, when the window form is minimized, or the OS Windows is locked. In many cases, clients just left the application running after their work. Windows is locked, but the application had still been pulling data from the SQL server.

Then I proposed a optimized strategy to stop the data pulling when the UI is not available, either minimized or Widnows is locked. My suggestion was accepted.

Checking Application Status

To find out the Window from's status is very easy. This can be done by checking form's property WindowState. Here are the codes in a Timer's cycle event:

private void timer1_Tick(object sender, EventArgs e) {
if (IsWindowFormActive()) {
// set interval to max
timer1.Interval = int.MaxValue;
Cursor c = this.Cursor;
this.Cursor = Cursors.WaitCursor;

RefreshDataAndViews();

this.Cursor = c;
// save the last update timestamp to timer's tag
timer1.Tag = DateTime.Now;
// if the window is locked, min or inactive, OnPaint() will not be called.
this.Invalidate();
}
else
{
timer1.Interval = int.MaxValue;
}
}

private bool IsWindowFormActive() {
bool bRet = ( !_windowIsLocked && this.WindowState !=
FormWindowState.Minimized &&
this.Visible && this.Enabled);
return bRet;
}

When the Window Form's state is minimized, Windows is locked or the form is not visible, the timer's interval is set to the maximum number of integer. All the status checking is done within the method IsWindowsActive.

Find out If Windows is Locked

There is one class level variable _windowsIsLocked as a flag for Windows lock status. To set this flag, an event is added within the form's CTOR:

class MainForm {
private bool _windowsIsLocked;
...
// CTOR
public MainForm()
{
...
SystemEvents.SessionSwitch +=
new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
...
}
...
void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
{
if (e.Reason == SessionSwitchReason.SessionLock)
{
_windowIsLocked = true;
}
else if (e.Reason == SessionSwitchReason.SessionUnlock)
{
// cause OnPaint event called where timer is reset
_windowIsLocked = false;
}
}

Enable Timer When Application Back to Normal Running Status

When the timer's interval is set to the maximum value of integer, how to bring the timer back to the required cycle interval, such as 2 minutes(120000 milliseconds)? The trick is to overwrite form's OnPaint method.

Make sure the base method is called first. This even is the most intensively called event. Whenever the form is activated, clicked, re-sized or moved, OnPaint will be called. Therefore, it is recommended to avoid any lengthy codes in this method. For my case, what I need to do is to reset the timer's interval if the application is back to normal:

protected override void OnPaint(PaintEventArgs e)
{
try
{
base.OnPaint(e);
int interval = NORMAL_REFRESH_INTERVAL;
object timerTag = Timer1.Tag;
// check if the tag was set?
if (timerTag != null && timerTag.ToString().Length > 0)
{
DateTime dt = (DateTime)timerTag;
long ticks = DateTime.Now.Ticks - dt.Ticks;
TimeSpan ts = new TimeSpan(ticks);
// Is this time interval since last refreshing too long?
if (ts.TotalMilliseconds > 1.5 * (double)interval)
{
// secons to start the next timer cycle
interval = QUICKREFRESH_INTERVAL_AFTERAWAKE;
}
// Reset the timer's interval
Timer1.Interval = interval;
}
}
catch { }
}

There is a try and catch blocks and exceptions are ignored. I had several cases of crashes when OnPaint was introduced. Since there are not critical codes there, I just ignore any exceptions from this event.

Read More...

Sunday, June 17, 2007

Building Solution Failure: binary files could not be created

Recently, I installed Ubuntu Linux desktop on my computer. Before the installation, I had Windows XP. I got a bigger hard drive and I did partition on HD as 2 partitions. I plan to set a dual boots system, one for my Windows and another for Ubuntu.

My previous HD also had two partitions, that was done by HP, one small one for backup systems. I used Norton Ghost to do a partition image of my Windows and after I install the new HD, I restored my windows. That safes me a lot of time to reinstall my application and configure my working environment. So far so good.

The Ubuntu was installed successfully, and it is very impressive. I am going to further to investigate the OS.

My Windows works fine. However, I encountered a problem while I was compiling a solution project. I got a message saying that "The volume does not contain a recognized file system, ...". The build was failed because the binary files could not be created. I checked my path. It is fine. The message is very misleading.

Finally, I figured out the problem. It is the environment var Temp. I set this one to my "D:\temp". After the dual OS systems was set up, the D: partition was not available any more. What I did is to format the missing partition D:. After that, all the temporary files can be created and there is no problem to build my solution.

Read More...

Wednesday, January 11, 2006

Windows Installer Problem

Some times I got anoying error messages when I tried to open some applications such as VB6.0. The message is like a dialog window with the message:

Setup is aborting now. Cannot detect file: mediainfo.ini


This is caused by Windows Installer when I tries to find some files based on Registry settings. For example, I removed some binary files which were installed by Windows Installer but I could not find Uninstaller for those files or I could not run uninstaller successfully.

Here are some steps to avoid these messages:

Locate missing files

  • Open Event Viewer from Administration Tools.
  • View property for the most recent warning messages in Application node, and make a note of missing file, for example, "C:\MyTools\Bin\Interop.Utility.dll".
Search for Registry settings for missing files
  • Open RegEdit
  • Locate to "My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer"
  • Search for the file with path found above. Note, do not include drive like "C:" in the search string.
  • You should find a key like this: "...\UserData\S-1-5-18\Components\D1311F8CC3D78BB42BCF6A". Under this one you will find a key Item with a value like "C?\\MyTools\Bin\Interop.Utility.dll".
Change Reistry Settings
  • What I do first is to find the missing files and copy them to a folder like "C:\MissingFiles\Installer\"
  • Then I change the registry key item's value to "C?\MissingFiles\Installer\Interop.Utility.dll".
After I change all the registry items for these missing files, I will not get warning message any more.

I am not sure if I should remove these registry keys or not. For safe purpose, I try to find missing files and udpate registry instead.

Read More...