Is it possible to run a VBA form as a .exe file - forms

Is it possible to save a form in VBA as .exe file and then run it.

No, not natively.
There are some ways to emulate an EXE:
Excel: 3rd party tool that claims to be able to compile an workbook to an EXE: DoneEx XCell Compiler. You can also create an automatic marco, Auto_Open, to run when the workbook is opened.
Access: Microsoft used to have a way of delivering an Access database as an executable (the name of the tool escapes me) so you could deploy your database to desktops that didn't have Access installed, but I don't think they offer this anymore. You could convert you MDB to an MDE and set the startup properties to hide the database window and menus and such to emulate an EXE, but your users will need to have Access installed.
Word: You can pass the /m switch to Word on startup with the name of a macro to run.

I think there is at least 2 way
move the code into visual basic 6 and compile it or use visual studio tool for office and see what you can do.
if these 2 solutions is a no no for you, then you are out of luck

No. VBA is an addon to applications to support "scripting" in the form of VB.
So unless your application supports a way to save the internal script as en external EXE, you are out of luck.

I think DoneEx still needs Excel installed, it just bootstraps something to the xls file, or bootstraps that to something and wraps it up as an exe???/..
as I think this does.
http://cpap.com.br/orlando/XLtoExeMore.asp
But at least the second one if free!
I have not tested on PC's with out office.
what is it you are trying to accomplish there may be a work around another way?
thanks
Ross

Related

Obfuscating a PowerShell script

I have written a PowerShell script in many hours and days and would like to obfuscate it, but so that the code is no longer readable or decompilable, but the script can still be executed. Is there something like that?
With regards to actually obfuscating an entire powershell script, this site seems to do just that.
I tested a script a little over a year ago and here are some of my findings:
Windows10: The obfuscated script worked on Windows 10. I dont
remember the Powershell version I had back then.
macOS: Confirmed it also works on Macs (if you have powershell installed), but I remember there were some errors spat out.
I just tested another script a few minutes ago on a Windows Server 2016 (PSVersion:5.1./Desktop) system. No issues so far.
Now, as was already mentioned by previous posters, it is important to note that any obfuscation can be hacked into. It's just a matter of incentive for the hacker.
I say "any" specifically because you dont control the hosts on which your powershell script will be used. And as such, those who do, if inclined, can alter the binary of the powershell program to get it to spit out everything that it does. How easy that is, I do not know. But a quick google search suggests there are settings available that, if turned on, can log the entire execution of your powershell script, obfuscated or not.
A couple of links that touches on Powershell logging:
PowerShell Logging: Recording and Auditing all Things
About Logging Windows - PowerShell - Microsoft Docs
There is a thing named Powershell Constrained language.
Quoting from here: https://devblogs.microsoft.com/powershell/powershell-constrained-language-mode/
Constrained language mode is a language mode of PowerShell designed to support day-to-day administrative tasks, yet restrict access to sensitive language elements that can be used to invoke arbitrary Windows APIs.
In Constrained mode, these are not supported:
COM objects
Unapproved .NET types
XAML based workflows
PowerShell classes
It's best for running administrative tasks, still it's not better for daily uses. To start it use:
$ExecutionContext.SessionState.LanguageMode = 'ConstrainedLanguage'
Read more here: https://devblogs.microsoft.com/powershell/powershell-constrained-language-mode/
The Invoke-Obsufcation wrote by Daniel Bohmann is much better for this purpose. Link: https://github.com/danielbohannon/Invoke-Obfuscation
Usage Guide: https://blog.vonhewitt.com/2017/08/obfuscating-powershell-commands-using/
If you want something to obfuscate your powershell code to make it unreadable but keep it working you should check a project called Invoke-Obfuscationation done by Daniel Bohannan. You should check his talk about powershell obfuscation where he presented the tool.

PowerShell to executable - go the extra mile or leave it?

It seems like it is not all that easy to create an executable from a PowerShell script - do you know if it was ever meant to be an option?
I have found tools like PS2EXE, but still it does not seem like it was meant to be.
I am asking, if it is worth it to go the extra mile or leave it.
Background reason: I have some less technical users that need a smoother workflow.
As #Bill_Stewart kindly noted:
PowerShell is a shell that contains a powerful scripting language.
Which is perfectly in line with Microsoft's definition :
PowerShell is a task-based command-line shell and scripting language built on .NET.
Basically, wrapping it in an executable would go beyond its purpose. The nice thing about scripting is, that it's lightweight and task based. And in this case, that you can easily run it on multiple OS-ses.
So, I wouldn't go through the effort creating an exe.
If you want to run it easily, just create a .bat or .cmd file (if using Windows). On windows, I believe, you can also create a shortcut with command arguments and a little icon.
For Linux you clould use a .sh.

How do I convert a PowerShell script with custom modules into a single executable?

I've written a simple script that has multiple custom functions stored as modules. I have done it this way because I was always been told that if your function can be reused by other things then it should be a module and not a .\ source include. I'm starting to think that mantra isn't right in my current scenario. I am trying to convert the script to an single .exe so that I can install it as a windows service.
Probably should acknowledge that I understand why you wouldn't want to include system modules like Active Directory or IIS management for the obvious issue that could lead to but I'm only trying to include custom functions in a single disputable non editable way.
I have used PowerGUI in the past but can't find any valid exe's for that since DELL have removed it and from memory, I don't think I've ever used it with a module.
I've tried PS2EXE-GUI and PS2EXE. Both of these make the exe and everything works fine while the modules exist. However, as soon as I put the exe on a server that hasn't got the Modules deployed to it, it fails to run. I thought the compile followed all the dependencies and included them as part of the build into the single exe? That appears to not be the case.
I've also tried the PowerShell Studio 2018 by Sapien, but based on their forums you can't include modules into the complied exe. Which again feels wrong if they are actually just custom functions, but it's the way they've written it.
I see https://poshtools.com/docs/posh-pro-tools/merge-script/ would possibly do what I need but that's chargeable and it looks like it actually merges all the content back into a single file. Given the time pressure I'm starting to think I'll have to pay if there are really no other better options. I just don't have time to join everything together manually and I can't help thinking there is a better way I'm missing!
Can anybody please suggest other options?
Could I also get clarification around my original mantra (functions go in modules...)?
"No, never!" or "Yes, always!" or "It's just wrong in this scenario."

Read the word document conent without using Microsoft office

I am using word documents for the population of random mails. But to read the content, we are using MS Word. But the scripts are quite slow because of its auto-recovery feature.
My code is in powershell, is there any other alternative to read word docs? I tried to use wordpad but no success.
If they are docx files then they are an OpenXML format. Several solutions exists of reading docx files from code without requiring Office. See here and here. They are in C# but translating that to PowerShell should prove little problems. Or have a go with PowerTools for Open XML if you want to use PowerShell commands. Here is some more documentation on that subject.
If you mean you want to view them in their final format like a normal user would do, but without office, you can use this for example.
I have found the solution with the help of PowerTools for Open XML (Select-OpenXmlString -path $file_name).content.
To use powerTools on many machines will need Visual Studio to be installed on all machines which is not very feasible. It is available at: https://github.com/OfficeDev/Open-Xml-PowerTools
I have followed this screencast: http://www.youtube.com/watch?v=zU0utt3uga4.
And for other machines there is one small catch:
Copy the dlls by maintaining the folder structure
On the machine where you have built it. Copy the GAC C:\Windows\assembly\gac_msil\DocumentFormat.OpenXml and paste it to other machines where you want to use it.
Thanks Lars Truijens!!

Talend studio tWaitForFile issue

I am using a tWaitForFile component from a Talend Studio Project and I want to know if there is a way to be sure a file to trig the event when this file is fully written on disk.
I tried to set the advanced property : "Wait the file to be released"
but it seems this is useless, the file trigs the component even it is not finished to be transmitted.
Does anybody have the same behaviour and a solution to fix that?
The version of Tos is: 4.2.3
The advanced setting "Wait for file to be released" only works on Windows. It has no effect on Unix, which probably explains why it did not work for you.
It is generally difficult, or even impossible, for a Unix process to figure out if a file has been written completely or not. Consequently, there is no easy way to do this in Talend, either.
(For example, if you wanted to wait until the file size does not change anymore -- how long do you wait?)
A common solution involves the process writing to the file: Create the file under a different name first, and when it is written completely, rename it to the name that the other process expects. That way, it will show up in its full size immediately.