CreateFile doesn't prevents other processes from opening my device - createfile

I'm using CreateFile to open a connection to my USB hardware. If I have two (or more) hardwares connected to the PC I would like to prevent several instances (different PIDs) of my PC-application to connect to the very same hardware.
I thought this was accomplished by running CreateFile with dwShareMode = 0. For some reason this doesn't work. Several different instances of the PC-application will get a valid handle when running CreateFile towards the same USB-device.
hDev = CreateFile(
"\\\\?\\usb#vid_0442&pid_0891&mi_01#6&2ea0fbc8&0&0001#{ff646f80-8def-11d2-9449-00105a075f6b}"
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL
);
If possible I would like to make this work as I want without changing the driver since that will invoke driver certificate signing, yadayada...
What have I missed?
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx

WdfDeviceInitSetExclusive(...) at EvtDeviceAdd made it work re-signing my driver 8-]

Related

WinInet FtpOpenFile timeout

I have an app that regularly uploads file using WinInet's FTP functions. It's been running for years but started failing on 4/1/2021. It fails opening a file using FtpOpenFile with a status of 12002 Internet Timeout. The call looks like this..
hiOpenFile = FtpOpenFile(
hiSiteConnect,
"TEMP.htm",
GENERIC_WRITE,
FTP_TRANSFER_TYPE_ASCII,
NULL
);
The file does get created on the server.
I'm wondering what the time out value for this function is and if there is anyway to change it?
I kept getting 12002 Internet Timeout with both FtpOpenFile and FtpGetFile but both work now after adding the INTERNET_FLAG_PASSIVE flag to my InternetConnect call.
Regarding timeouts, normally you would use INTERNET_OPTION_CONNECT_TIMEOUT,INTERNET_OPTION_RECEIVE_TIMEOUT, or INTERNET_OPTION_SEND_TIMEOUT with InternetSetOption. See here for details on the option flags: https://learn.microsoft.com/en-us/windows/win32/wininet/option-flags
However, due to a very old MS bug, setting the timeout as above simply has no effect whatsoever. There is a workaround to reduce the timeout but not to increase. It is done by creating a new worker thread and waiting for it. See here for the article:
https://mskb.pkisolutions.com/kb/224318

CreateFile failed with 5

I'm using win xp Professional x64 Edition and I'm trying to send message to Windows Message Service like using net send. I'm using mailslot:
LPCTSTR SlotName = TEXT("\\\\.\\mailslot\\messngr");
hFile = CreateFile(SlotName,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
(LPSECURITY_ATTRIBUTES)NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
(HANDLE)NULL);
and after launching it, I got error 5 from GetLastError() in CreateFile. I don't know how to fix it. I gave all VM permission, I turned message service ofc, and I can open it to be notpad like others suggested in: CreateFile() Failed With GetLastError() = 5. I tried many flags, but it didn't change anything. Any guess?
Like it says in the mailslot documentation, only the process that created the mailslot can read from it. Mailslots are one-way communication.
Remove the request for read access.

selenium driver disabling html 5 support

I am trying to test a third party website/application, this is the only one we are having issue with...and can get through multiple pages, but there is one page in particular that when I am doing the following:
var chromeOptions = new ChromeOptions();
Instance = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), chromeOptions.ToCapabilities(), TimeSpan.FromSeconds(600));// NOTE: connection timeout of 600 seconds or more required for time to launch grid nodes if non are available.
Driver.Instance.FindElement(By.ClassName("main-container"));
Simple right? I am getting the following message:
Driver does not support manipulating the HTML5 application cache. Use the HasApplicationCache property to test for the driver capability.
I am trying to find the way around it...or not to use the cache? Driver Options are like the following, and I see that this has changed too..so if this is where I change it...I am not sure how I would change it. I don't seem to be using the grid, just one singular test on a local stand alone server.

APPFabric client communication error?

I have configured 2 AppFabric instances and try to connect from a test client to the cache.
At first, I had trouble establishing the cache using the DataCacheFactory, but after opening the 22233-22235 ports in the firewall I have managed to get the cache using the DataCacheFactory.
As soon as I try to use the cache for a very small object (using a simple get), I get the following with a null InnerException:
ErrorCode:SubStatus:The connection was terminated, possibly due to server or network problems or serialized Object size is greater than MaxBufferSize on server. Result of the request is unknown.
I don't believe it's the MaxBufferSize issue (I also modified the transportProperties in the config just to make sure), but on the other hand - I'm able to get the cache, which I believe should indicate that the client can communicate with the server. So what is it? -How can I get more details on this issue?
Thanks in advance,
Nir.
Got this to work!
All I needed to do was just to add the host names, as appear in ClusterConfig file to the hosts file of the client, and that's it!
Hope that helps anyone,
Nir.

Error deleting a record using Linq2SQL

I've received an error report from a client recently and am having no luck resolving it. I'm hoping someone can give me some insight to what may be wrong.
The error seems simple enough:
Csla.DataPortalException: DataPortal.Delete failed (System.InvalidOperationException: Sequence contains more than one element at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
Here is my DataPortal_Delete method, which takes the FileId (PK) as a parameter.
private void DataPortal_Delete(SingleCriteria<File, Guid> criteria)
{
using (var ctx = ContextManager<Ronin.Data.RoninDataContext>
.GetManager(Database.ApplicationConnection, false))
{
var data = ctx.DataContext.Files
.Single(row => row.FileId == criteria.Value);
ctx.DataContext.FileSources.DeleteAllOnSubmit(data.FileSources);
ctx.DataContext.Files.DeleteOnSubmit(data);
ctx.DataContext.SubmitChanges();
}
}
First thing I check was to see if there was another record with the same FileId (although being the primary key, this should be impossible). All FileIds were in fact unique. I launched the application connecting to the client database and tried to delete the record and it worked without any issues. The IT guy at the client site used the "Problem Step Recorder" to send me step by step screenshots of the actions taken by the user. Nothing out of the ordinary, and when he used a different machine, he was able to delete the record without any errors. Apparently this only happens when the application is run in Windows 7.
That said, any ideas as to what could be causing this?
Assuming the call to Single is the source of the problem, instead of:
ctx.DataContext.Files.Single(...)
change the code to allow the return of multiple rows from that query and then log what it's returning when it returns more than one row. This should point you toward your "duplicate" data problem.
Another thing to look at is the SQL that is being generated behind the scenes. Not sure that will help, but it can't hurt. I don't know your data model, so I can't understand your code as well as I would like to.
If it only happens in Windows 7 then this might be cause by the OS. Have you tried it on Vista? Vista's environment is simmilar on Windows 7. You can also use Windows Virtual PC + XP Mode. This is a virtualization application specially designed for Windows 7 to let users run applications like they use to in Windows XP. Note: XP Mode requires virtualization capable processor.
I had the same exception when deleting one entity. The problem turned out to be a foreign key relation defined in the dbml-File. So this was the reason for the exception in my case.
After I removed that it worked to delete the record (and I didn't want to cascade delete the records from the other table, I just need to find out how to configurate linq-to-sql to just set the foreign key column to null)