Windows explorer monitors directory changes in a tricky way? - winapi

I have a sandbox system redirecting file modifications by hooking Ntxxx file system APIs. An interesting thing is, if i move files in Notepad->File/Open dialog in my sandbox, e.g. from desktop\a.txt to desktop\b\a.txt, the a.txt file on real desktop just disappears, and it comes back after i refresh real desktop by pressing F5. actually there is no change in desktop folder at all, because all changes are directed. I know that most apps use API like ReadDirectoryChanges to monitor changes, but apparently explorer is doing something different. I tried tools like https://directorymonitor.com/, they did not observe any changes on desktop. I guess SHFileOperation internally interact with explorer somehow, but who knows details and how can i prevent this notification? It is really strange for users to see a file disappearing while it is actually still there.

windows calls windows_storage!SHChangeNotify instead of that one in shell32. Why does Windows have two copies of same API, are they different?

Related

How to hide terminal shell on server application like Warp in Windows?

I have a small warp server project on Windows that listen to a particular port and do something whenever I send a command to it by REST (for example: POST http://10.10.10.1:5000/print). It's a small client for printing PDF / receipt directly from another computer.
It works. But my problem is when I had to package the whole project, the Rust compiler give me an executable file (.exe). The application displays a terminal window when I run it. I want this terminal to be hidden somehow.
I try to run the program as a windows service (by using NSSM). It doesn't work for me since I had to access the printer. Windows doesn't allow my app to access any devices or any other executable as a windows service. (The reasons are explained here: How can I run an EXE program from a Windows Service using C#?)
So I plan to run my app as a tray-icon application so user can control or close the app. (https://github.com/olback/tray-item-rs)
Unfortunately, I still cannot hide the app's terminal window.
Another solution that I found is hstart (https://www.ntwind.com/software/hstart.html). But I would like to use this as "the last resort" solution since many antivirus/windows defender mark it as a malware.
Do anyone know how to hide or get rid of it ?
After lot of searching, It turns out to be easier than I thought. Just add
#![windows_subsystem = "windows"]
on top of your main.rs file. (for rust > 1.18) and the terminal is gone.
These control the /SUBSYSTEM flag in the linker. For now, only
"console" and "windows" are supported.
When is this useful? In the simplest terms, if you're developing a
graphical application, and do not specify "windows", a console window
would flash up upon your application's start. With this flag, it
won't.
https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute
https://blog.rust-lang.org/2017/06/08/Rust-1.18.html
https://learn.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem?view=msvc-170

Logon-type wxpython app

I manage a number of Windows PCs which are used to control equipment. Each computer has a specific program installed which is what people launch to use that equipment. We want to require people to log in before they can access this program.
Currently, I have a wxpython app which just launches that executable when people log in with the correct credentials. However, you can just run the program directly and bypass logging on. I'd like to make a mock logon screen, ie, fullscreen and modal, which only goes away when you log in. Also it should not be able to be bypassed by alt-tab, windows key, etc. How might I accomplish this with wxpython?
There is no full proof way to do this on Windows. You can show a wx.Frame modally using its MakeModal() method. And you can catch EVT_CLOSE and basically veto it it they try to close the frame. However, if they have access to the Task Manager or even Run, they can probably get around the screen. Most users won't be that smart though. You can delete the shortcuts to the apps you want to launch with wx and that will force most normal users to use your login screen. It's only the smart ones who like to troll through the file system who will go around it.

Locking user to browser window (using .dll files)

Is it possible to lock a user in chrome using .dll files (NPAPI plugin) or any other method?
I want to invoke chrome browser in highly controlled environment preferably on Windows. I would download chrome for businesses and write policies such that user isn't allowed to access any url except one.
I would create a packaged app and create an application shortcut on desktop for user which goes to the url. So it will open in KIOSK mode. But I would want that user shouldn't be able to navigate away from chrome, specifically that window and shouldn't be able to use any other program until he logs out of the application or explicitly closes the window. That means disabling function /ctrl/alt and window keys.
Something like this but with chrome.
Even opening chrome itself in 'locked' mode is not a problem.
Has someone ever implemented it? Is it possible using NPAPI plugin or any other method? If anybody could direct me towards any such resources I would be grateful.
No, this is not realistically possible using an NPAPI plugin, at least not by itself. At minimum you'd need an extension (see http://npapi.com/extensions).
If you loaded it from an extension it might be possible to get the window handle of the browser and such, but I think you'd probably be better off with a separate app.

Drag and drop on Win7 machine to my app

I have a user that is currently running my Winforms app on Win7. My app allows users to select rows from an open Excel spreadsheet and drag-n-drop them onto the app. However, this user cannot do the drag-n-drop. The cursor changes to the "no" cursor (little circle with line through it) and the operation won't complete.
I was researching drag-n-drop and Win7 and everything I found points to UAC and/or UIPI. I was looking for some solutions and am not sure if any of the below would work:
If the user logs in as admin (and as a result runs my app as admin) would that allow drag-n-drop to work?
Does the user need to turn off or change the settings of UAC/UIPI in order to be able to drag-n-drop?
I am not sure what the issue is. My app usually runs from C:/Documents and Settings/... (C:/Users/... on Win7). Does where it is running from matter? Does drag-n-drop not work because the user is not running my app with enough permissions? Are his Excel and my app on different permission levels? If so, what can be done about that? Note that even though my app allows users to just drag the file directly, that doesn't work either.
Also, is there any way I can have the user reproduce this issue with other apps? Are there apps that come with Win7 that he can see the same problem with. For example, can this be reproduced using Notepad?
Thanks.
Explaining this problem away by UIPI is a very long stretch. It doesn't have anything to do with whether or not the user is logged-in as an admin, that doesn't affect UAC and your program will be running with that same account anyway. The only way UIPI could kick in to stop a D+D is when your program is elevated and Excel is not.
To get yourself elevated requires work and doesn't happen by accident. You'd have to include a manifest so that the user gets the UAC prompt, you'd know about that. Or the user would have to change the desktop shortcut and tick the "Run this program as an administrator" option, she's know about that. While UIPI can be bypassed for Windows messages (ChangeWindowMessageFilter), it cannot for Drag and Drop so if any elevation is going on then your stuck. The ultimate test is to simply ask the user to put the UAC slider all the way down.
The much more likely scenario is that your DragEnter event handler simply isn't happy with the data it sees and therefore doesn't assign the e.Effect property. If you can't get a debugger on-site then write a little test program that logs the values of e.Data.GetFormats() plus whatever else you use to check if the drop is acceptable. And don't forget the obvious: the user simply fumbling the drag somehow.

Is it possible to access Win API from Firefox/Internet Explorer toolbar extention?

We have an idea to develop a toolbar for major browsers on Windows.
The toolbar will be a compliment for our weather application.
We want the toolbar to have an access to Windows API, specifically we need Registry and file system access (want access main app user settings).
Is it possible with Firefox and Internet Explorer toolbar extentions?
Browser toolbar development is new grounds for me.
I just want to know if it makes sense to start the project.
You can access the registry and filesystem from Firefox using the existing XPCom interfaces that are already exposed for you.
Internet Explorer plug-ins are all native, so you're already writing Win32 and COM, so you just call whatever API you need. However, since you are most likely running in a low integrity process, you need to read this which will explain the limitations on registry and filesystem access that you will encounter. If you describe exactly what registry and filesystem locations you're interested in, I can give you a more detailed answer.
The filesystem can be accessed from a Firefox extension:
File System access from Firefox Extension
I don't know about Internet Explorer, but that seems like it would make sense.
As for Registry access in Firefox, see this:
https://developer.mozilla.org/en/accessing_the_windows_registry_using_xpcom
It sounds like it should all be possible. I didn't find anything about Internet Explorer, but it seems like that would be a feature that they would include. I don't like to mess with the registry since that is not cross-platform, but if you really need the user settings, then I guess you have a valid reason. Just remember that not all of your users will be using Windows, and Mac OS doesn't have a registry (neither does Linux), so try not to restrict yourself too much if you can avoid it.

Resources