Sign in to follow this  
Followers 0
southboyj

FileCopy inside RunAs

8 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@southboyj

try

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

HTH,

whim

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

LOL, yeah, missed that. AutoIt will not recognise vars within a string, so maybe this will work:

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

Share this post


Link to post
Share on other sites

I have a workaround that may be acceptable...

I create a script that contains FileCopy and I right-click and do a RUNAS from Windows. Worked like a champ.

Thanks for playing....

Share this post


Link to post
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
Sign in to follow this  
Followers 0