Jump to content

Recommended Posts

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

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

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

Posted

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.

Posted

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)
Posted

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

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
  • Recently Browsing   0 members

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