Why does 'shell' opening an executable in a Visual Basic Script sometimes give a 'run time error 5' but not always? - excel

I am playing around with the basics of VBS and have a very simple Visual Basic script which executes a file using shell.
I am using Excel under Windows 10.
Sub Whatever()
Dim Example_One As String
Example_One = "C:\Users\IEUser\python-3.8.0.exe"
Shell Example_One, vbNormalFocus
End Sub
The weird thing is that some files will run (e.g. Python as above) while others e.g. VLC, WinRAR give the error: Run time error 5: Invalid procedure call or argument.
I simply cannot figure out why some .exe files will run and others will not. I thought it might be something to do with how the installation works but ChromeSetup.exe works while VLC.exe does not (even though they both ask "Do you want this app to make changes to your device?" (Python has it's own installer). Double-clicking all files in Windows Explorer runs them as normal (they don't ask for any special rights).

Related

ROX-filer: "Set Run Action" for filetype to be opened my MSWin program

I want to set csv files to open in a windows program thru Wine when I click on any csv file.
I use ROX 2.10 filemgr and have Set run action as:
' wine "/home/name/.wine/drive_c/Program Files/dbEdit/dbedit.exe" "z:$#" '
This causes the error of:
Z:\home\name\Documents\ZipCodes.csv\ZipCodes.csv
I thus far am unable to correct the double ZipCodes.csv, which doesn't exist.
Placing either slash following Z: or capitalizing the Z makes no difference in the error
Also, I had tried to Set run action as:
' wine "/home/name/.wine/drive_c/Program Files/dbEdit/dbedit.exe" "$#" '
which causes the error of:
Z:\ZipCodes.csv, which also doesn't exist at location
So does anyone know the proper syntax to be used to correct the error?
Obviously the best fix would be find a simple Linux database program to use, but I like the simplicity of the dbedit program.

Is there a way to set a python script as program to open a type of file?

The problem:
I'm currently working on a programming language, which uses a simple python interpreter. The interpreter loops over every line with a bunch of if-statements.
The file extension I'd like to use is .ccp.
So far my progress. I want the computer to recognise .ccp files as a CalcScript file, and open it with the script.
I don't want to have a default filename which I can open using text = open("filename.idk","r").read(), I want to open a file like a 'normal' file. You double-click on the file in explorer, and it opens it in the python script. Regardless of the filename.
What I've tried:
Tinkering with the default applications in settings
Tinkering in regedit
Converting my .py file to .exe
Scouering the internet
My code:
https://github.com/AnonymousPixel/CalcScript
Sorry for bad English if there was any.
Summarizing my comments on the question, you can follow the steps below to achieve what you are asking:
Use sys.argv to access the command line arguments. For example the following script will just print all the arguments given to it:
import sys
print("Given arguments: ", str(sys.argv))
Let's name it myprogram.py.
You can then call it (I think) with: python myprogram.py arg1 arg2 arg3 and it will run and print the command line arguments.
Notice that the first argument (sys.argv[0]) is the script's path. So arg1 would be sys.argv[1], arg2 would be sys.argv[2] and so on.
I am saying to use sys.argv because as far as I remember double clicking a file with an extension which has a default opening program, will open that program with the file path as an argument.
Next step is to package your python script to an executable. This has been already asked and answered for example here (which is a duplicate, where you can follow the question which came before it to see even more examples). I used PyInstaller to test it (and on Windows OS). My command was like:
pyinstaller myprogram.py
... and it generated some folders and files. Specifically the folder dist\myprogram contained the executable along with its dependencies. You can then run your program by double clicking on it in the dist\myprogram folder. It should pop a CLI window, printing the arguments (ie only the program's path, since we called it without any other) and immediately exit. Or you can open a CLI window and run it with a command like:
myprogram argument1 argument2 argumentN
(supposing your current working directory is dist\myprogram) and it will indeed print the arguments.
Finally you have to set it up as the program which by default opens files with .ccp extension. On Windows 10, you can do this via:
Open up File Explorer.
Find a file with .ccp extension (or create one).
Right click on it.
Click on Properties on the dialog that pops up.
Go to General tab (if you are not already there) on the dialog that pops up.
On the Open with: section there is a button which reads Change. Click it.
Select More apps at the bottom of the dialog.
Make sure you have the Always use this app to open .ccp files checkbox selected.
Scroll to the bottom of the dialog and click on the blue text which prompts for manually selecting the default app, which in turn pops up a file chooser. I am not running on English language so it is a bit difficult to translate it exactly (I followed some online pages to actually see the default translation for the previous steps).
Select your executable as the default.
Confirm your choices by selecting Ok, Apply or anything else required.
Then you will also be able I think to change this extention later via:
Settings --> Apps --> Default Apps --> Choose default apps by file type.
Some references:
PyInstaller website and introductory manual.
Official page for step 3.
Unofficial page for step 3, a lot more detailed.

Pass argument to AppleScriptTask

When I switched to MacOS Mojave, I was no longer able to save an Excel document as a PDF to a specific location using a macro.
I have had to save it to /Library/Group Containers/UBF8T346G9.Office/⁩ and then move it to the Desktop by calling a script stored in /Library/Application Scripts/com.microsoft.Excel/.
This has worked for months. Someone who uses this macro/script combo has all of a sudden been unable to do so. No other user has a problem, some having the same combination of Excel and MacOS (16.29 and 10.14.6 respectively).
When she tries to run the macro, it throws
Invalid procedure call or argument (Error 5)
specifically on the line that calls this script.
There is another script at the beginning of the macro that does not take an argument and is working. I used MsgBox to see what string was being passed to AppleScriptTask, plugged it into the script using Script Editor, and ran it without issue.
Here is the AppleScript:
ExistsFile(sPath)
on ExistsFile(sPath)
set sPath to sPath as POSIX file
tell application "Finder" to set sPath to file sPath
set dest to (path to desktop)
move sPath to dest without replacing
end ExistsFile
Here is the call from the macro:
result = AppleScriptTask("moveToDesktop.scpt", "ExistsFile", sPath & strJobNumber & " Cover Page.pdf")
I tried the following based on what I have seen on other forums:
Set the filename to a variable and passing that to AppleScriptTask
Removing the extension in the script, removing the extension in the folder, and combinations of those two
In MacOS Mojave and newer, you'll need to do the following:
Open System Preferences - Security and Privacy - Privacy Tab - Automation - Excel ~ check off Finder.
Sounds like it could be a permissions error if it fails to run for one user only. This page has all the requirements to run the AppleScriptTask command. Possible solution could be to enable the correct permissions for the script to run using chmod command from terminal. This will provide permission for root and current user. If this doesn't work, double check that all the requirements are met on the user's system.
cd <path to script file>
sudo chmod 755 moveToDesktop.scpt
Its the spaces in the parameters you are passing to the AppleScript. You have at least one one before "Cover Letter.pdf" (and then one between "Cover" and "Letter"), probably in other cells as well that you are using to create the parameter.
I had the same problem as well as it was driving me mad that the AppleScript itself was working fine when feeding it the combined parameter directly.

Automate "Right-click + Print" on .xlsx files

I need to automate the act of printing .xlsx file.
I have already seen some answers to this task saying that it is possible by creating a VBA script, as well as some examples. That is not about what my question revolves around.
Thought, I know that it is also possible to right-click on a .xlsx file and click "Print", which does the exact task that I want. It opens Excel, prints the file to the default printer, then closes Excel. (Windows 7, by the way)
So I'm thinking that the work has already been done here.
What process is launched when clicking this "Print" option? Can it be launched via command line, or "clicked" by a python script or something? And if not, why? How can something so easy to click be impossible to automate? I assume a process of some sort must be launched in some way.
Found it!
This task can be easily launched using python.
import os
os.startfile('C:/path/to/the/file.xlsx','print')
This code will launch the same print task. From there, it is pretty trivial for a python developer to automate the task in his scripts.
However, if you do not know much about Python and do not want to learn it now, an easy (or lazy?) way to add it in any automation script would be to save the two lines of code above in a whatever.py file, and launch it via command line (with Python installed, of course).
The context menu print command for Office documents utilizes Dynamic Data Exchange (DDE) and does not directly run a command that can be replicated from the command line.
You can view the content of the commands in the registry. Browse to HKEY_CLASSES_ROOT\.xlsx and look at the (Default) data column. On my machine, "Excel.Sheet.12" is the type of a .xslx file. Then browse to HKEY_CLASSES_ROOT\Excel.Sheet.12\shell\ to see the commands registered for that file type. On my machine, the Print (Default) is "C:\Program Files\Microsoft Office\Office16\EXCEL.EXE" /dde and the "command" is zn=BV5!!!!4!!!!MKKSkEXCELFiles>]-z5hw$l[8QeZZR4_X=$ /dde, none of which is directly useful or accessible for running from a command line.
It will require another program to allow you to access the interface, but there are programs that allow you to make use of DDE from the command line. I recommend Freddy Vulto's Class Exec. More information and a few other similar utilities can be found here.

I've downloaded an .exe file but it closes quickly as it opens

I am trying to open a downloaded .exe file but it closes as soon as it opens. Is there any possible way so that I can open it for a longer duration to read the content.
It's probably a console application rather than a GUI application. Use the command prompt to run the .exe.
Do the following...
Hold down your Windows key on your keyboard and then tap "R".
This will bring up the Run dialog. Type in "cmd" (without the quotes). Hit enter.
(this will work in all Windows versions - browsing the start menu/screen differs in each version)
If you saved the file to c:\downloads and it's called myFile.exe, type
C:
cd C:\Downloads
myFile.exe
Some of the steps are a bit redundant - if you know what you're doing in the command prompt then skip as needed (but then you probably wouldn't be posting this question). This will work even if you saved the file to D:\downloads.
Another example - if you saved the file to D:\folderA\Folder with a space\ and the file is called "my file with a space.exe" then type
D:
cd "D:\folderA\Folder with a space"
"my file with a space.exe"
If there is an issue (eg it's a 64-bit executable and you're on 32-bit Windows) then you may get a better error message at the command line.
There are so many reasons why the executable does not run. Here are some ways to check what is going wrong:
Is it your .exe? Do you known the "normal" behavior?
When you download it manually, it the result the same?
Do you download the .exe manually or via your application?
Do you see any problem in your Windows Event Viewer?
Is it the same result if you try to download the .exe via different browsers (IE, FF, ...)?
More details are welcome!
The nuget.exe file is not a console GUI application but rather a console package. Once you've downloaded it, you'll want to place it in a folder outside your Downloads folder. For example, C:\NuGet\nuget.exe - then set it as a PATH variable so that it's executable from anywhere.

Resources