1. JOHN THOMAS
  2. PowerBuilder
  3. Tuesday, 11 August 2020 23:36 PM UTC

Greetings all - didn't see anything quite like this in the Q/A so far. We suddenly have a special problem when calling this .Net exe from new PB. This arrangement has been and is still working for 10+ years now on a Windows 2003/PB 12.5 combination, but we are now trying to run this in a much newer (Windows 2019) platform. I am finding, for one, that just about every app needs the "run as administrator" setting turned to be able to run them correctly. Whatever, the below is the PB code snip and the error we're getting:

====================

wsh = CREATE OleObject
li_rc = wsh.ConnectToNewObject( "WScript.Shell" )


ls_temp = lsExe + " ~"" + lljob +"~" ~"" + ldFrom + "~" ~"" + ldthru + "~" ~"" + lsRootFolder + "~" ~"" + lsDbServer + "~" ~"" + lsDbName + "~" ~"" + lsTempFolder + "~""


li_rc = wsh.Run(ls_temp, NORMAL, WAIT)

==========================

On the above call to Run() we are getting simply "error calling external object function RUN".  That's all. All args composing the ls_temp var string have valid values, none null (we'd probably get the "null arguments" error if that were the case).   Note that the .Net exe in lsExe runs fine when run standalone and I also have it set to "run as administrator" in the Compatibility tab (right mouse on file), so I'm hoping that our PB calling app is not running into that deficiency; it's not saying that it is anyway. The "Run()" function doesn't seem to have very many options for feedback. Anyway, we need a way out of this asap. Any help appreciated, thanks!

JOHN THOMAS Accepted Answer Pending Moderation
  1. Monday, 17 August 2020 17:35 PM UTC
  2. PowerBuilder
  3. # 1

Thanks Chris for your  17 August 2020 17:30 PM reply, and all of you, really appreciate the input. We have solved the problem actually by means of some of your input and some help from our infrastructure guys whose solution I'm not at liberty to discuss cool.  Anyway, it wasn't complicated. Consider this resolved!  best,  jt

Comment
  1. Chris Pollach @Appeon
  2. Monday, 17 August 2020 18:39 PM UTC
Hi John .. that is "awesome" news & thanks for letting us know! :-)
  1. Helpful
There are no comments made yet.
JOHN THOMAS Accepted Answer Pending Moderation
  1. Wednesday, 12 August 2020 19:33 PM UTC
  2. PowerBuilder
  3. # 2

Hi again folks  - this is in response to Chris in particular re: the manifest settings in Project Painter. I looked this up and think from the help info below, the two options I have in red would probably be the most needed. I don't know if any of these manifest settings kick in at all when running source code in debug. I think the below red would at least ensure we're giving the app the highest privilege level it could get from Windows environment. Maybe. thanks.  

 =================================

Attaching or embedding manifest files
Prev Creating Executables and Components Next

--------------------------------------------------------------------------------

Attaching or embedding manifest files
If you want to deploy an application to the Windows Vista operating system that meets the certification requirements of the Windows Vista Logo program, you must follow User Account Control (UAC) guidelines. The executable file must have an embedded manifest that defines the execution level and specifies whether access to the user interface of another window is required. The Vista Application Information Service (AIS) checks the manifest file to determine the privileges with which to launch the process. Use the Security tab page in the Project painter to specify these properties.

Generate options

Select Embedded manifest if your application needs to be certified for Vista. A manifest file with the execution level you select is embedded in the application's executable file.

You can also select External manifest to generate a standalone manifest file in XML format that you ship with your application's executable file, or No manifest if you do not need to distribute a manifest file.

 

Execution level

Select As Invoker if the application does not need elevated or administrative privileges. Selecting a different execution level will probably require that you modify your application to isolate administrative features in a separate process to receive Vista certification.

Select Require Administrator if the application process must be created by a member of the Administrators group. If the application user does not start the process as an administrator, a message box displays so that the user can enter the appropriate credentials.

Select Highest Available to have the AIS retrieve the highest available access privileges for the user who starts the process.

UI access

If the application needs to drive input to higher privilege windows on the desktop, such as an on-screen keyboard, select the "Allow access to protected system UI" check box. For most applications you should not select this check box. Microsoft provides this setting for user interface Assistive Technology (Section 508) applications.

Authenticode signing required
If you check this box, the application must be Authenticode signed and must reside in a protected location, such as Program Files or Windows\system32.


--------------------------------------------------------------------------------
Prev Up Next
Using dynamic libraries Home Distributing resources

Comment
  1. Chris Pollach @Appeon
  2. Monday, 17 August 2020 17:30 PM UTC
Hi John. Sorry for the slow reply. I was on vacation last week and also somehow missed your reply. I would start with the "Embedded manifest " option first. It's the easiest option to try and does not involve anything complicated. Just a recompile of your EXE. If that does not help, then the external manifest route would be my alternate route. HTH
  1. Helpful
There are no comments made yet.
JOHN THOMAS Accepted Answer Pending Moderation
  1. Wednesday, 12 August 2020 15:04 PM UTC
  2. PowerBuilder
  3. # 3

Thanks gents for all the quick feedback. To try to answer:

Armeen - don't know the 32 vs. 64 bit yet, I will try to find out. re: new .Net calls, we are trying to avoid any new development to this PB code as the whole thing is going away soon...but I'll keep it in mind

 

Chris  - Thanks for the Run & Wait example, though I don't think those addl input settings are what's needed...the thing is not even opening the shell window at all, hence I think the solution (if any) is more in this area, or what Roland/Miguel are pointing to:

re:  Have you tried using the MS-Windows compatibility mode setting or including a manifest in your EXE (project painter)?  -- as per my message:

"...Note that the .Net exe in lsExe runs fine when run standalone and I also have it set to "run as administrator" in the Compatibility tab (right mouse on file)..."

That's all I've done, is there more to compatibility settings that I could do?  

 

Roland /Miguel - thanks, I'll have to get with my infra guy to see about further Windows settings, but I'll check out your PB examples. 

 

I'll let you all know what I find!

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 12 August 2020 08:53 AM UTC
  2. PowerBuilder
  3. # 4

Security on Windows 2019 is probably much tighter than on 2003. Therefore I'd expect it to be more demanding on security. Maybe there are some settings of WS 2019 which would allow you to run shell scripts without "running as admin".

 

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Wednesday, 12 August 2020 02:06 AM UTC
  2. PowerBuilder
  3. # 5

I have a RunAndWait example that uses Windows API functions. Also can capture the program's return code.

https://www.topwizprogramming.com/freecode_runandwait.html

 

Comment
  1. JOHN THOMAS
  2. Wednesday, 12 August 2020 16:03 PM UTC
hey Roland - looked at a little bit of your examples, very comprehensive. If I can beg a little, you could save me a lot of time and wrong roads by pointing me to a specific function in the object/s that can capture the shell return code. This is really what I need. I don't think our routines being run in the shell app are going to have any problems with timeouts, depending on how many policies we have to load and zip up it might run as long as 3-4 mins but it's never had a problem waiting so far. It's really this new Windows environment + admin rights b.s. that I think is choking the thing. Appreciate it.
  1. Helpful
  1. Roland Smith
  2. Wednesday, 12 August 2020 19:57 PM UTC
GetExitCodeProcess returns the exit code of the external program.

In my n_runandwait object there are three of_run functions. Look at the first one in the list. The other two are overrides.

If you remove the timeout code, it looks like this:



If CreateProcess(ls_null, as_exefullpath, ll_null, &

ll_null, False, ll_CreationFlags, ll_null, &

ls_null, lstr_si, lstr_pi) Then

// wait until process ends

WaitForSingleObject(lstr_pi.hProcess, INFINITE)

// check for exit code

GetExitCodeProcess(lstr_pi.hProcess, ll_ExitCode)

// close process and thread handles

CloseHandle(lstr_pi.hProcess)

CloseHandle(lstr_pi.hThread)

Else

// return failure

ll_ExitCode = -1

End If



Return ll_ExitCode
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 12 August 2020 00:29 AM UTC
  2. PowerBuilder
  3. # 6

Hi John;

   Code like yours has been running for ages... Run & Wait.

     Have you tried using the MS-Windows compatibility mode setting or including a manifest in your EXE (project painter)?

Regards ... Chris

Comment
There are no comments made yet.
Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 12 August 2020 00:04 AM UTC
  2. PowerBuilder
  3. # 7

Was your Windows 2003 32-bit and 2019 64-bit?

It might be the .NET EXE is running as 64-bit and so your 32-bit process cannot access it.

Just FYI, PB 2019 R2 supports 64-bit compilation and there is new objects and DLL importer to natively call .NET DLLs from PowerScript.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.