WMI Win32_Printer not working on XP Embedded - winapi

I have some code which works on a standard XP system, but fails on XP
Embedded test machine.
I get System.Management.ManagementException : Provider Load Failure
Here is my code:
string query = "Select * From Win32_Printer";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection results = searcher.Get();
Are there services to start or DLL's to register?
Please, help me find the answer!
Thanks in advance,
Flea

You must check wich the System.Management.Instrumentation.dll library is properly registered.
try out this link
How to: Fix Provider Load Failure Error

Related

Console application with Topshelf throws an exception when running as a service

I've developed a Console Application that connects to RabbitMQ then process some messages. I'm using Topshelf to allow the execution as a service without (on the paper) issues, but when I run it as a service I got the following exception
Application: XXX.exe Framework
Version: v4.0.30319 Description: The process was terminated due to an
unhandled exception. Exception Info: System.IO.FileNotFoundException
at
Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean)
at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
at
Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(System.Collections.Generic.IList`1)
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build() at
XXX.Program.Main(System.String[])
Now I think it's somehow missing the configuration file or some dll but I've all the files a folder on c:\services\myservice. If I run the exe from command prompt it works flawlessly.
I've also tried to set the identity to network service / admin user and similar... with no luck. I'm using TopShelf 4.0.4
Any suggestion?
Thanks
SOLUTION
It was a fault of mine...
I had to use
var builder = new ConfigurationBuilder()
.SetBasePath(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location))
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings.{environmentName}.json",true,true);
instead of
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory()) //(which is the default code present on MS site)
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings.{environmentName}.json",true,true);
As suggested by #bozoJoe here's the answer to my question, for upvote
SOLUTION
It was a fault of mine...
I had to use
var builder = new ConfigurationBuilder()
.SetBasePath(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location))
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings.{environmentName}.json",true,true);
instead of
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory()) //(which is the default code present on MS site)
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings.{environmentName}.json",true,true);

How can I connect to Oracle DB using Sahi 5.0 OS

I'd like to connect to Oracle Database using Sahi 5.0 OS API:
var $db = _getDB($driver, $jdbcurl, $username, $password)
or
var $db = _getDB("oracle.jdbc.driver.OracleDriver",
"jdbc:oracle:thin:#dbserver:1521:sid",
"username", "password");
I have downloaded classes12.jar and ojdbc14.jar and put it in C:\Users\Username\sahi\extlib\db
I've also already added in dashboard.bat:
set SAHI_CLASS_PATH=%SAHI_HOME%\lib\sahi.jar;
%SAHI_HOME%\extlib\rhino\js.jar;%SAHI_HOME%\extlib\apc\commons-codec-1.3.jar;
%SAHI_HOME%\extlib\db\ojdbc14.jar;%SAHI_HOME%\extlib\db\classes12.jar
and in dashboard.sh:
SAHI_CLASS_PATH=$SAHI_HOME/lib/sahi.jar:$SAHI_HOME/extlib/rhino/js.jar:
$SAHI_HOME/extlib/apc/commons-codec-1.3.jar:
$SAHI_HOME/extlib/db/ojdbc14.jar:$SAHI_HOME/extlib/db/classes12.jar
However if I try use 1st method to use _getDB i've following result:
Java constructor for "net.sf.sahi.plugin.DBClient"
with arguments "string,string,string,string" not found.
When I use second one I have this:
Java constructor for "net.sf.sahi.plugin.DBClient"
with arguments "string,string,java.util.Properties" not found.
How connect I connect to Oracle DB and use methods like $db.select and $db.update?
I'm working on Windows 7 with JDK 1.8
I think I can help you.
Was also getting errors when trying to connect to a database with Sahi OS.
The examples shown in https://sahipro.com/docs/sahi-apis/database-apis.html page are useful, but I believe there is more to the SAHI Pro.
Because I said it above?
I tried a number of ways and was not loading the database. Another problem is that I was trying to insert and not recover data.
I began to analyze the obtained error (same as yours) and then found that the SAHI API, this class 'net.sf.sahi.plugin.DBClient', there is the constructor method in the class, the _getDb function () calls to start the object.
Concludes that it found the SAHI API available on Github and checked by the class.
There is no method builder, this function does not work for SAHI OS.
So we have to do this using functions of the JAVA language, as is the example: https://sahipro.com/docs/sahi-apis/database-apis.html#Accessing%20databases%20directly
I modified this function (as I said, I was entering in the database) to my need, which was inserted into the database and vualá !!!! It worked!
I used SQLite (the SAHI documentation contains no example)
To clarify, the function I created would be this:
function setRawDB(driverName, jdbcurl, sqlQuery) {
java.lang.Class.forName(driverName);
var connection = java.sql.DriverManager.getConnection(jdbcurl);
var stmt = connection.createStatement();
var query = stmt.executeUpdate(sqlQuery);
stmt.close();
//sahi auto commit
//connection.commit();
connection.close();
}
and then I got to use automated scripts (before I was just getting used testing directly on the page), saving directly in the local database.
Only in this way could use.

Database access issue with Visual Studio application

I has been created a program that works with MS Access 2010 (.accdb)extension. The program is fully works fine.
The issue is:
When the program is installed into another PC that has no MS Office installed, then the Exception that defined in the program returns connection error. Yes of course because the program can't read the (.accdb) file without office installed.
Need solution:
Is there any way to import this (.accdb) in order to read and modify it. Or is there any other simple solution that works when the application is installed to any non office installed PC?
The Demo of My program Code is:
Connection String:
Imports SpeechLib
Imports System.IO
Module MdlIPray5ve
Public con As OleDb.OleDbConnection
Public cmd As OleDb.OleDbCommand
Public sql As String
Public speaker As New SpVoice
Public Function connection() As String
Try
connection = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=azan_time.accdb; Persist Security Info=False;"
Catch ex As Exception
MessageBox.Show("Could not connect to the Database. Check your Connection!")
End Try
End Function
Something that Accesses the Database:
Private Sub UpdateAlarmTone()
Try
Dim cmdText = "UPDATE alarm_tone SET subhi= #subhi1, zuhur =#zuhur1, aser = #aser1, megrib = #megrib1, isha = #isha1"
Using con As New OleDb.OleDbConnection(connection)
Using cmd As New OleDb.OleDbCommand(cmdText, con)
con.Open()
cmd.Parameters.AddWithValue("#subhi1", txtSubhi.Text)
cmd.Parameters.AddWithValue("#zuhur1", txtZuhur.Text)
cmd.Parameters.AddWithValue("#aser1", txtAser.Text)
cmd.Parameters.AddWithValue("#megrib1", txtMegrib.Text)
cmd.Parameters.AddWithValue("#isha1", txtIsha.Text)
Dim infor As String
infor = cmd.ExecuteNonQuery
If (infor > 0) Then
MsgBox("Alarm Tone record updated successfuly")
Else
MsgBox("Update failed!")
End If
End Using
End Using
Catch ex As Exception
MessageBox.Show("There is a problem with your connection!")
End Try
End Sub
create the Access database via ODBC, that comes with Windows itself.
You can also use other databases (eg., MySQL, Firebird, SQLite, and others) that are available that wouldn't necessarily cost your client anything if they installed it (or, for some, if you included it in your installation for them).
Using the MS Office COM automation requires that the MS Office product be installed on the machine running the automation.
There are third-party code libraries that replace that functionality with their own code, meaning your app could create it's own Access-compatible files. However, your users would still need Access to use them

IIS5 - ODBC - Data source name not found and no default driver specified

I’ve got some problem using an ODBC connection with IIS.
Here is my config :
IIS 5 on Windows XP
ASP.NET 2.0
Oracle 9
VS 2005
When I try too use my web application on IIS, I’ve got the following exception:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
BUT, when I use it like a web site in VS2005, I didn’t have any error.
So, I’d try to make a very little app, with the following code:
using System;
using System.Data;
using System.Data.Odbc;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
OdbcConnection con = new OdbcConnection();
con.ConnectionString = "DSN=<MyDSN>;Uid=<LOGIN>;Pwd=<PASSWORD>";
IDbCommand com = new OdbcCommand();
com.CommandText = "select sysdate from dual;";
com.CommandType = CommandType.Text;
com.CommandTimeout = 30;
com.Connection = con;
try
{
con.Open();
Response.Write(com.ExecuteScalar());
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}
}
}
It work fine on VS’s web server (ie: http://localhost:3715/Web/Default.aspx), but I’ve got the same exception (IM002) when I use it on IIS (ie: http://localhost/Tester/default.aspx).
My DSN is declared on the “ODBC Data Source Administrator” and work well when I test the connection…
The ASPNET account is in the same group as my user account (Administrators).
Full right for ASPNET Account on HKEY_LOCAL_MACHINE\SOFTWARE\ODBC and
HKEY_CURRENT_USER\Software\odbc keys.
I've read this post, but nothing work...
I'd look after an answer on stackoverflow (search, related questions, etc.), google...but I didn't found a working solution...
Is there anyone who have an idea?...
Where is my mistake?...
UPDATE: 2011/04/06
What I’ve done so far:
Tracing for ODBC: on VS’Web server, I got log; but on IIS, none...
System and User DSN are filled with the same information
Allow ASPNET, IUSR_XXX, IWAN_XXX, and all users (sic…) accounts full rights to: %ORACLE_HOME%, HKEY_LOCAL_MACHINE\SOFTWARE\ODBC, HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE
Windows, VS and IIS are all for 32 bits (so, there is no c:\windows\syswow64).
Check PATH value, and put %ORACLE_HOME% first.
IIS was reset each time I do a modification, my computer reboot twice.
But, now, I’ve got this message:
ERROR [IM003] Specified driver could not be loaded due to system error 998 (Oracle dans OraHome92).
And I finally found...
The administrators have install all the drivers in order to be used by the user only...
I’d create a system env var ORACLE_HOME...
There was only a user var :s
Thanks for your help.
I validate the Garry M. Biggs' answer because of the difference between system/user...
Had this problem ..
The best solution is to re install your odbc driver ... worked for me ..
the registry entries in your system might have got tampered .
I did a complete uninstall and re install .. worked for me .. lame but quick solution .
Make sure you have created a System DSN rather than a User DSN.
IIS will be running as a System service and therefore does not have access to User registry entries...
Maybe your system is 64 bit version
of Windows and IIS is 64 bit, but VS
is 32 bit? If so, look at my
answers:
odbc connection string dosen't work on windows 7
If you can connect from one environment and not from the other then enable ODBC tracing and compare log files. MS described it at: http://support.microsoft.com/kb/274551

C# WMI Eventwatcher code stopped working on Windows 7 with security exception

This is code that worked fine on Windows XP for years. User is not local administrator.
WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_ProcessStopTrace");
ConnectionOptions co = new ConnectionOptions();
co.EnablePrivileges = true;
ManagementEventWatcher watcher = new ManagementEventWatcher(new ManagementScope(#"root\cimv2",co), query);
watcher.EventArrived += StopEventArrived;
watcher.Start();
This throws an SecurityException on Windows 7, Access Denied when running as a non admin. On XP this works fine without being admin.
On this link MS states that 'Windows 7: Low-integrity users have read-only permissions for local WMI operations.'. I guess this is the problem.
But I can't find any clue on how to change this.
Workaround:
I ended up creating a windows service that runs in 'local system' context, and commanding this service by WCF.

Resources