Jump to content

FileCopy inside RunAs


Recommended Posts

I want to be able to copy a file from a share the user will have full control of to the C$ share of another computer which they will need to enter admininstrative credentials for. I don't want to map a drive. The problem is that RunAs doesn't see the FileCopy function as a program. I'm sure there is something smple I am overlooking. Script is below. Thanks

;Variables

$UserID = InputBox ("User", "Enter Administrative Account", "", "")

$Password = InputBox ("Password", "Enter Password","", "X")

$Domain = InputBox ("Domain", "Enter Domain","" , "")

$ComputerName = InputBox ("Computer", "Enter Computer Name or IP Address","", "")

RunAsWait ($UserID, $Domain, $Password, 0, FileCopy ('\\ServerName\ShareName\FileName.cmd', '\\' & $ComputerName & '\c$\', 1), "", @SW_HIDE, "")

Edited by southboyj
Link to comment
Share on other sites

That is because FileCopy is an AutoIt function and not a program. RunAsWait expects a program parameter to run, which is not what it is getting.

Where do you intend to run the script? Which computer, your's, the user's, a third computer?

You could try:

RunAsWait($UserID, $Domain, $Password, 0, "copy \\ServerName\ShareName\FileName.cmd \\$ComputerName\c$\", "", @SW_HIDE)

No guarantees though.

Edited by omikron48
Link to comment
Share on other sites

That is because FileCopy is an AutoIt function and not a program. RunAsWait expects a program parameter to run, which is not what it is getting.

Where do you intend to run the script? Which computer, your's, the user's, a third computer?

You could try:

RunAsWait($UserID, $Domain, $Password, 0, "copy \\ServerName\ShareName\FileName.cmd \\$ComputerName\c$\", "", @SW_HIDE)

No guarantees though.

Thanks. Will try that. The script will be run from local computer copying a file from a remote server to a remote computer.
Link to comment
Share on other sites

Actually I tried:

;Variables

$UserID = InputBox ("User", "Enter Administrative Account", "", "")

$Password = InputBox ("Password", "Enter Password","", "X")

$Domain = InputBox ("Domain", "Enter Domain","" , "")

$ComputerName = InputBox ("Computer", "Enter Computer Name or IP Address","", "")

RunAsWait($UserID, $Domain, $Password, 0, "copy \\Servername\Sharename\Filename.cmd \\" & $ComputerName & "\c$\", "", @SW_HIDE)

and received the same results. Any other thoughts

Link to comment
Share on other sites

It doesn't work.

RunAsWait($UserID, $Domain, $Password, 0, @ComSpec & " /c copy \\ServerName\ShareName\FileName.cmd \\$ComputerName\c$\", "", @SW_HIDE)

The $Computername variable above in BOLD is not recognized as a variable when entered like this.

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