I am trying to follow this (rather old) instruction for how to copy files to a network share with elevated credentails, but I cannot get it to work.
http://codeverge.com/sybase.powerbuilder.general/copy-files-to-network-with-elevat/1038363
My code is below.
/**************************************************************************************
// External Functions
public function boolean RevertToSelf() LIBRARY "advapi32.dll" alias for "RevertToSelf;Ansi"
public function boolean LogonUser(string lpszUserName, string lpszDomain, string lpszPassword, long dwLogonType, long dwLogonProvider, ref long phToken) LIBRARY "advapi32.dll" alias for "LogonUserA;Ansi"
public FUNCTION boolean ImpersonateLoggedOnUser(long IntPtr) LIBRARY "advapi32.dll" alias for "ImpersonateLoggedOnUser;Ansi"
// Function parameters as_user string, as_domain string, as_password string
boolean lb_ret
int li_return
long ll_token
string as_user, as_domain, as_password
as_user = "aUser"
as_password = "aPassword"
as_domain = "myDomain"
ll_token = 0
lb_ret = LogonUser(as_user, as_domain, as_password, 3, 0, ll_token)
lb_ret = ImpersonateLoggedOnUser(ll_token)
li_return = FileCopy('c:\test.pdf', 'S:\temp\restricted\test.pdf', True)
RevertToSelf()
//CloseHandle(ll_token)
/**************************************************************************************
If I create a restricted folder on my local machine and attempt to copy a file to it via the above it works. If I runt he same code and try to copy to a network share, it fails.
Is there an issue with the above I'm not seeing, or maybe a better way to accomplish my goal?
Thanks!
What I'm trying to get away from is opening up my network share permissions to match that of the user(s) who are running the application. I want to avoid intentional or unintentional meddling in the network share folder by these users to as to keep sub-folders and file names predictable. That's why I figured I would lock down file permissions to a service account only and have my app use that account when doing I/O.