1. Lawrence Anderson
  2. PowerBuilder
  3. Tuesday, 31 March 2020 16:10 PM UTC

Is there a way to execute "Datastore.SaveAs(ls_filename, PDF!, false)" as a specific Windows user? I'm working on a process that involves a user hitting a button in a powerbuilder application which causes datawindow results to be saved off as PDFs at a network location. Another individual in my department would like to have the network location locked down so normal users can't access it for security reasons.

Is there a way that I can perform the "SaveAs" in Powerbuilder in a way that it can write to a location the user of the application wouldn't normally be able to write files? We're already going to make undiscoverable on the network if you don't know the file path.

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 31 March 2020 16:32 PM UTC
  2. PowerBuilder
  3. # 1

Hi Lawrence;

   You could ...

1) Run an external (even hidden) EXE that has the raised privileges for this type of operation.

2) Create a PB based .Net IIS Web Service that performs this PDF task for you into a privileged location.

Food for thought.
Regards ... Chris

Comment
  1. Lawrence Anderson
  2. Tuesday, 31 March 2020 17:03 PM UTC
Thanks. I was hoping to keep the PDF generation confined to the application that is going to start the trigger from a maintenance standpoint (the datawindow that defines the layout is already used in the application, this is just an added feature).

For 1, would Powerbuilder be able to trigger an external executable to run with raised privileges (with Powerbuilder providing any needed credentials)? I've made use of "Run" within powerbuilder before, but I didn't know if there's syntax to set the run as user.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Wednesday, 1 April 2020 17:23 PM UTC
Hi Lawrence;

FWIW: Instead of an EXE, you can Run() either a Short-Cut or a batch command file that has the raised privileges already assigned. Food for thought. ;-)

Regards ... Chris

  1. Helpful
There are no comments made yet.
Kevin Ridley Accepted Answer Pending Moderation
  1. Tuesday, 31 March 2020 16:40 PM UTC
  2. PowerBuilder
  3. # 2

In addition to what Chris said, you could save the file local temporarily and FTP it to another location, then delete the file.  You can do a try/catch/finally with the delete in the finally block to make sure it's not saved locally even if there's an error.

 

KR

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 31 March 2020 16:58 PM UTC
  2. PowerBuilder
  3. # 3

UNC naming will allow saving to any network folder that the user has permission to. UNC naming:

\\servername\sharename\folder

You can collect the file name from a PB window and then build the UNC file name to pass to SaveAs using hard coded servername & sharename.

Comment
There are no comments made yet.
Brad Mettee Accepted Answer Pending Moderation
  1. Wednesday, 1 April 2020 14:16 PM UTC
  2. PowerBuilder
  3. # 4

There is one issue you'll likely run into trying to save to a network drive. If you have already attached to another computer, you can't attach to the same one a second time with a different username:

If you Attach to \\Server1\Resource1 as SomeUser, then you can attach to any other resource on the server as that user (providing you have rights to it), without needing a password. As soon as you try to connect with a different username, you'll get a system error 1219, whose error text looks something like this: "Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again."

It is possible to call networking functions within windows to use a resource (and release it), using these two function definitions:
Function Int WNetAddConnection2( ref stru_netresource nr, ref string password, ref string username, long flags) library "mpr.dll" alias for "WNetAddConnection2W"
Function Int WNetCancelConnection2( ref string s_resourcename, long flags, int forceclose) library "mpr.dll" alias for "WNetCancelConnection2W"

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Wednesday, 1 April 2020 14:21 PM UTC
  2. PowerBuilder
  3. # 5

I'm thinking that Kevin's idea of using FTP is the simplest way to do it.

I have an example of using WinInet to do FTP:

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

WinInet doesn't support SFTP.

 

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.