I'm learning developing drivers with win10 1709 and visual studio 2017. I created a empty wdm project and build it into mydriver1.sys
But I can't start service
sc create mydriver binpath= mydriver1.sys type= kernel
[SC] CreateService SUCCESS
sc start mydriver
[SC] StartService FAILED 2:
Then I checked the mydriver1.sys with Dependency Walker, it shows that many sys files and dll are missing.
1
How shall I solve is Problem. I don't think downloading those dlls one by one is a good idea.
My Code is a simple Hello world:
#include <ntddk.h>
VOID Unload(IN PDRIVER_OBJECT DriverObject)
{
KdPrint(("Good bye Driver\n"));
}
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
KdPrint(("Hello Driver\n"));
DriverObject->DriverUnload = Unload;
return STATUS_SUCCESS;
}
Related
I create an automate deployment script that will mint 2million SPL tokens to an address, the mint is owned by the program PDA as shown in Solana explorer:
Bellow is the last step in the deployment script:
export async function mint2e6Tokens(provider: anchor.AnchorProvider, tokenAccount: PublicKey, mint: PublicKey): Promise<void> {
// get the token account could be PDA
const programKeypair = await createKeypairFromFile(PROGRAM_KEYPAIR_PATH);
/** Load from PDA */
let mint_tokens_tx = new Transaction().add(
createMintToInstruction(
mint,
tokenAccount,
programKeypair.publicKey, // -> I DOUBLE CHECKED, THIS IS 6Z24B3qCrWfWvDo1f2HgxmnBSGhqQes1sHobqMtMxfbP
2e6,
[],
TOKEN_PROGRAM_ID
)
);
// We sign with our programId instead of the wallet because this is a PDA
// Program Derived Adress
await provider.sendAndConfirm(mint_tokens_tx, [programKeypair]);
}
When I run in LocalNet, it works:
Migrating to LocalNet...
RUNNING CUSTOM SCRIPT ====>>>
Payper: EsgJ9ihTEZskWyWpMMPuGVisy5ay76YWgetgTLb3jRmj
Using program 6Z24B3qCrWfWvDo1f2HgxmnBSGhqQes1sHobqMtMxfbP
Program: 6Z24B3qCrWfWvDo1f2HgxmnBSGhqQes1sHobqMtMxfbP
Mint: AVPgrT1y6ZfjGWPyLCWEPZdogRgmEMbrdRbcHNSfAPzF
Campaign: FcAmyEgZsXUKLB6hKufDmLuSBzMzVtPmRPm7vZLStK4U
31999500
However when I switch to DevNet, it always give me error
Migrating to DevNet...
RUNNING CUSTOM SCRIPT ====>>>
Payper: EsgJ9ihTEZskWyWpMMPuGVisy5ay76YWgetgTLb3jRmj
Using program 6Z24B3qCrWfWvDo1f2HgxmnBSGhqQes1sHobqMtMxfbP
Program: 6Z24B3qCrWfWvDo1f2HgxmnBSGhqQes1sHobqMtMxfbP
Mint: AVPgrT1y6ZfjGWPyLCWEPZdogRgmEMbrdRbcHNSfAPzF
Campaign: FcAmyEgZsXUKLB6hKufDmLuSBzMzVtPmRPm7vZLStK4U
SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x3
at Connection.sendEncodedTransaction (/code/beens/node_modules/#solana/web3.js/src/connection.ts:4248:13)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Connection.sendRawTransaction (/code/beens/node_modules/#solana/web3.js/src/connection.ts:4210:20)
at async sendAndConfirmRawTransaction (/code/beens/node_modules/#project-serum/anchor/src/provider.ts:288:21)
at async AnchorProvider.sendAndConfirm (/code/beens/node_modules/#project-serum/anchor/src/provider.ts:148:14) {
logs: [
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]',
'Program log: Instruction: MintTo',
'Program log: Error: Account not associated with this Mint',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2809 of 200000 compute units',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: custom program error: 0x3'
]
}
Why the authority is right, but Solana complain that Error: Account not associated with this Mint?
It turns out that my versions for Solana, Anchor and Rust are not compatible with DevNet and / or testnet.
I upgrade solana to main net recommended version and it works. One more things to mention that don't forget to run "solana program close --buffers" before trying. My current settings are:
root#d4c64206ce03:/code# solana --version
solana-cli 1.10.31 (src:77a40cd8; feat:4192065167)
root#d4c64206ce03:/code# rustc --version
rustc 1.63.0 (4b91a6ea7 2022-08-08)
root#d4c64206ce03:/code# anchor --version
anchor-cli 0.25.0
I am trying to invoke commands in Rust (1.0 beta 3) on Windows 7 in an MSYS2 environment, but I cannot understand how to do it.
Suppose that you have this very simple script called myls in your home folder:
#!/bin/bash
ls
And now create a simple program in Rust that calls the script:
use std::process::Command;
use std::path::Path;
fn main()
{
let path_linux_style = Path::new("~/myls").to_str().unwrap();
let path_win_style = Path::new("C:\\msys64\\home\\yourname\\myls").to_str().unwrap();
let out_linux = Command::new(path_linux_style).output();
let out_win = Command::new(path_win_style).output();
match out_linux
{
Ok(_) => println!("Linux path is working!"),
Err(e) => println!("Linux path is not working: {}", e)
}
match out_win
{
Ok(_) => println!("Win path is working!"),
Err(e) => println!("Win path is not working: {}", e)
}
}
Now, if you try to execute it, you will get the following output:
Linux path is not working: The system cannot find the file specified.
(os error 2)
Win path is not working: %1 is not a valid Win32 application.
(os error 193)
So I am not able to invoke any command in MSYS environment.
How can I solve it?
EDIT:
I noticed that if I invoke an executable, the problem doesn't happen, so it seems to be related to invocation of bash script. Anyway, it's quite annoying since it makes compiling projects depending on external C/C++ code (that need to launch configure script) tricky to get to work.
The Windows example doesn't work because Windows isn't a Unix. On Unix-like systems, the #! at the beginning of a script is recognized, and it invokes the executable at the given path as the interpreter. Windows doesn't have this behavior; and even if it did, it wouldn't recognize the path name to the /bin/bash, as that path name is one that msys2 emulates, it is not a native path name.
Instead, you can explicitly execute the script you want using the msys2 shell, by doing something like the following (alter the path as appropriate, I have msys32 installed since it's a 32 bit VM)
let out_win = Command::new("C:\\msys32\\usr\\bin\\sh.exe")
.arg("-c")
.arg(path_win_style)
.output();
I am creating an MSI package for installing and starting Windows services using WiX v3.8. The code as follows:
<Component Id="INSTALLAPSSERVICE" Guid="991D5F82-0E77-4FE3-B1D8-4C941B84C7CD" Win64="yes">
<File Id="ApsService.exe"
Name="ApsService.exe"
Source="Resource\ApsService.exe"
KeyPath="yes"
Vital="yes"
DiskId="1"></File>
<ServiceInstall Id="ApsServiceInstaller"
Name="ApsService"
DisplayName="ApsService"
Type="ownProcess"
Start="auto"
ErrorControl="normal"
Description="A monitor service for windows application."
Account="[SERVICEACCOUNT]"
Password="[SERVICEPASSWORD]"
Vital="yes"
Interactive="no"></ServiceInstall>
<ServiceControl Id="StartService"
Start="install"
Stop="both"
Remove="uninstall"
Name="ApsService"
Wait="yes"/>
</Component>
But install fails with the following errors in the log:
Executing op: ServiceControl(,Name=ApsService,Action=1,Wait=1,)
StartServices: Service: ApsService
Error 1920. Service 'ApsService' (ApsService) failed to start. Verify that you have sufficient privileges to start system services.
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 3676 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 1888 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 1764 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 3504 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 2100 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 2752 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 3672 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 3876 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 1400 could not be cancelled. Error: 1168
MSI (s) (F0:C0) [15:57:28:630]: Product: WinApsSetup64 -- Error 1920. Service 'ApsService' (ApsService) failed to start. Verify that you have sufficient privileges to start system services.
How can I fix the errors?
The error message you are getting is the generic message the Windows Installer sends when it fails to start a service during install. Almost always the issue is that the Service is missing a dependency or otherwise not fully configured when the start occurs. To debug the root issue try:
Install the MSI package.
When the error dialog comes up indicating there is a failure to start the service *do not dismiss the dialog.
Start services.msc or use sc.exe from the command-line to attempt to start your service. The Windows Installer should have configured enough of the service to be able to debug deeper why it failed.
If necessary debug into your service executable directly to see why it cannot be started.
If this is a service written in managed code, ensure that it does not depend on files being placed in the GAC. Files are not in the GAC until very, very late during the installation process. If you must use files in the GAC, you will not be able to use the built-in ServiceControl element and will have to write a custom action to run after InstallFinalize. Note that after InstallFinalize a custom action will not be elevated so your service will have to support being started by non-elevated users. Again, I recommend not depending on the GAC.
Good luck debugging your service!
The ServiceInstall Account is obfuscated in the OP's example, but this error can happen if one forgets to fully qualify the account, as such:
<ServiceInstall ... Account="NT AUTHORITY\LocalService" />
Your installer will fail if you only specify the username (w/o the NT Authority) like this:
<ServiceInstall ... Account="LocalService" />
Remember to add "Log on as a service" rights to the [SERVICEACCOUNT],
To add the "Log on as a service" right to an account on your local computer
1) Open Local Security Policy.
2) In the console tree, double-click Local Policies, and then click User Rights Assignments.
3) In the details pane, double-click Log on as a service.
4) Click Add User or Group, and then add the appropriate account to the list of accounts that possess the Log on as a service right.
From: http://technet.microsoft.com/en-us/library/cc739424%28v=ws.10%29.aspx.
When debugging a service startup issue, I always just use a simple if() statement that checks for the existence of a particular file in the installation directory. When the service fails, I open a command prompt (before dismissing the dialog indicating the failure) and use "echo >thatfile" to create the file that I am looking for in the if(). The object of the if() is the Debugger.Launch() invocation.
Now, I can dismiss the dialog and rerun the installer and this time it will start the debugger and I can see what happens. I tend to use static class init as the moment to launch the debugger, but you can try to do it in "OnStart()", but if there are loading/binding issues, you probably won't get to that point before it dies. Whereas doing it during static class init will almost always tell you the things that you need to address as dependencies.
So I got this error today because my service had dependencies that had to be GACed before starting the service. As it turns out, dependencies are GACed last by the installer, and there's really no good way to get around this without building some kind of bootstraper/multipart installer.
However, I found the following resolution: deploy the assemblies both to the GAC and install them in the same directory as the service. This way, the service will be able to find the DLLs on start in the program files directory, and they will be GACed (which was a requirement for other reasons).
To do this, I had to create two separate component groups, and a "dummy" Directory:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="NameOfProgram" />
<Directory Id="GacDlls" Name="libs" />
</Directory>
</Directory>
I then create two Component Groups: one that has the exe and all libraries, and a second with the same libraries with the Assembly attribute set to ".net":
<ComponentGroup Id="ServiceLibs" Directory="GACDlls">
<Component Id="log4netGAC"
Guid="a23099ac-5880-4b6e-af3f-fa7cef113226">
<File Id="log4net.dllGAC"
Name="log4net.dll"
Source="..\ProjectDir\bin\$(var.Configuration)\log4net.dll"
KeyPath="yes"
Vital="yes"
DiskId="1"
Assembly=".net"
/>
</Component>
</ComponentGroup>
<ComponentGroup Id="ProductComponents" Directory="INSTALLDIR">
<Component Id="log4net"
Guid="463e05db-e248-44d7-bbde-467358b7310f">
<!-- normally we'd want to GAC this (Assembly=".net"), but that would prevent us from starting the service up during install so we'll just drop it in the program folder -->
<File Id="log4net.dll"
Name="log4net.dll"
Source="..\ProjectName\bin\$(var.Configuration)\log4net.dll"
KeyPath="yes"
Vital="yes"
DiskId="1"
/>
</Component>
... other components ...
</ComponentGroup>
And now it works!
I was also having this issue, an error kept occurring during installation even though the service registry keys were created and I was able to manually start the service.
So I solved it this way:
Instead of starting the service right at installation with the Service control:
<ServiceControl Id="StartService"
Start="install"
.. />
I just removed Start from the ServiceControl so the installer's success is not dependent on the service being started. You just need to start the service manually after successful installation which can be done easilly with a script.
My remote Service works fine on my Server 2008, 32 bit, but when I try to run it on my Windows 7 machine StartService() fails with ERROR_FILE_NOT_FOUND.
OpenSCManager(), CreateService(), QueryServiceStatus() and OpenService() all return success, but StartService() fails.
I even compiled the Service from the SDK Samples\WinBase\Service and copied it to Windows\system32 directory on my Win 7 machine, and ran it with '-install'. When I tried to start it with 'SC start' it returns the same error.
Here is the info from SC:
C:\Windows\System32>sc query SimpleService
SERVICE_NAME: SimpleService
TYPE : 10 WIN32_OWN_PROCESS
STATE : 1 STOPPED
WIN32_EXIT_CODE : 1077 (0x435)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
C:\Windows\System32>sc qc SimpleService
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME: SimpleService
TYPE : 10 WIN32_OWN_PROCESS
START_TYPE : 3 DEMAND_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : C:\Windows\System32\ServiceSvc.exe
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : Simple Service
DEPENDENCIES :
SERVICE_START_NAME : LocalSystem
C:\Windows\System32>sc start SimpleService
[SC] StartService FAILED 2:
The system cannot find the file specified.
I even ran xCmd.exe on my Win 7 machine, it runs a similar type of remote Service, it gives virus warnings, but even that returns the same error.
I'm sure that if it was a permissions issue that it would probably return ERROR_ACCESS_DENIED.
I've searched all over the net and can't find anything on why it's returning that.
I'm pretty sure I found the problem.
I found code to detect if the app was running in WOW64
and it returned true, it was running on a 64 bit Windows 7 machine.
When it's running in WOW64 it goes to Windows\SysWOW64 not system32.
Once I copied the 32 bit Service .exe into Windows\SysWOW64
and ran it the Service started! :-)
Run the service executable from \windows\system32
This Code is working fine with simple application so the drivers are fine.
so why the connection object is not able to initialise with drivers.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import com.opensymphony.xwork2.ActionSupport;
public class Insert extends ActionSupport {
public String execute() throws Exception, SQLException {
String sql = "";
String url = "jdbc:mysql://localhost:3306/test";
//String dbName = "test";
String driverName = "org.gjt.mm.mysql.Driver";
String userName = "root";
String password = "root";
Connection con=null;
Statement stmt=null;
try {
Class.forName(driverName).newInstance();
con = DriverManager.getConnection(url, userName, password);
stmt = con.createStatement();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
What does the exception say? A NullPointerException on createStatement?
In any case, has the class been loaded; is the class on the classpath (i.e. the MySQL jar on the classpath?)
Check the object returned from Class.forName() to check whether the class has been found.
After your comment it is clear that you have a classpath problem. The mysql jar is not on the classpath. I assume you are talking about a web app deliverable (war file), as changing the build path in eclipse is trivial.
In a web application deployed in, for example, tomcat you can look into <webapp-name>/WEB-INF/lib. The file WEB-INF/lib/mysql-connector-java-5.0.5.jar, or something similar, should be there.
If you have a war file (not yet deployed) you can extract it using the command line tool "jar", or get a file listing from it. If you do (on a command line) jar tf | grep mysql the jarfile should be visible. If you use windows; WinRAR (and probably WinZip) can also open warfiles. In WEB-INF/lib a MySQL jar should be visible.
If you use maven to build your web app; don't forget to add a dependency to the mysql jar. If you use ant to build; don't forget to copy the mysql jar file into WEB-INF/lib before creating the war file.
Please note that currently the recommended driver to ask for is 'com.mysql.driver.Driver', and not 'org.gjt.mm.mysql.Driver'. You can try to load that Driver class in stead of the older driver; further; check whether this driver is actually in the mysql jar (jar tf mysq.jar | grep Driver or so). If the Driver is in the mysql jar and the mysql jar is on the classpath of the webapp (in WEB-INF/lib) and there is only one mysql jar there (version conflicts are no fun), and it still does not work I really don't know what could be wrong. I think I'd download the driver jar again from MySQL and try again.