Build an EXE containing all files (dotsource)

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
zztemp
Posts: 42
Last visit: Mon Oct 02, 2023 10:51 pm
Answers: 1
Has voted: 2 times

Build an EXE containing all files (dotsource)

Post by zztemp »

Product, version and build:5.4.145 Powershell Studio 2017
64-bit Windows 10

So i have my folder with the following files:

- Folder1
- Folder2
- info.txt
- company.ico
- db.csv
- GUI.Package.ps1
- GUI.psf
- GUI.psf.psbuild

Now as you can see, it references a CSV file from where i build up my Treeview.
In my code i just dotsource '.\db.csv' to the file. So therefore i want it included.

Is there a way to put all of this in 1 executable ? So that i can place this 1 EXE on a known location from where my users can access it?
If my DB.csv gets updates, i only have to package a new EXE and replace the old one with the new one.

Can this be done? So the goal is to have 1 exe that contains all my needed files and folders.

Thanks in advance!

cheers

C.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Build an EXE containing all files (dotsource)

Post by davidc »

If you depend on a folder structure, that can't be embedded into the executable, but I would recommend using a MSI installer if you require a specific structure with additional files.

As for keeping it updated, you could place the executable in a network location, but that can result in some security issues when running from other machines. It is a good idea to copy the executable locally or use an installer.

As for the csv file, you could reference the file from the network or place it on the cloud. As for checking for updates, you could have your script check the network location for new files (maybe use a text file with version info) and alert the user that a new version is available.

Let me see if we can work on a framework for this in a future version of PowerShell Studio. I will add it to our wish list.
David
SAPIEN Technologies, Inc.
User avatar
zztemp
Posts: 42
Last visit: Mon Oct 02, 2023 10:51 pm
Answers: 1
Has voted: 2 times

Re: Build an EXE containing all files (dotsource)

Post by zztemp »

Hi,

Thanks for getting back to me, i'm confused :-/ .

I'm creating a GUI to install a TCP/IP printer.
It reads the needed info for the TCP/IP-port out of the CSV.
The CSV file contains 4 values : Office;Workplace;IP;Portname, eg: NY;Ticketboot2;10.10.10.10;NYTicketboot2

The IT-staff would only have to add/remove/edit a printer in that file. This would be the primary "database".
I only want one copy of this CSV-file in existence. So that there never can be a faulty version.
I also only want one EXE of this GUI. It should be located on a networkdrive that everyone can access.
I DON'T want to install this application/GUI on each computer, because that would mean i'd have too much maintenance on rolling out a new version for reason X or Y. (even tho i have SCCM at my disposal, its far from a perfect solution).

So 1 version is way less hassle.

It installs the driver that is located in a folder on the same level as the PS1 so i dotsource to it .\driverfolder\whatever.inf
I also have an ACL list that i need to import during the installation.

So i hope this gives you a more correct idea of what i'm trying to accomplish.

So my question now is, how do i go about it ?

Do i create an exe from my PS1 file and place that EXE, a long with all other files (driver, csv, ..) in a public folder?

Thanks in advance.

C.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Build an EXE containing all files (dotsource)

Post by davidc »

I moved this topic over to the PowerShell GUIs forum so that others my chime in.

Yes, can certainly try to put the executable in a public folder, but this often could lead to security issues when running the executable from a network. But you will not know until you try it.

Use the Get-ScriptDirectory function / snippet, in order to get the correct folder of the running executable.
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Build an EXE containing all files (dotsource)

Post by jvierra »

I somewhat agree with David. Other issues are.
  • You cannot store folder structure inside of an EXE.
  • In a Windows domain this functionality is already provided by the Print Management Server.
  • Storing a volatile CSV inside of an EXE is counter productive and defeats the purpose of a CSV.
  • An EXE that can execute at an Admin level and stored publicly is a huge security breach.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Build an EXE containing all files (dotsource)

Post by jvierra »

I can also suggest that you might search for articles on basic program design. There are many blogs and books that can help you to understand how a program needs to be designed to accomplish your goals. Much of how you would accomplish this depends on understanding how Windows is designed to simplify management.

By using Print Manager you can then easily deploy printers via Group Policy which is the most automatic and reliable way to manage printers in a domain.
User avatar
zztemp
Posts: 42
Last visit: Mon Oct 02, 2023 10:51 pm
Answers: 1
Has voted: 2 times

Re: Build an EXE containing all files (dotsource)

Post by zztemp »

Hi guys,

Thanks for answering my question, bottom line, what i want to do isn't meant for an EXE.

Since you guys are as kind to spend your time answering my questions, i'll try to give some more insight.
The concerns you have are not applicable for my situation (you could not have known that, so i appreciate them).
"In a Windows domain this functionality is already provided by the Print Management Server."
The printers will NOT be installed on a printserver. They will have fixed IP's and will be printed to directly.
These printers are replacements of very small USB printers that sit next to each DESKTOP. Each remote office has 1 to max 8 "personal" printers that are now USB, but will then be TCP/IP printers.

For reasons i won't explain, each printer needs to be added to a computer 4 times with a different name.
So imagine we have about a hundred printers in remote offices, that's times four (and it could become six at some point). Management would be crazy on a printserver. There are some other reasons why they choose to do it this way, but i can't tell them. These decisions are out of my hands, so i'm making our users life as easy as it can be. And if it were in my hands, given the situation, i would probably do the same.

The reality is that each user will get a LAPTOP this year (no longer the desktop story). They'll move between offices on a daily basis (and sit at a different desk possibly) and need to be able to add the printer they need at that time. Some might commute in between the same offices, others might be subs and constantly move to different locations. You might start see why GPO isn't a good option. A GPO can't know at what desk in what office the user will sit at on any given moment. You could catch that by installing all printers of a remote office where that user might work at, but that isn't really user friendly + would be a huge time investment to figure that out. (and the situation could change every month)
An EXE that can execute at an Admin level and stored publicly is a huge security breach.
I don't know where i gave you the idea the EXE would have admin-rights, sorry if i did but of course it won't have that much power.The most BASIC user in our domain, will be able to install a printer via TCP/IP , and remove it, but all this WITHOUT having ANY admin permission.
By using Print Manager you can then easily deploy printers via Group Policy which is the most automatic and reliable way to manage printers in a domain.
I hope i explained it into enough detail to see that this isn't a good option for this situation.
Yes we manage our big networkprinters just like you imagine it would be done, but this is a different story all together.

Anyway, thanks for answering my question, i have worked out how i'll be going on from here.

The CVS will be on a networkshare where only adminusers will have edit-permissons. A normal user can only read the file, that will suffice for using the GUI.

The driver will either be installed from , again a networkshare OR (and this is what i prefer), i get the SCCM guys to include the driver into the staging image.

With these two "problems" out of the way, i can now create ONE exe that can be placed in a networkshare , without security issues and with the benefit that everyone can use it.

Thanks again.

cheers
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Build an EXE containing all files (dotsource)

Post by jvierra »

It baffles me why anyone in a Windows domain would not want to use a spooler. This allows Active Directory to complete manage all printers and printer deployments as well as driver updates and installation. It is simple and transparent. A spooler can manage hundreds of printers and thousands of users attachments by department, floor, building or user group.

If you do deploy printers via a direct connection then you will always have issues. For one thing only administrators can install printers.

If all of these issues are OK then installing locally can be done as you ask.

Note also that IP printers can be installed remotely via WMI.

Also, when printers are deployed via AD a user can just browse to any printer in their location and use it even if they have never used it before.
User avatar
zztemp
Posts: 42
Last visit: Mon Oct 02, 2023 10:51 pm
Answers: 1
Has voted: 2 times

Re: Build an EXE containing all files (dotsource)

Post by zztemp »

It baffles me why anyone in a Windows domain would not want to use a spooler. This allows Active Directory to complete manage all printers and printer deployments as well as driver updates and installation. It is simple and transparent. A spooler can manage hundreds of printers and thousands of users attachments by department, floor, building or user group.
I know, but that also has the disadvantage that when the printserver (and thus spooler) is down, non of our remote offices are able to print.
If you do deploy printers via a direct connection then you will always have issues. For one thing only administrators can install printers.
This is not true. You can allow users to install certain types of drivers through GPO.
Adding a TCP/IP port is just the same as adding a networkprinter.
They only downside is that users can't remove printers as easily, but i got around that issue too.

If all of these issues are OK then installing locally can be done as you ask.
Yup. My issues are more with the GUI than the solution it holds.
Note also that IP printers can be installed remotely via WMI.
This might be interesting to try out, for that time a GUI fails or a users messes up. Thank you i'll be looking into this!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Build an EXE containing all files (dotsource)

Post by jvierra »

I have run print spoolers for nearly 20 years and have never had an issue. If we need to provide super hardening then we cluster the spooler. In smaller sites I just run two spoolers and distribute the printers across the two. If one is down the job is sent to the companion spooler.

You can do it your way but it is not really necessary and much less reliable especially when you need to migrate.
This topic is 6 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked