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.
User avatar
stevens
Posts: 365
Joined: Wed Jun 15, 2016 2:26 am

Open document with exe of Sapien PS Studio

Post by stevens » Fri Dec 06, 2019 9:32 am

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: 7151
Joined: Tue May 29, 2007 4:43 pm

Re: Open document with exe of Sapien PS Studio

Post by Alexander Riedel » Fri Dec 06, 2019 9:37 am

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: 365
Joined: Wed Jun 15, 2016 2:26 am

Re: Open document with exe of Sapien PS Studio

Post by stevens » Fri Dec 06, 2019 3:55 pm

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: 365
Joined: Wed Jun 15, 2016 2:26 am

Re: Open document with exe of Sapien PS Studio

Post by stevens » Mon Dec 09, 2019 6:51 am

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.        
  4.  
  5.         $Global:Extension = ([IO.Path]::GetExtension($File))
  6.  
  7.         $Global:FileName = [io.path]::GetFileName($File)
  8.  
  9.         $Global:Extension = ([IO.Path]::GetExtension($File))
  10.  
  11.  
  12.  
  13.         #Commandarg is shown correctly, but it does not show form1
  14.  
  15.         if ($($Extension -like '.exe') -or $($Extension -like '.msi'))
  16.  
  17.         {
  18.  
  19.             Show-Form1_psf
  20.  
  21.            
  22.  
  23.         } #exe or msi
  24.  
  25.         else
  26.  
  27.         {
  28.  
  29.             Show-Form2_psf
  30.  
  31.         }

jvierra
Posts: 14045
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Open document with exe of Sapien PS Studio

Post by jvierra » Mon Dec 09, 2019 1:50 pm

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: 365
Joined: Wed Jun 15, 2016 2:26 am

Re: Open document with exe of Sapien PS Studio

Post by stevens » Mon Dec 09, 2019 1:57 pm

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: 14045
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Open document with exe of Sapien PS Studio

Post by jvierra » Mon Dec 09, 2019 3:14 pm

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: 365
Joined: Wed Jun 15, 2016 2:26 am

Re: Open document with exe of Sapien PS Studio

Post by stevens » Mon Dec 09, 2019 4:44 pm

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 12 times

jvierra
Posts: 14045
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Open document with exe of Sapien PS Studio

Post by jvierra » Mon Dec 09, 2019 5:12 pm

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: 14045
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Open document with exe of Sapien PS Studio

Post by jvierra » Mon Dec 09, 2019 8:13 pm

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.

Locked