NAVmoble - the pocket-sized ERP
Optimized for Microsoft Dynamics NAV and Windows Mobile powered devices

Sunday, February 25, 2007

Sql Server 2005: Change schema for all tables

I recently needed to change the schema for all the tables in a Sql Server 2005 database.
Sql Server 2005 provides a T-SQl statement capable to change the schema for a given object called ALTER SCHEMA
You may use the following syntax to change the schema for all the tables in a database. Just change the "new_schema" string with the desired one:

exec sp_MSforeachtable "ALTER SCHEMA new_schema TRANSFER ? PRINT '? modified' "


Enjoy!

Friday, February 16, 2007

“How to” Series: Automating Windows Mobile with Windows PowerShell

A lot of noise is going around the Windows PowerShell these days. I like this tool and definitely it may be of use even for the embedded developer.

Are you having some repeating tasks in your daily dev activities? Are you copying files on/from the device, manipulating registry keys, start /stop processes, etc... All these may be automated using Windows PowerShell.

I'll give 2 short examples, here – just to illustrate the idea.

Microsoft provides API called Remote Applications Programming Interface - a.k.a. RAPI. It allows to "touch" the device from the desktop machine, when the device is cradled. It works via ActiveSync or Windows Mobile Device Center on Vista. Unfortunately the RAPI itself is unmanaged and will be a little tricky to use it from a PowerShell script. So, here comes the RAPI class from the OpenNETCF.Desktop.Comunication library - a managed RAPI wrapper.

Example 1: Copying pictures from the device

The following example connects to the cradled device and copies all the pictures located on the device (\My Documents\My Pictures\) in the current location on the desktop

Note that in this example you should have
OpenNETCF.Desktop.Communication.dll placed
in D:\RAPI. You may change the path or think about a smarter assembly loading scheme.

[System.Reflection.Assembly]::LoadFrom("d:\RAPI\OpenNETCF.Desktop.Communication.dll") |Out-null

$rapi = New-Object OpenNETCF.Desktop.Communication.RAPI

$desktopPath = Get-Location

$desktopPath = $desktopPath.Path

$devicePath = "\My Documents\My Pictures\"

echo "Connecting to device..."

$rapi.Connect()

$pictures = $rapi.EnumFiles($devicePath+"*.jpg")

$pictures.Count.ToString()+" pictures found"

echo "-------------------------------"

foreach($f in $pictures)

{

  $remoteFile=$devicePath+$f.FileName

$localFile=$desktopPath+$f.FileName;

"Copying "+$remoteFile+" to "+$localFile

$rapi.CopyFileFromDevice($localFile,$remoteFile,1)

}


 

Example 2: Creating a registry key

This example reads and displays a list of registry keys on the screen – the installed applications in this case. Then it creates a new registry key called "My Key"

Note that in this example you should have
OpenNETCF.Desktop.Communication.dll placed in D:\RAPI. You may change the path or think about a smarter assembly loading scheme.

[System.Reflection.Assembly]::LoadFrom("d:\RAPI\OpenNETCF.Desktop.Communication.dll") |Out-null

echo "---------------------------"

echo "Installed applications list"

echo "---------------------------"

[OpenNETCF.Desktop.Communication.CERegistry]::LocalMachine.OpenSubKey("SOFTWARE\Apps").GetSubKeyNames()

echo "---------------------------"

echo "Create new key "

echo "---------------------------"

[OpenNETCF.Desktop.Communication.CERegistry]::LocalMachine.OpenSubKey("SOFTWARE\Apps").CreateSubKey("MyKey")|Out-Null

echo "My Key" created


 

You may think about automating even more useful and boring tasks - task that you do not want to do manually every day. Explore the OpenNETCF.Desktop.Comunication library to discover even more useful features.

Links:

Windows PowerShell Team's Blog

OpenNETCF.Desktop.Communication library downloads

OpenNETCF.Desktop.Comunication Docs

Enjoy.

Thursday, February 08, 2007

Windows Mobile 6

I've just bouth a new WM5 device for personal use and ops -
Windows Mobile 6 was announced

So what's new there?


Dev's bits

  • Sql Server in ROM
  • CF2 SP1 in ROM
  • New APIs(WISP,New Sound API)
  • New developer tools(Cellular Emulator, FakeGPS, CabToolSigner,...)
  • Security Improvements(checkout this post via Daniel Moth)

    Check out this post at Loke's blog for details on the dev's bits


End-User pearls

Monday, February 05, 2007

Resolved: Explorer crash on Vista

I have Windows Vista on my dev box for quite some time and I felt just fine with it.
The Problem
I' had a real fun with Vista, until the day my explorer started to crash every time I tried to open the Control Panel or Network and Sharing Center . I tried to remember the things I've installed or changed recently, but without success. Then I tried to find solution by googling - failure again. I've found that sometimes explorer crash may be experienced due to enabled-by-default DEP in Vista. I've disabled it, following these instruction, but no luck. I've tried to update my drivers, disable some services and so on.
The Solution
It took me few days to realize the real reason:
I've installed Firebird 1.5 few days ago. After removing it , everything was just fine. My further investigation revealed that the problem is caused by the .cpl applet installed by the Firebird Installer. Fortunately, there was a option to omit the Firebird .cpl. installation.

Conclusion
Are you experiencing strange explorer crashes? Are you having crashes, while trying to open Control Panel or Network and Sharing Center? Try to remember, what you've installed recently. Check if these apps install Control Panel Applets (*.cpl)
You may search for *.cpl in Windows\System32. You may uninstall apps by launching Windows Explorer(assuming it does not crash) and navigating to MyComputer/Control Panel/Programs and Features. Do not click over Control Panel - just click over the arrow next to the Control Panel text to expand it in the folder view.

Sunday, February 04, 2007

“How to” Series: Windows Mobile Security Configurations

I've plugged a new Windows Mobile 5 device to my dev box and tried to deploy and debug a simple Compact Framework app. The device was HTC P3600 and it was obtained from a local mobile operator. However, the VS2005 complained that it can't deploy the app, because the device's security configuration does not permit debugging

The message said: "Unable to start program…"

I just wanted to debug, but no luck!
In order to deal with such issues, one should check out the following resource:
Windows Mobile 5.0 Application Security

Assuming, you are familiar with the concepts discussed in the resource given, I will outline some of the possible options: First we need the right tools to work with the security configurations. There are some "low-level" tools , but I personally find the Security Configuration Manager Powertoy for Windows Mobile to be a very useful toy.


Cradle the device and start the Security Conf. Manager
The right part of the screen displays the current device security configuration.
See the underlined labels? I'll explain the most important ones:

  • Configuration type shows the name of the standard security configuration loaded.
  • Security model
    shows if the device support trusted or normal execution mode. Only the Smartphone platform supports two tier security model. The PocketPC devices are one tier. It means that apps always run in trusted mode on PocketPC based devices.
  • Prompt indicates if the user is prompted, when unsigned app is about to be launched.
  • Unsigned applications- shows if unsigned application may be launched.

You may try the following scenarios in order to proceed with the day-to-day development normally:

  1. Scenario 1: Do not sign your app
    If Unsigned applications are allowed for execution you may debug and deploy without signing your app. However depending on the security configuration you app may run in normal mode (no access to specific APIs and resources). If the Prompt option is on, the device will show a confirmation message box every time your app is about to be launched. And that could be very annoying.
  2. Scenario 2: Sign your app

    This is the recommended scenario if Unsigned applications are not allowed for execution.

    1. Try to install a development certificate on the device.
      Go to the Security Configuration Manager and click "Add Development Certificate" from the "Device" menu. If the operation fails, you should consider contacting the deice vendor for a development certificate. Checkout the configuration type. Is it Locked or Third-Party Signed?
    2. Sign your app with a development certificate
      Although you may sign your app with the Security Configuration Manager, it is not practical enough during the development phase. Use the Visual Studio 2005 for that purpose. Use the Devices tab from the Project Properties (right click from the Solution Explorer). See the Signing an Application During Day-to-Day Development topic from the Windows Mobile 5.0 Application Security article for details.

    3. Deploy and debug your signed app.

  3. Scenario 2: Turn-off security
    This scenario is not recommended, because it is unlikely to have a commercial device with Security-Off. The development environment will be too different from the production one and may produce unexpected behavior. At least consider testing your app before releasing in a security configuration close to the production one.

    1. Provision device with the Security-Off Security configuration

      Select "Security-Off" from the dropdown list under "Selected Configuration" and click the "Provision" button. Wait until the device is provisioned with the new configuration.

    2. Deploy and Debug without signing your apps



Links:
Windows Mobile 5.0 Application Security
Windows Mobile 5.0 Security Model FAQ
Codesigning for Windows Mobile-based Smartphones and Pocket PCs
Security, Deployment, and Management