Does Win32::OLE::Const->Load('Microsoft Excel'); depends on Excel version - perl

I'm using Win32::OLE::Const->Load() in perl :
$xl = Win32::OLE::Const->Load('Microsoft Excel');
then I test if scalar(keys %{$xl}) is zero :
if (scalar(keys %{$xl})==0) {
return False;
}
else {
return True;
}
I tested this code in machine which supports Microsoft Excel 2003 it gives True, but when I tested the same code in machine where there is Microsoft Excel 2013 it gives me False!
I also printed the scalar(keys %{$xl} in the first machine it gives 2023, in the second machine it is 0!
Best Regards

after searching I found the solution.
it gives 0 in the second machine cuz there is no win32 Excel key in the registre.
the solution is adding win32 key in HKEY_CLASSES_ROOT\TypeLib\{00020813-0000-0000-C000-000000000046}\1.8\0\

Related

Q# : QDK Errors

I've recently tried to install the QDK via the VSCode extension in my Windows 10 Desktop and VSCode wasn't able to find the Microsoft libraries even after I was able to execute the code by the dotnet run command on the terminal. The code was the sample project code described in the create new project part of the tutorial. I also didn't have .NET SDK so I installed it but it seems to be working fine. In computers I got problems all the code, all related to not finding the namespaces.
namespace QuantumRNG {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Convert;
operation GenerateRandomBit() : Result {
using (q = Qubit()) {
H(q);
return MResetZ(q);
}
}
operation SampleRandomNumberInRange(max : Int) : Int {
mutable output = 0;
repeat {
mutable bits = new Result[0];
for (idxBit in 1..BitSizeI(max)) {
set bits += [GenerateRandomBit()];
}
set output = ResultArrayAsInt(bits);
} until (output <= max);
return output;
}
#EntryPoint()
operation SampleRandomNumber() : Int {
let max = 50;
Message($"Sampling a random number between 0 and {max}: ");
return SampleRandomNumberInRange(max);
}
}
Do you see any error messages in the output console?
To see the output console select "View: Toggle Output" (Ctrl + Shift + U) and select "Q# Language Extension" from the drop down list.
If the drop down list doesn't show "Q# Language Extension" then it probably means that the language-server that gets downloaded on first run is still downloading, so give it a minute or so (depending on your internet connection).
I think I also had the same problem. The .Net SDk which you have downloaded automatically creates a path in the environment variable by the name "%USERPROFILE%.dotnet\tools" so delete this and add "C:\Program Files\dotnet\sdk" or copy the path of dotnet SDK from the drive where you have installed dotnet and create a new environment variable under user variable. This might solve your namespace problem.

Crystal report export to excel : unable to read file

I am using vb6 program to export a crystal report to excel sheet.After running the program the exported excel sheet is unreadable. getting the error "Unable to read file"
CrxRep.DiscardSavedData
CrxRep.ExportOptions.DestinationType = crEDTDiskFile
CrxRep.ExportOptions.FormatType = crEFTExcel97
'Input parameter set
CrxRep.ExportOptions.DiskFileName = DestName
CrxRep.ExportOptions.ExcelExportAllPages = True
CrxRep.EnableParameterPrompting = False
CrxRep.ExportOptions.ExcelUseWorksheetFunctions = True
CrxRep.ExportOptions.ExcelUseTabularFormat = True
CrxRep.ExportOptions.ExcelPageBreaks = True
CrxRep.ExportOptions.ExcelTabHasColumnHeadings = True
CrxRep.Export False
However this problem occurs only on production server.When I tried to export in dev server it works fine.
From where are you trying to read the file ?
If you are logged onto the server and can't read it, that suggests that Excel or perhaps ADO is not installed on the server, but you can answer that by looking at the icon. If windows recognizes the file type and shows you the Excel icon, then Excel is installed there.
If Excel is installed there, then copy the file to your desktop, or to the dev server, and try to open it there. If it opens there...the problem is likely a missing component ( perhaps ADO ) on the prod server.

Why did SQL Server Management Studio 2008 command-line switches stop working?

I've always relied heavily on Windows shortcuts to SSMS that include command-line switches allowing me to quickly open up a specific database on a specific server. For example
Ssms.exe -S 123.123.123.123 -U sa -P goodpassword -d DbName
or
Ssms.exe -S . -E -d DbName
These suddenly stopped working. I get this error from SSMS:
Failed to create new SQL Server script.
Object reference not set to an instance of an object. (AppIDPackage)
Program Location: at Microsoft.SqlServer.Management.UI.VSIntegration.
AppIDPackage.AppIDPackage.OpenConnectionDialogWithGlobalConnectionInfo()
I can still launch SSMS without the command-line switches, and then manually establish the connections. Some command-line switches still work, for example
ssms.exe -nosplash
works fine.
I get the same error with any combination of the -S, -E, and -d command-line switches. It doesn't matter if I'm pointing to a valid server or database or not, or if my login credentials are good or not. I can point to the older version of SSMS and it works fine, but not the 2008 version.
This post on MSDN's forums is all I've found online, but MS hasn't been very helpful on this thread.
Any ideas how I might start to fix this? I work with a lot of different databases on different servers, and I really rely on these shortcuts.
I've thrown the DLL in question at reflector and it's given me back the code at the bottom of this post, sadly there's nothing immediately obvious in the code that makes it easy to work out why it's stopped working for you (wouldn't it be nice if Microsoft shipped debug symbols with anything they produce that's written against the CLR?).
There are a couple of places where the code makes me wonder if you might have a corrupted "recently used servers" list or something similar, perhaps you could try following the steps listed in this question to clear them out and see if that helps.
private void OpenConnectionDialogWithGlobalConnectionInfo()
{
if ((ServiceCache.GlobalConnectionInfo != null) && (ServiceCache.GlobalConnectionInfo.Count != 0))
{
try
{
using (ConnectionDialog dialog = new ShellConnectionDialog())
{
IDbConnection connection;
dialog.ImportRegisteredServersOnFirstLaunch = true;
dialog.AddServer(new SqlServerType());
UIConnectionInfo connectInfo = ServiceCache.GlobalConnectionInfo[0].Copy();
if (dialog.TryToConnect(this.PopupOwner, ref connectInfo, out connection) == DialogResult.OK)
{
this.ScriptFactory.CreateNewBlankScript(ScriptType.Sql, connectInfo, connection);
}
}
}
catch (Exception exception)
{
ExceptionMessageBox box = new ExceptionMessageBox(new ApplicationException(SRError.FailedToCreateNewSqlScript, exception));
box.Caption = SRError.MessageBoxCaption;
box.Show(this.PopupOwner);
}
}
ServiceCache.GlobalConnectionInfo = null;
}
The ObjectExplorer window must be open. Don't hide.
I solved my problem this way :)
Works fine like this:
sqlwb.exe -S . -E -d dbName
I'm using SSMS2008 against a SQL2005 database, and the ssms command line works fine here.
This is the version info produced by the SSMS About dialog:
Microsoft SQL Server Management Studio 10.0.1600.22 ((SQL_PreRelease).080709-1414 )
Microsoft Data Access Components (MDAC) 6.0.6001.18000 (longhorn_rtm.080118-1840)
Microsoft MSXML 2.6 3.0 5.0 6.0
Microsoft Internet Explorer 8.0.6001.18813
Microsoft .NET Framework 2.0.50727.3074
Operating System 6.0.6001
There are several sources (MSSqlTips, and here) that state the command line arguments are available on sqlwb.exe. Yet the Books Online page for ssms states that the options are available on ssms.

Set-SPDebug -trace 1 not working in PowerShell host

I have a few PowerShell hosts, and in these hosts Set-SPDebug -trace 1 does not work.
I tested PoshConsole, here it works, but for example the Host6 in the PowerShell SDK does not work.
Any idea what is required in a host to get this working?
My smart collegue Jan Pieter Guelen found the answer after going through the PowerShell automation api using Reflector. You have to enable history in CreatePipeline with the following code:
pipeline = runspace.CreatePipeline("", true);
Now the tracing works!Even the Wrox book "Windows PowerShell Programming" does not mention this:-( The PowerShell SDK sample (Host6) should include this as well... PoshConsole does this as well, but I never thought that this would be the problem.
In what way isn't it working? If you aren't seeing any output, did you override the WriteDebugLine() method of the PSHostUserInterface base class e.g.:
public override void WriteDebugLine(string message)
{
this.WriteLine(ConsoleColor.DarkYellow, ConsoleColor.Black,
String.Format(CultureInfo.CurrentCulture, "DEBUG: {0}", message));
}

Perl's TieRegistry and Windows Server 2008 R2

We have a Perl program that ran well on all Windows platforms so far.
When we tried it on the newly released Windows Server 2008 R2, it stopped working. Investigation revealed that the problem is that calls to read registry values using TieRegistry returned undefined values.
Is this a known problem? Did anyone run into a problem accessing the registry on Windows Server 2008 R2 using TieRegistry?
I'm running the program as administrator, so I don't think it is permission problems. The program works great and read the registry correctly on Windows 7 and Vista.
A sample script I wrote to access the registry also fail:
use Win32::TieRegistry(Delimiter=>'\\');
my $reg = "HKEY_LOCAL_MACHINE\\SOFTWARE\\TEST\\Value1";
my $val = $Registry->{$reg};
print "val: ".$val."\n";
Any help would be appreciated.
Thanks,
splintor
Since google likes to come up with this when people are looking for the solution I figured I'd drop a little note.
You do not have to modify TieRegistry.pm to get this to work. All you have to do is add the "Access" parameter to the call. here is an example:
my $rk = Win32::TieRegistry->new('LMachine\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL', {Access=> 0x20019|0x0200});
There are two flags above ORd together:
0x20019 -- Read access to keys
0x0200 -- Access the 64 bit version of registry (ignored on 32 bit systems)
You can also use 0x0100 to access the 32 bit redirect version of the registry (also ignored on 32 bit systems)
This way you don't have to modify the library AND a single program can access BOTH versions of the registry.
I found the source of my problem.
In order to make TieRegistry work well on 64-bit Windows, and access the correct registry hive, we used the solution suggested by Tony B. Okusanya (also quoted here). However, this solution adds both KEY_WOW64_64KEY and KEY_WOW64_32KEY to the access parameter, which is not logical – either you want to access the 64-bit registry and use KEY_WOW64_64KEY or you want the 32-bit registry and use KEY_WOW64_32KEY. Using both doesn’t really make any sense.
Nevertheless, in previous versions of Windows, as well as Windows 7, it seems that when RegOpenKeyEx notices that the KEY_WOW64_64KEY flag is set in the access parameter, it uses the 64-bit registry, and ignores the KEY_WOW64_32KEY flag. Windows Server 2008 R2, on the other hand, doesn’t ignore the KEY_WOW64_32KEY flag, and if both flags are set, opening the registry key fail, and Win32API::Registry.regLastError returns the error The parameter is incorrect.
Removing |KEY_WOW64_32KEY from our changed TieRegistry.pm solved the problem and caused our application to work again.
Regards,
splintor
This my first time posting here. Here was the solution I came up with and an example of its use:
use Win32::TieRegistry( Delimiter=>"#", ArrayValues=>0 );
my $pound = $Registry->Delimiter("/");
my $fileSep = "\\";
my $path = "";
my $PerlBin = "";
my $PerlInstallDir = "";
my $PerlInstallDrive = "";
my $SybaseInstallDir = "";
my $SybaseInstallDrive = "";
# Standard syntax for access to 32-bit registry
my $regKey = $Registry->{"HKEY_LOCAL_MACHINE/SOFTWARE/Perl"};
print "\n\n\n" . "Accessing 32 bit registry for Perl Info:" ."\n\n\n";
foreach $key (keys %$regKey){
print"$key: " . $regKey->{"$key"} . "\n";
}
$path = $regKey->{"/"};
$PerlInstallDir = Win32::GetShortPathName($path);
$path = $regKey->{"/BinDir"};
$PerlBin = Win32::GetShortPathName($path);
$PerlInstallDrive = substr($PerlInstallDir, 0, 2) . $fileSep;
print "\n\n\n" . "Accessing 64 bit registry for Sybase Info:" ."\n\n\n";
# This syntax passes the HEX flag to access the 64 bit registry
$regKey = $Registry->Open("HKEY_LOCAL_MACHINE/SOFTWARE/SYBASE/Setup", {Access=> 0x20019|0x0100});
foreach $key (keys %$regKey){
print"$key: " . $regKey->{"$key"} . "\n";
}
$path = $regKey->{"/SYBASE"};
$SybaseInstallDir = Win32::GetShortPathName($path);
$SybaseInstallDrive = substr($SybaseInstallDir, 0, 2) . $fileSep;
print "\n\n\nFinished retrieving registry info:" . "\n";
print "Perl executable Location == $PerlBin" . "\n";
print "Perl Install Drive == $PerlInstallDrive" . "\n";
print "Perl Install Directory == $PerlInstallDir" . "\n";
print "Sybase Install Drive == $SybaseInstallDrive" . "\n";
print "Sybase Install Directory == $SybaseInstallDir" . "\n";
This works for me
use Win32::TieRegistry (
ArrayValues => 0,
SplitMultis => 1, AllowLoad => 1,
qw(:KEY_), Delimiter => '/', FixSzNulls => 1
);
use constant KEY_WOW => (uc($ENV{PROCESSOR_ARCHITECTURE}) eq "AMD64" || uc($ENV{PROCESSOR_ARCHITEW6432}) eq "AMD64") ? 0x100 : 0x200;
$Registry->Open('LMachine/Software/Microsoft/',{Access => KEY_READ | KEY_WOW});