Tag Archives: tip - Page 2

Launch apps as Admin without prompt

This is a tip intended to ease the pain of continuously having to click the ‘Yes’ prompt when you want to launch an app in ‘Admin mode’.

The trick is to use the built-in Windows Task scheduler.

1. First you create a new task (not a basic task) and specify a name e.g. ‘CommandLine’ plus check the ‘Run with highest privileges’ check box.

2. On the actions tab you add a ‘Start a program’ action and select the executable e.g.’C:\Windows\System32\cmd.exe‘

3. Optionally under the Settings tab you can choose ‘Run a new instance in parallel’so you can run multiple instances of the app if required.

4. Click OK to create the task

Next you create a Windows shortcut (say on the desktop by right clicking and choosing new -> Shortcut)

1. Specify the following as the ‘Target’: e.g.  ‘C:\Windows\System32\schtasks.exe /run /tn CommandLine‘
Pay attention that the last parameter must match the task name.

2. You may want to manually select an icon for the shortcut as it won’t select the app icon by itself.

Now if you click (double-click) the shortcut a brief command line window before opening your app (in admin mode) – without prompting you! One big disadvantage is that you cannot pass command line parameters this way so launching say notepad with a specified txt file this way won’t work.

Of course, it would have been easier if MS built in a way you can choose (at your own risk) which apps you would like to launch in admin mode without prompting. There is a potential security risk in allowing functionality like that but if they wanted to it could be done with a big warning dialog at the start – that tells you you’re doing this at your own risk. It could use something like signing the required exe with a local (only) certificate to mark it trusted only on the local machine or generating a hash that gets stored in an encrypted system location or something, to tell the OS that particular exe can be trusted (when launched). The way to set up this hash and stuff would need to be a secure process in itself (requiring a ‘human’ user input) and letting you jump through a couple of hoops – once off. The idea is to allow only that particular exe on the particular machine as trusted. Copying it to another machine or changing it would require setting up the ‘trust’ again. Just an idea… (throwing a hint… to Microsoft)

IT ‘tips’

A few ‘IT’ tips

1. When you are looking into a problem – always check the obvious things first

2. If you cannot solve a problem yourself – read the manual

3. Don’t trust users to explain ‘what’ the problem is. Those are just symptoms

4. Remember, computers ‘can’ make mistakes – very fast ones these days!

5. Out of memory errors usually are not because of memory problems…

6. Never give users more functionality than they need – otherwise you have to maintain that too!

7.  The best debugging tool is a message box (alert in js) – just don’t forget to take them out again!

and some general wishdom…

1. Never assume things will always go well. They generally have a habit not to

2. Never underestimate the power or impact of users doing stupid things

3. You only get 2 kinds of hard drives… those that have failed, and those that soon will. Apparently these days this rule applies to most hardware components…

4. Crysis wasn’t created in one day, but you can play through it in a day

Formatting C# code for blogging

I came across a nice example of a tool that can help with formatting of C# source code that you want to publish (on say Word Press that does not support it). The tool’s source code can be extracted from CodeProject (Fast Colored TextBox for syntax highlighting). Incidentally it can also format VB, HTML, SQL and PHP (pitty about JavaScript 😉 )

Development tip for testing

Quick tip for all developers/programmers and anyone involved with creating software…

You haven’t tested your software until you’ve broken it yourself – aka negative testing.

If you couldn’t break your program yourself then… either you’re a super duper crazy developer or someone else will find a way to break it and make you look bad!

 

Extension method to create CSV from List collection

A quick one to share:

I needed to a method to quickly convert a List<string> to a plain comma delimited string. So I created this little Extension class:

public static class ListEx
{

public static string ToCSVString(this List<string> l)
{

StringBuilder sb = new StringBuilder();
if (l != null)
{

l.ForEach(li => sb.Append(li + “, “));

}
return sb.ToString().Trim(‘ ‘, ‘,’);

}

}

Of course this is still very specific to string collections only. I could have created something that does the same to say a List<T> list that is more generic but that I’ll leave for another day.

[Update]

While I’m at it – here is the opposite method:

public static List<string> ToListFromCSVString(this string s, bool ordered = false)
{

List<string> list = new List<string>();
if (s != null && s.Trim().Length > 0)
{

if (ordered)

list.AddRange((from sitem in s.Split(new char[] { ‘,’ }, StringSplitOptions.RemoveEmptyEntries)
orderby sitem
select sitem.Trim()).ToArray());

else

list.AddRange((from sitem in s.Split(new char[] { ‘,’ }, StringSplitOptions.RemoveEmptyEntries)
select sitem.Trim()).ToArray());

}

return list;

}

Waiting for your exit

With a heading like this the post could be mistaken for something more philosophical but fortunately this is a plain developmental posting 🙂

Suppose you have some program that does some work and then have to ‘sleep’ for a while before doing some more work – like a service checking or polling stuff. You can simply use something like a Thread.Sleep() but that also means the thread cannot do or respond to anything else during that time – like the program or service stopping. That would mean the stopping process has to wait until the ‘sleeping’ thread becomes active again.

A solution to this is by having a variable or property that indicates if the program or service is still running and having the ‘waiting’ routine wait in little ‘jumps’ checking the ‘IsRunning’ variable each time and then waiting a little bit more until the full ‘sleeping’ period time is done.

private void BackgroundWaitIsPolling(int nextWaitInterval)
{
   int waitTimeRemaining;
   int decrementBy = 2000;
   if (IsRunning)
   {
       try
       {
           if ((nextWaitInterval <= decrementBy) && (nextWaitInterval > 0))
           {
               Thread.Sleep(nextWaitInterval);
           }
           else
           {
               waitTimeRemaining = nextWaitInterval;
               while (IsRunning && (waitTimeRemaining > 0))
               {
                  if (waitTimeRemaining <= decrementBy)
                  {
                      waitTimeRemaining = 0;
                  }
                  else
                  {
                      waitTimeRemaining -= decrementBy;
                  }
                  if (decrementBy > 0)
                  {
                      Thread.Sleep(decrementBy);
                  }
               }
           }
        }
        catch { }
   }
}

 

Microsoft Access Database Engine for 64-bit

Wow I must have missed this one when it was released but it (has the potential to) solves some problems with accessing Access databases (*.mdb) from a 64-bit process. I haven’t tested it yet and the description mention that you can only use the 32-bit driver on Windows XP (sp3) but at least it should work for Windows 7 (and yes that other one…Vista as well).

Download link: Microsoft Access Database Engine 2010 Redistributable

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13255

 

Basic string to integer conversion extensions

Sometimes the more simpler things in life really help. Take the following couple of .Net extensions posted to CodeProject. Some of these will make (developer) life a bit easier.

http://www.codeproject.com/Tips/211015/Basic-string-to-integer-conversion-extensions

Moving the SQL server databases of a BizTalk (2006) installation

This is hopefully not something you have to do often and even more so for a production environment!

Firstly if you don’t have any applications installed yet or don’t worry about re-installing everything then rather go ahead and do a fresh install. Secondly, if you can recreate the sql server with exactly the same name – that should be safest option because you don’t need to make any changes to the BizTalk front end servers. Lastly, you can try the ‘restore’ vb scripts that is located in the ‘C:\Program Files\Microsoft BizTalk Server 2006\Schema\Restore’ directory of the BizTalk server(s).

To use these scripts you have to perform the following steps (after making proper backups of the ‘whole’ environment)

1. Stop all host instances plus SSO services.

2. Edit the sample xml file and replace all the placeholder names ‘SourceServer’ and ‘DestinationServer’ plus uncomment the sections you need and save the file.

3. Run the 2 scripts ‘UpdateDatabase.vbs’ (once) and ‘UpdateRegistry.vbs’ (on each BizTalk server).

4. Start SSO service (master first)

5. Start BizTalk hosts

6. If it worked go buy yourself a drink… else start praying…

How to make you computer talk at start-up

If you want to try some different.

http://microsoftfeed.com/2011/how-to-make-your-computer-talk-at-windows-7-startup/

Now you can set it up to greet you – ‘Hello Dave. I’m HAL 9000..” hehe