It’s important to understand which kind of DSN you have. On an x64 system, you can create an ODBC connection(DSN) on the 32-bit side of the system or on the 64-bit side of the system.
32-bit applications will only see ODBC connections created in the 32-bit side, and 64-bits applications will only see ODBC connections from the 64-bit side. Each kind of application has is own registry.To setup DSN for 32-bit application you must use:
%WINDIR%\SysWOW64\odbcad32.exe
and for 64-bit application you must use:
%WINDIR%\System32\odbcad32.exe
There is not 32-bit edition of Windows XP on the XP Pro x64 media.
http://support.microsoft.com/kb/942976/en-us
A 64-bit version of the Microsoft Windows operating system includes the following versions of the Microsoft Open Database Connectivity (ODBC) Data Source Administrator tool (Odbcad32.exe):
• The 32-bit version of the Odbcad32.exe file is located in the %systemdrive%WindowsSysWoW64 folder.
• The 64-bit version of the Odbcad32.exe file is located in the %systemdrive%WindowsSystem32 folder.
The Odbcad32.exe file displays the following types of data source names (DSNs):
• System DSNs
• User DSNs
Wednesday, December 21, 2011
Using Excel in Windows service on windows 200864 bit machine
Recieved following error message when try to open Excel file in Windows service on 2008 R2 64 bit
exception from hresult 0x800a03ec excel
Solution
1. Create following 2 folders and make sure service account have R/W access
C:\Windows\System32\config\systemprofile\Desktop
C:\Windows\SysWOW64\config\systemprofile\Desktop
2. For any Automation client to be able to access the VBA object model programmatically, the user running the code must explicitly grant access. To turn on access, the user must follow these steps.
exception from hresult 0x800a03ec excel
Solution
1. Create following 2 folders and make sure service account have R/W access
C:\Windows\System32\config\systemprofile\Desktop
C:\Windows\SysWOW64\config\systemprofile\Desktop
2. For any Automation client to be able to access the VBA object model programmatically, the user running the code must explicitly grant access. To turn on access, the user must follow these steps.
Office 2003 and Office XP
- Open the Office 2003 or Office XP application in question. On the Tools menu, click Macro, and then click Security to open the Macro Security dialog box.
- On the Trusted Sources tab, click to select the Trust access to Visual Basic Project check box to turn on access.
- Click OK to apply the setting. You may need to restart the application for the code to run properly if you automate from a Component Object Model (COM) add-in or template.
Office 2007
- Open the 2007 Microsoft Office system application in question. Click the Microsoft Office button, and then click Application Options.
- Click the Trust Center tab, and then click Trust Center Settings.
- Click the Macro Settings tab, click to select the Trust access to the VBA project object model check box, and then click OK.
- Click OK.
Tuesday, December 6, 2011
Power Shell - equivalent of a Windows CMD or MS-DOS batch file
Run a powershell scriptA PowerShell script should be saved with a .ps1 extension, e.g. MyScript.ps1.
Before running any scripts on a new powershell installation, you must first set an appropriate Execution Policy, e.g. Set-ExecutionPolicy RemoteSigned
There are two ways to run a PowerShell script.
The most common (default) way to run a script is by calling it:
PS C:\> & "C:\Belfry\My first Script.ps1"
If the path does not contain any spaces, then you can omit the quotes and the '&' operator
PS C:\> C:\Belfry\Myscript.ps1
If the script is in the current directory, you must indicate this using .\
PS C:\> .\Myscript.ps1
When you invoke a script using the syntax above, variables and functions defined in the script will disappear when the script ends.1
Dot Sourcing
When you dot source a script, all variables and functions defined in the script will persist even when the script ends.
Run a script by dot-sourcing it:
PS C:\> . "C:\Belfry\My first Script.ps1"
Dot-sourcing a script in the current directory:
PS C:\> . .\Myscript.ps1"
The System Path
If you run a script (or even just enter a command) without specifying the fully qualified path name, PowerShell will search for it as follows:
Firstly it will look at currently defined aliases, then currently defined functions and lastly commands located in the system path.
1unless they are explicitly defined as globals: Function SCOPE:GLOBAL or Filter SCOPE:GLOBAL or Set-Variable -scope "Global"
# ------------------------------------------------------------------------------
function writelog
{
param([string]$LogFile, [string]$data)
Write-Host $data
if ($LogFolder -ne "")
{
$data >> $LogFile
}else
{
}
}
# ------------------------------------------------------------------------------
function ZIPFolder
{
param( [string]$sourcefolder, [string]$outputfolder, [int]$retention, [string]$LogFolder )
$CompareDate=(Get-Date).AddDays(-$retention)
writelog $LogFolder ""
writelog $LogFolder "-- Search file old or equal this date: $CompareDate"
$a = Get-ChildItem -recurse $sourcefolder | where-object {$_.LastWriteTime -le $CompareDate}
foreach($x in $a)
{
writelog $LogFolder " evaluating file: $x"
#try/catch only Works in version 2
try
{
# $y = ((Get-Date) - $x.CreationTime).Days
$y = ((Get-Date) - $x.LastWriteTime).Days
# if ($y -gt $retention -and $x.PsISContainer -ne $True)
if ($x.PsISContainer -ne $True)
{
# $FileDate =Get-Date -format "dd-MMM-yyyy"
# $FileDate=($x.LastWriteTime).tostring("yyyy-mm-dd")
$FileDate=($x.LastWriteTime).tostring("yyyy-MM-dd")
$outputFile="$outputfolder$FileDate-output.zip"
writelog $LogFolder " Start ZIP file $x to package $outputFile"
$x |ZIPFile $outputFile
writelog $LogFolder " deleting file: $x"
# $x.delete()
writelog $LogFolder " Finished ZIP $x --> $outputFile, source file deleted"
writelog $LogFolder ""
}else
{
}
}
catch
{
writelog $LogFolder $_.Exception.ToString()
}
}
writelog $LogFolder "-- END Search file old or equal this date: $CompareDate"
}
# ------------------------------------------------------------------------------
function ZIPFile
{
param([string]$zipfilename)
if(-not (test-path($zipfilename)))
{
set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
# $Path=$zipfilename.Remove($zipfilename.LastIndexOf("\")+1)
foreach($file in $input)
{
#write-host $zipPackage.Items().Contains($file)
#write-host $zipPackage.Items(0).tostring()
# if (-not (Test-Path("$zipfilename\$file")))
# {
$zipPackage.CopyHere($file.FullName,0x16)
Start-sleep -milliseconds 500
# }
}
}
# ------------------------------------------------------------------------------
1. Create a New Zip
Before running any scripts on a new powershell installation, you must first set an appropriate Execution Policy, e.g. Set-ExecutionPolicy RemoteSigned
There are two ways to run a PowerShell script.
The most common (default) way to run a script is by calling it:
PS C:\> & "C:\Belfry\My first Script.ps1"
If the path does not contain any spaces, then you can omit the quotes and the '&' operator
PS C:\> C:\Belfry\Myscript.ps1
If the script is in the current directory, you must indicate this using .\
PS C:\> .\Myscript.ps1
When you invoke a script using the syntax above, variables and functions defined in the script will disappear when the script ends.1
Dot Sourcing
When you dot source a script, all variables and functions defined in the script will persist even when the script ends.
Run a script by dot-sourcing it:
PS C:\> . "C:\Belfry\My first Script.ps1"
Dot-sourcing a script in the current directory:
PS C:\> . .\Myscript.ps1"
The System Path
If you run a script (or even just enter a command) without specifying the fully qualified path name, PowerShell will search for it as follows:
Firstly it will look at currently defined aliases, then currently defined functions and lastly commands located in the system path.
1unless they are explicitly defined as globals: Function SCOPE:GLOBAL or Filter SCOPE:GLOBAL or Set-Variable -scope "Global"
# ------------------------------------------------------------------------------
function writelog
{
param([string]$LogFile, [string]$data)
Write-Host $data
if ($LogFolder -ne "")
{
$data >> $LogFile
}else
{
}
}
# ------------------------------------------------------------------------------
function ZIPFolder
{
param( [string]$sourcefolder, [string]$outputfolder, [int]$retention, [string]$LogFolder )
$CompareDate=(Get-Date).AddDays(-$retention)
writelog $LogFolder ""
writelog $LogFolder "-- Search file old or equal this date: $CompareDate"
$a = Get-ChildItem -recurse $sourcefolder | where-object {$_.LastWriteTime -le $CompareDate}
foreach($x in $a)
{
writelog $LogFolder " evaluating file: $x"
#try/catch only Works in version 2
try
{
# $y = ((Get-Date) - $x.CreationTime).Days
$y = ((Get-Date) - $x.LastWriteTime).Days
# if ($y -gt $retention -and $x.PsISContainer -ne $True)
if ($x.PsISContainer -ne $True)
{
# $FileDate =Get-Date -format "dd-MMM-yyyy"
# $FileDate=($x.LastWriteTime).tostring("yyyy-mm-dd")
$FileDate=($x.LastWriteTime).tostring("yyyy-MM-dd")
$outputFile="$outputfolder$FileDate-output.zip"
writelog $LogFolder " Start ZIP file $x to package $outputFile"
$x |ZIPFile $outputFile
writelog $LogFolder " deleting file: $x"
# $x.delete()
writelog $LogFolder " Finished ZIP $x --> $outputFile, source file deleted"
writelog $LogFolder ""
}else
{
}
}
catch
{
writelog $LogFolder $_.Exception.ToString()
}
}
writelog $LogFolder "-- END Search file old or equal this date: $CompareDate"
}
# ------------------------------------------------------------------------------
function ZIPFile
{
param([string]$zipfilename)
if(-not (test-path($zipfilename)))
{
set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
# $Path=$zipfilename.Remove($zipfilename.LastIndexOf("\")+1)
foreach($file in $input)
{
#write-host $zipPackage.Items().Contains($file)
#write-host $zipPackage.Items(0).tostring()
# if (-not (Test-Path("$zipfilename\$file")))
# {
$zipPackage.CopyHere($file.FullName,0x16)
Start-sleep -milliseconds 500
# }
}
}
# ------------------------------------------------------------------------------
1. Create a New Zip
function New-Zip
{
param([string]$zipfilename)
set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}usage: new-zip c:\demo\myzip.zip2. Add files to a zip via a pipeline
function Add-Zip
{
param([string]$zipfilename)
if(-not (test-path($zipfilename)))
{
set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
foreach($file in $input)
{
$zipPackage.CopyHere($file.FullName)
Start-sleep -milliseconds 500
}
}usage: dir c:\demo\files\*.* -Recurse | add-Zip c:\demo\myzip.zip3. List the files in a zip
function Get-Zip
{
param([string]$zipfilename)
if(test-path($zipfilename))
{
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
$zipPackage.Items() | Select Path
}
}usage: Get-Zip c:\demo\myzip.zip4. Extract the files form the zip
function Extract-Zip
{
param([string]$zipfilename, [string] $destination)
if(test-path($zipfilename))
{
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
$destinationFolder = $shellApplication.NameSpace($destination)
$destinationFolder.CopyHere($zipPackage.Items())
}
}usage: extract-zip c:\demo\myzip.zip c:\demo\destination
So, how do we package the Vista Sidebar Gadget?
dir <path_to_gadget_files | add-Zip <path_to_gadget_zip> Rename-Item <path_to_gadget_zip> <path_to_gadget_zip>.Gadget
Subscribe to:
Comments (Atom)