Open document with exe of Sapien PS Studio

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 4 years and 3 months 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
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Open document with exe of Sapien PS Studio

Post by stevens »

Hi,

I have used this viewtopic.php?f=21&t=14127 to generate an exe/msi.
They work fine on my local machine but not when launched on another (remote) machine (so f.e. opening test.xmind with the exe should show a window test.xmind). The exe launches but shows no output for the extension (it does when running locally).

Maybe I need to change the way I generate the exe/msi?
Thanks

S
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Open document with exe of Sapien PS Studio

Post by Alexander Riedel »

You are going to have to provide a few more details on what you are doing. The exe and MSI generation seem to have no bearing on what you are describing.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Open document with exe of Sapien PS Studio

Post by stevens »

Thanks. I did change from a single form (psf) to a project after which it doesn't work.
The project has globals.ps1 and some other files. Where do I define the Params($args) in a Project vs single form -see link to previous post-, now they are in the pss file?

Note: the project has several forms which open depending on the param that is given
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Open document with exe of Sapien PS Studio

Post by stevens »

Sorry, let me try again :-)
The $commandarg is working fine it seems.
It is the reading of the extension that doesn't seem to work.
It works fine in Powershell studio, not when in an executable.

F.e. c:\mydocuments\test.exe shows form2 wheras it should show form1 :-(


  1.         $Global:File = [io.fileinfo]$commandarg
  2.        
  3.         $Global:Extension = ([IO.Path]::GetExtension($File))
  4.         $Global:FileName = [io.path]::GetFileName($File)
  5.         $Global:Extension = ([IO.Path]::GetExtension($File))
  6.  
  7.         #Commandarg is shown correctly, but it does not show form1
  8.         if ($($Extension -like '.exe') -or $($Extension -like '.msi'))
  9.         {
  10.             Show-Form1_psf
  11.            
  12.         } #exe or msi
  13.         else
  14.         {
  15.             Show-Form2_psf
  16.         }
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Open document with exe of Sapien PS Studio

Post by jvierra »

The "Show" function will only exist if you add the form to the project correctly. Just adding it as a file it will not be a function and will not be visible in autocomplete.

Adding an external file to a forms project will require calling the forms PS1 file:

.\yourform.ps1
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Open document with exe of Sapien PS Studio

Post by stevens »

Thanks, the show is not the problem. Both forms show correctly when called.

The variable file is not recognized, args is recognized, but I can t get the args into extension, FileName, path.

In otter words: "If extension" does not work. It always shows the same form.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Open document with exe of Sapien PS Studio

Post by jvierra »

There is still no way to understand what you are asking. What arguments? WHere are they defined? Where are you trying to use them?
Again - we need an full code example that is simple and demonstrates what is wrong.

What is $commandarg? Where is it defined?
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Open document with exe of Sapien PS Studio

Post by stevens »

Hope this makes it clear.
When the project starts as exe, it should read the argument passed to it (dragging a file to it). Then when it should open form1,form2 or form3 based upon the argument passed.
F.e. if it is .exe it should open formx, when no argument formy, else formz.
Attachments
Example.zip
Example project
(91.61 KiB) Downloaded 86 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Open document with exe of Sapien PS Studio

Post by jvierra »

The following works fine for me:

Code: Select all

function Main {
	Param ($commandarg)
	
    $file = [system.io.directoryinfo]$commandarg
    if (! $commandarg){
        Show-Form1_psf
    }elseif($file.Extension -match 'exe|msi'){
        Show-Form2_psf
    }else{
        [System.Windows.Forms.MessageBox]::Show($commandarg)
        Show-Form3_psf
    }

	$script:ExitCode = 0 #Set the exit code for the Packager
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Open document with exe of Sapien PS Studio

Post by jvierra »

I was wondering why this was so hard for you but I realize that complex logic can be difficult for non-programmers.

Here is another approach that may help you to see what is happening here:

Code: Select all

function Main {
	Param ($commandarg)
	
    switch -regex ($commandarg){
        '^$'             {Show-Form1_psf}
        '\.exe$|\.msi$'  {Show-Form2_psf}
        default          {Show-Form3_psf}
    }

	$script:ExitCode = 0 #Set the exit code for the Packager
}
I should also note that $commandarg is only defined in thtat one function so it may have been that you were trying to use it elsewhere or that you had created your own variable with that name.
This topic is 4 years and 3 months 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