Jump to content

RunAsWait & File Copy


Recommended Posts

Hi,

I am trying to upload file from local machines into remote network path.

If I use the same as FileCopy($Source, $Destination, 1) it works only for me. But for others it will require access to upload files. But RunAs is not working. Is my command incorrect?

Global $UserID = "username"
Global $Domain = "domain"
Global $Password = "password"
Global $Source = "C:\Test\Test.log"
Global $Destination = "\\Server Folder Path"

RunAsWait($UserID, $Domain, $Password, 0, @ComSpec & " /c copy " & $Source & " " & $Destination, "", @SW_HIDE)

 

Link to comment
Share on other sites

Untested, but according to the help: " It is important to specify a working directory the user you are running as has access to, otherwise the function will fail. "

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
Share on other sites

@Marc, thanks for quick response. I figured that the issue was with the destination folder and filename which had spaces. For some reason if there is space is folder or file structure it won't copy. It works without any spaces.

But it works from command line, not from the code. So users will not have access to the location which is why I am specifying the account credentials which will have. Should I be using 2 or 4 here?

Global $UserID = "username"
Global $Domain = "domain"
Global $Password = "password"
Global $Source = "C:\Test\Test.log"
Global $Destination = "\\Server_Folder_Path"

RunAsWait($UserID, $Domain, $Password, 0, @ComSpec & " /c copy " & $Source & " " & $Destination, "", @SW_HIDE)
Link to comment
Share on other sites

RunAsWait($UserID, $Domain, $Password, 0, @ComSpec & ' /c copy "' & $Source & '" "' & $Destination &'"', @TempDir, @SW_hide)

Try this one. Should fix it :)

Or the  the visible solution where you can read the result message:

RunAsWait($UserID, $Domain, $Password, 0, @ComSpec & ' /k copy "' & $Source & '" "' & $Destination &'"', @TempDir, @SW_show)

 

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
Share on other sites

strange. Tried it with our test user, works fine... :think:

UNC pathes work, too. No idea why you get the error message.

Edited by Marc

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to comment
Share on other sites

Link to comment
Share on other sites

Does the account you are using have rights to the local machine?

If the account is for the destination only, try using $RUN_LOGON_NETWORK  for the logon_flag parameter.

Link to comment
Share on other sites

4 hours ago, spudw2k said:

Does the account you are using have rights to the local machine?

If the account is for the destination only, try using $RUN_LOGON_NETWORK  for the logon_flag parameter.

Yes, the account has rights to both the local machine and network path. That's why command line parameter is able to copy files but not via the autoIT code.

Link to comment
Share on other sites

Is it not possible to avoid the runaswait then and just run the script with the desired user?

The fact that the runaswait is giving an access denied tells me the account perms are wrong somewhere.

It's hard to troubleshoot without the full picture, so I apologize for redundant questions, but are you positive that the account has permissions on the source folder?

What about my earlier question?

12 hours ago, spudw2k said:

If you do a manual test using a cmd prompt and the runas tool, does it work?

runas /user:domain\username cmd.exe

copy source dest

 

Link to comment
Share on other sites

3 hours ago, spudw2k said:

Is it not possible to avoid the runaswait then and just run the script with the desired user?

The fact that the runaswait is giving an access denied tells me the account perms are wrong somewhere.

It's hard to troubleshoot without the full picture, so I apologize for redundant questions, but are you positive that the account has permissions on the source folder?

What about my earlier question?

 

I used my own credentials which has admin rights to both local machine and Network path. That's why running the command line from Windows CMD works with no issues but I am not sure why it says "Incorrect User name and password" from AutoIT command line.

The only reason I am using RunAsWait is my creds will not have admin rights to other users machines and eventually I will be using some elevated accounts. But the process and command line will be the same.

Also to let you know, the destination path is a SharePoint site library. I tried looking for other solution to add / upload files from local to SP but there was not much found. Which is why I had to go via the RunAsWait command line to get it simply as File copy method.

Link to comment
Share on other sites

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...