Jump to content

Copy Files with RunAs


DiegoT
 Share

Recommended Posts

Hi,
I'm a new user of AutoIT and Forum then sorry if this question has already been answered, however I tried to find a solution to this problem and so far I have not found it.

I just want to copy some files from a network share to Program Files directory, but to do this I need to run with administrative credentials, because it will run by common users.

I try this script:

#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <Constants.au3>

;Credentials
Local $sUserName = "adminuser"
Local $sPassword = "adminpwd"
Local $sDomain = "domain"
RunAs($sUserName , $sDomain , $sPassword ,2,@ScriptName,@ScriptDir)

MsgBox($MB_ICONWARNING, "Auto Atualização do AX-PDV", "Este procedimento irá atualizar o AX PDV. Feche o AX PDV antes de inicar a atualização e clique em OK. ESTE PROCEDIMENTO IRÁ INICIAR AUTOMATICAMENTE EM 10 SEGUNDOS OU CLICANDO EM OK", 10)

;Copia as dlls atuais da pasta POSUpdates do servidor da loja para as pastas raiz e Extensions
FileCopy("\\homeserver\POSUpdates\Extension\","C:\Program Files (x86)\Microsoft Dynamics AX\60\Retail POS\Extensions",$FC_OVERWRITE))
FileCopy("\\homeserver\POSUpdates\Raiz\","C:\Program Files (x86)\Microsoft Dynamics AX\60\Retail POS",$FC_OVERWRITE))

but didn't work. 

Then I try it:

RunAsWait($sUserName, $sDomain, $sPassword, 0, @ComSpec & " /c copy /Y \\homeserver\POSUpdates\Extension\ C:\temp", "", @SW_HIDE)

but it didn't work too.

What am I doing wrong?

thank you all!

 

Link to comment
Share on other sites

RunAs and RunAsWait does not request the Admin Token when it executes.  It will only runs the process under the context of the requested user, not with full admin rights, even if the user is in the local Administrator's group.  There are some workarounds for this, just search the forum for "RunAs Admin Token."  

 

Adam

 

Link to comment
Share on other sites

17 hours ago, JohnOne said:

Run and runAs require a program for example a .exe not a file like .au3.

That's just for a start.

Thank you JohnOne.
Do you have any ideia that how can I do this copy as administrative privilegies? 
I thought about calling a bat script but I believe this is not the most correct way to do this.

Link to comment
Share on other sites

18 hours ago, AdamUL said:

RunAs and RunAsWait does not request the Admin Token when it executes.  It will only runs the process under the context of the requested user, not with full admin rights, even if the user is in the local Administrator's group.  There are some workarounds for this, just search the forum for "RunAs Admin Token."  

 

Adam

 

Hi AdamUL, thank you for your reply.

So, I searched for "RunAs Admin Token" and I found some information about UAC, ConsentPromptBehaviorAdmin and #RequireAdmin but not that I can understand it in my case.

I just need to run a copy from a network share to "C:\program files\..." and the current user don't have permission on "C:\program files\".

Do you know a way to do it by autoit?

Tks a lot!

Link to comment
Share on other sites

16 hours ago, jguinch said:

 - the UAC is enabled ?
 - the user you specified in RunAs can access the files on the remote share ?

Hi, tks for your reply.

Yes, the UAC is enabled.
Yes, the user that I specified have access for both, source and destination. I tested running cmd with this user and running the copy command and it worked fine.

Link to comment
Share on other sites

So, you "just" need to bypass the UAC prompt ? Well, not easy. The simpler way is to specify the local builtin administrator account in your RunAs call. This account (not others local admins) is not concerned by the UAC prompt. If it doesn't have access to the remote share, use DriveMapAdd with a user having rights.

 

 

Link to comment
Share on other sites

  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...