The C# @ String Literal

This is why I love C#.  Simple, effective and sensible.

 @”c:\somepath\someotherpath\myapp.exe”

or @”This is a just some text

and on it goes

I love C#

I’m really still into in-line fragments – proper coding.

Advertisements

SQLPLUS – Windows – Administator only….

Came across this little chsnut on win2k recently – how to make SQLPLUS work on Citrix – with non admin users – handy alright! – This works a charm. 

Applies to:
Oracle Server – Enterprise Edition – Version: 10.1.0.2.0 to 10.2.0.1.0 Oracle Server – Standard Edition – Version: 10.1.0.2.0 to 10.2.0.1.0 Microsoft Windows 2000 Microsoft Windows XP Microsoft Windows Server 2003 Symptoms

When logged on to the Windows server as a non-Administrator OS account using Microsoft Terminal Services client (mstsc.exe), starting SQL*Plus fails with

SP2-1503: Unable to initialize Oracle call interface
SP2-0152: ORACLE may not be functioning properly

Starting SQL*Plus works when logged on to the Windows server using an Administrator OS account.

Starting SQL*Plus works when logged on locally to the Windows server console using the non-Administrator OS account.
Cause

The issue is related to a Windows Security configuration. The problem is caused by a security policy called “Create Global Objects”. The user account that is used to run the program does not have the “Create global objects” user right. This security policy was introduced with Windows 2000 SP4, and determines if applications started during a Terminal Services session can create or access globally accessible memory. By default, members of the Administrators group, the System account, and Services that are started by the Service Control Manager are assigned the “Create global objects” user right.
Solution
Assign the “Create global objects” user right to the non-Administrator account.

1. Click Start, point to Programs, point to Administrative Tools, and then click Local Security Policy.
2. Expand Local Policies, and then click User Rights Assignment.
3. In the right pane, double-click Create global objects.
4. In the Local Security Policy Setting dialog box, click Add.
5. In the Select Users or Group dialog box, click the user account that you want to add, click Add, and then click OK.
6. Click OK.

Sorted!

Right Click for Command Prompt

Right – always wanted to remember how to do this…

  1. Navigate in your Registry to

    and create a key called “Command Prompt” without the quotes.

  2. Set the default string to whatever text you want to appear in the right-click menu.

  3. Create a new key within your newly created command prompt named “command,” and set the default string to

    You may need to add %SystemRoot%/ before the Cmd.exe if the executable can’t be found.

  4. The changes should take place immediately. Right click a folder and your new menu item should appear.  

Works a treat.

Safe Threading in C#

Simple explanation. Its a bit like recursion….

Identify the class thats being called from another thread – lets assume its got a few Windows Form calls in it.  

I’ll use the example here.  I have a multithreaded application and one of the worker threads needs to update a text box – on the main app screen.

The class is within the main GUI form  – mainform.cs and ist defined as:

private void MessageHandler_Message(int nId, string sMessage)

The idea behnid this is to marshall into the original thread that contains the GUI code. You need to declare a callback function – like this within the main class.

delegate void MessageHandler_MessageCallback(int id, string sMessage);

OK, so its got the same arguments.

Now in the class thats being called – 

MessageHandler_Message(int nId, string sMessage) it needs re-writing to be thread aware.

private void MessageHandler_Message(int nId, string sMessage){

// Check to see if we are in the correct thread

if (this.InvokeRequired){ // We need to create the callback function in the corrrect thread

MessageHandler_MessageCallback m = new MessageHandler_MessageCallback(MessageHandler_Message);

// Callback function is in the right thread – .Invoke fires it there.this.Invoke(m, new object[] { nId, sMessage }); }else{// If we get here we must be in the right thread

m_listBoxMessages.BeginUpdate();

int nItem = m_listBoxMessages.Items.Add(string.Format(“({0}) <{1}> {2}”, nId, System.DateTime.Now, sMessage));if (m_listBoxMessages.Items.Count > 5000){m_listBoxMessages.Items.RemoveAt(0);
}

if (m_listBoxMessages.SelectedIndex < 0){ {m_listBoxMessages.TopIndex = nItem;}

else if (m_listBoxMessages.SelectedIndex == nItem – 1){m_listBoxMessages.SelectedIndex = nItem;
}

m_listBoxMessages.EndUpdate();

}

}

VB Package Deployment issues

I realized that many people, just like myself, were having problems with the Package and Deployment Wizard for VB 6.0 and when trying to install their program on another PC they were getting the following message:

“Setup cannot continue because some system files are out of date on your system. Click OK if you would like setup to update these files for you now. You will need to restart Windows before you can run setup again. Click cancel to exit setup without updating system files.”

Microsoft addresses this issue in their Help and Support (http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q191/0/96.ASP&NoWebContent=1) and proposes 8 solutions.

However, I found out that the problem was coming from the Bootstrap files in the Setup.LST file.
If you open Setup.LST (generated with the wizard) you’ll see something like this:

File1=@VB6STKIT.DLL,$(WinSysPathSysFile),,,3 25 99 11:00:00 PM,101888,6.0.84.50
File2=@MSVCRT40.DLL,$(WinSysPathSysFile),,,5 30 98 11:00:00 PM,326656,4.21.0.0
File3=@COMCAT.DLL,$(WinSysPathSysFile),$(DLLSelfRegister),,5 30 98 11:00:00 PM,22288,4.71.1460.1
File4=@stdole2.tlb,$(WinSysPathSysFile),$(TLBRegister),,8 23 01 1:00:00 PM,17920,3.50.5014.0
File5=@asycfilt.dll,$(WinSysPathSysFile),,,8 4 04 8:56:41 AM,65024,5.1.2600.2180
File6=@olepro32.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,8 4 04 8:56:44 AM,83456,5.1.2600.2180
File7=@oleaut32.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,8 4 04 8:56:44 AM,553472,5.1.2600.2180
File8=@msvbvm60.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,8 4 04 8:56:43 AM,1392671,6.0.96.90

Files 1 through 3 are needed to run your VB 6.0 program, but Files 4 through 8 were the ones that were “out of date” and caused the error. Since the host PC will most certainly have these files, there is no need for your program to install them (or even update them). So you can just insert a colon “;” in front of the lines for File 4 through 8 for the installation to ignore these commands.

So open your Setup.LST and change it like this:

[Bootstrap Files]
File1=@VB6STKIT.DLL,$(WinSysPathSysFile),,,3 25 99 11:00:00 PM,101888,6.0.84.50
File2=@MSVCRT40.DLL,$(WinSysPathSysFile),,,5 30 98 11:00:00 PM,326656,4.21.0.0
File3=@COMCAT.DLL,$(WinSysPathSysFile),$(DLLSelfRegister),,5 30 98 11:00:00 PM,22288,4.71.1460.1
;File4=@stdole2.tlb,$(WinSysPathSysFile),$(TLBRegister),,8 23 01 1:00:00 PM,17920,3.50.5014.0
;File5=@asycfilt.dll,$(WinSysPathSysFile),,,8 4 04 8:56:41 AM,65024,5.1.2600.2180
;File6=@olepro32.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,8 4 04 8:56:44 AM,83456,5.1.2600.2180
;File7=@oleaut32.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,8 4 04 8:56:44 AM,553472,5.1.2600.2180
;File8=@msvbvm60.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,8 4 04 8:56:43 AM,1392671,6.0.96.90

Save it, close it, and try installing your program again.

[B]Note: You may have other DLL files than those listed above, so you have to make sure which ones are the one out of date.