How to ask VB to virus-check a specific file - winapi

Is there an API call which will request the anti-virus software to check a specific file (same as right-clicking a file in Explorer and choosing Scan)?

You should look for a command-line interface. If such a interface exists, you can run it with a special command-line using CreateProcess.

Related

How to adjust an executable to have it stop emitting "allow this program app to make changes" in windows 10

We have an ancient win32 product that some customers still want to run in Windows 10, but in some cases several of its components (win32 executables) produce said message when run, while installing and after installing :
"Do you want to allow this app/program to make changes in your PC".
Is there any documentation of what Windows checks to emit the message ?
The message you're seeing is the UAC prompt, and it appears because Windows thinks the program wants admin privileges.
Ancient programs don't have manifests. Modern versions of Windows guess at whether really old programs require admin privileges. If the name of the program sounds like it would be an installer (e.g., setupfoo.exe), it will assume the program needs admin.
But many really old programs, even if they're not installers, often want admin privileges because they often try to do things like save files in the program's installation directory or change machine-wide registry values. If Windows detects a program attempting this and failing because it doesn't have admin privs, it might adjust the program's compatibility options so that next time it runs as an administrator. To check this, right-click on the executable file, choose Properties, and select the Compatibility tab. There you'll find a checkbox named "Run this program as an administrator."
To check if your program has a manifest, open the .EXE in Visual Studio (with just the regular open file command), or other resource viewer/editor tool, and look in the resources to see if it has an RT_MANIFEST resource.
If there is no manifest and the program is well-behaved, you can add one that sets the <requestedExecutionLevel> node to asInvoker.
If it has a manifest, look at the <requestedExecutionLevel> node in the XML. If it's there and it says requiresAdministrator, then there's probably nothing you can do. If it already says asInvoker, then something else is going wrong.
To provide or replace the manifest you have two options. You can create an external manifest file and place it in the same folder with the executable (for some versions of Windows, you also have to tell Windows to rely on the external manifest by changing a registry value).
Alternatively, you can use the manifest tool (mt.exe, which comes with Visual Studio) to embed an appropriate manifest in the executable itself (make a backup of the executable first!). In either case, you want to set the <requestedExecutionLevel> node to asInvoker to avoid the UAC prompt.
Note that, if the program really does need admin privileges, then providing a manifest that says it doesn't will cause the program to fail certain operations. The program might crash, or it might appear to work but silently fail to do something important (like saving your work).
Also note that manifests control other important things that you may have to get right, like marking whether the application is DPI-aware or what Windows versions it supports. So, if you try to add a manifest just to add asInvoker, you might also have to add some other important values. MSDN has lots of documentation on manifests and the manifest tool.

Using Win32's ::CopyFile to retrieve file from Symantec Enterprise Vault

I'm having a problem copying a file from a Symantec Enterprise Vault. Usually, I use the Win32 ::CopyFile function to copy from one NTFS to another. Now, the NTFS has a special symbolic link or shortcut. If you access the shortcut via Windows Explorer, the Symantec service intercepts the request and recovers the full file for you. This does not seem to happen when using the API call. It appears that the retrieval is occurring, but the API call doesn't wait for it to complete.
Is there a method for interacting with these special shortcuts programmatically?
I assume by IE you mean "Windows Explorer" and NOT "Internet Explorer"...
IF Symantec just intercepts so-called "shell operation" as your description suggests
then you need to use SHFileOperation for that...
see
http://msdn.microsoft.com/en-us/library/bb762164%28v=vs.85%29.aspx
depending on your OS it could be better to use IFileOperation
http://msdn.microsoft.com/en-us/library/bb775771%28v=vs.85%29.aspx
BOTH methods behave exactly as if the copy operation was handled by Windows Explorer (for example when you copy a file manually) thus would engage the Symantec Intercept in the same manner...
Enterprise Vault has it's own API, called the ECMAPI that allows you to interact with placeholders.
Unfortunately you have to be a member of the STEP program, which costs about $30,000 per year.
There are Symantec Partners, like QUADROtech and bluesource, who might be able to help you. QUADROtech do lots on the coding side of things.

Automatically creating shortcuts on any Windows computer

I'd like to create some sort of script that will create a particular shortcut on the desktop of any Windows computer. The idea is to make the script available (to students in a course) so that they can download it to their computer and run it just by clicking it (i.e. not running it at the command-line). The script will have to check for some particular folders and files, and, if they exist, create the shortcut.
I'm a Linux guy and know very little about Windows, and so I am not even sure where to start to looking. I considered into using a Python script to do this, but that apparently requires installing some Windows-specific extensions, which I don't want to insist that that users do.
This can be done in VBScript, using the Windows Script Host which should be installed and usable on nearly any recent enough copy of Windows.
You want the CreateShortcut() method of the WshShell object which gets you an object representing a shortcut. You'd modify its properties and use its Save() method to actually create the shortcut file.
I've linked to the scripting guide at MSTN, as well as a page specific to the shell object. That should be a good starting point.
For this, I often work up a quick NSIS script and compile it to an EXE. The result is a very small executable. You can download NSIS itself at http://nsis.sourceforge.net/Download. I recommend HM NIS Edit to start with, as it has a wizard that builds a base script for you. Most of that wizard won't be applicable to your situation, but it is a good way to get started. Notepad++ also does syntax highlighting for NSIS.

Correct way to design around Windows UAC limitations?

I found out an application I wrote does not work properly under Windows Vista/7 if UAC is enabled at any level, because it writes files to the install directory of the program, defaults to "C:\Program Files\MyProgram." If UAC is disabled (or on any other version of Windows) it works properly - I read that UAC denies applications write access to the Program Files directory by default.
My question is, well, how should I write my application so that it can be used without any "rights" needed at all. I don't want users to have to run it with elevated privileges or as administrator. I just want it to work. Are there certain directories that any app has write access to under UAC where it might be better to write my files? They are mostly config files that are dynamically created/destroyed/updated.
Thanks for you help!
Per-user application specific data should be written in the AppData folder.
You should use SHGetKnownFolderPath with FOLDERID_LocalAppData.
In managed code, you should use System.Environment.GetFolderPath with System.Environment.SpecialFolder.LocalApplicationData.
Yes, there are specific locations. Consider this msdn article as a first reference. It mentions the locations:
CSIDL_APPDATA
CSIDL_LOCAL_APPDATA
CSIDL_COMMON_APPDATA
In native code, the method SHGetKnownFolderPath should prove useful.
In managed code you can use Environment.GetFolderPath(). If you're in a specific application framework, such as windows forms, you can get even easier access via direct properties, such as Application.LocalUserAppDataPath (which is my personal favorite technique). The framework path will include app-specific qualifiers on the path it returns to distinguish between (e.g.) different versions of your app.

Creating drives to remote resources in windows?

There does not appear to be any good software to mount an FTP to a local drive letter (see here for details SF Question) so I was thinking why not just write it myself, but I have very little experience dealing with windows (at the programming level) so what would be involved in doing something like this? What needs to be done to get a new "drive" listed under "My Computer"? What needs to be done to then get the contents of the FTP (or other remote resource) listed that "drive"?
My initial thought would be you would need to write a shell extension to be able to show your FTP site, and that it would best be shown as a special folder in Windows Explorer. Your extension would ideally be written in a non-managed language that supported COM (C++, VB 6, etc). It would need to respond to events like:
The user highlighting a folder on the server
The user double-clicking on a folder on the server
The user dragging and dropping files to and from the server
The user wanting to disconnect/reconnect from the server
When you intercept these events you would issue the appropriate FTP command to accomplish the task (use LIST to get the contents of a directory, MKD to create a directory, STOR to upload a file, etc). You would have to take the results of these commands and show them in the folders view and the listview within Windows Explorer, and for that you will likely need to get up close and personal with the Win32 API. For that you can turn to books like Charles Petzold's classic Programming Windows. Also check out this tutorial on writing shell extensions.
It sounds like an interesting project.

Resources