Jump to content

Copy file as Domain User


GTunney
 Share

Recommended Posts

I use AutoIT to roll out mass software installations. I'm currently working on a script at the moment which copies files from a server to the local c drive and then copies a shortcut to the desktop. The files copy to the c drive no problem but it will not copy the shortcut. I have tried to use the RunAs command for the whole script but it doesnt appear to be working. any help would be appreciated.

Username, password and domain have been removed for security reasons.

; Fill in the username and password appropriate for your system.
Local $sUserName = "Username"
Local $sPassword = "Password"
Local $sDomain = "Domain.net"
Local $sShare = "\\helpdeskdev01\software"
Local $sLocation = $sShare & "\optim\"

;Copy files to local drive and shortcut.
DirCreate("C:\Acucorp\Acucbl722\AcuGT\bin")
FileCopy("\\helpdeskdev01\software\optim\files\*.*","C:\Acucorp\Acucbl722\AcuGT\bin",1)
FileCopy("C:\Acucorp\Acucbl722\AcuGT\bin\Optim Live System.lnk","C:\Documents and Settings\All Users\Desktop",1)
Link to comment
Share on other sites

Just to save a lot of time: why not via Group Policies?

Because the business has over 5000 users and it's not needed on all the machines, just about 200 in a certain building.

Not to mention our infrastructure team is pretty erm....lazy!

Edited by GTunney
Link to comment
Share on other sites

Know the feeling :)

In the AutoIt help file FileCopy is done with a trailing slash in the destination path. Try that please.

It's not the file path i'm having trouble with as the files do copy over. It's just the shortcut at the end which will not copy over.

As the All Users folder only has domain admins access. Which is why i wanted to runas which ever user is specified at the top.

Link to comment
Share on other sites

Check out the RUNAS examples. You can RUNAS your entire script as a domain user too.

It's deffo a file permission as it works fine when an admin runs it.

Thats what im trying to acheive juvigy and have looked at examples but can't figure it out.

Link to comment
Share on other sites

Try this:

Local $sUserName = "Username"
Local $sPassword = "Password"
Local $sDomain = "Domain.net"
RunAs($sUserName , $sDomain , $sPassword ,0,@ScriptName,@ScriptDir)

I've given that a go but just get error messages.

EDIT: My fault i left some old code in there, it's been tested and working perfectly.

Thanks for all your help :)

Edited by GTunney
Link to comment
Share on other sites

Ok got another slight problem, i've added a Installation Complete box at the very end and this box keeps opening like 10 times. I've checked the sessions as well and to copy the files over it's opening 10 sessions and running multiple instances of the auto it.

; Fill in the username and password appropriate for your system.
Local $sUserName = "username"
Local $sPassword = "password"
Local $sDomain = "domain"
RunAs($sUserName , $sDomain , $sPassword ,2,@ScriptName,@ScriptDir)

;Copy files to local drive and shortcut.
DirCreate("C:\Acucorp\Acucbl722\AcuGT\bin")
FileCopy("\\helpdeskdev01\software\optim\files\*.*","C:\Acucorp\Acucbl722\AcuGT\bin",1)
FileCopy("C:\Acucorp\Acucbl722\AcuGT\bin\Optim Live System.lnk","C:\Documents and Settings\All Users\Desktop",1)


; Show a message.
MsgBox(0, "Optim Live System Installed", "Any issues please contact the BIS Service desk on 0191 247 3999")
Link to comment
Share on other sites

I cant test it but i think it does it because it runas every file copy process separately.

FileCopy("\\helpdeskdev01\software\optim\files\*.*","C:\Acucorp\Acucbl722\AcuGT\bin",1)

Change this to a only one file copy to test it.

Link to comment
Share on other sites

Ok it was the RunAs command that was causing it to run numerous times even with 1 file it would run numerous times.

I have removed the runas command and instead of copying the shortcut to all users desktop i am just trying to copy it to the logged on users desktop but having some trouble with the variable.

I have tried both @UserName and %UserName% but if i enter the username of the logged on user it works fine.

;Copy files to local drive and shortcut.
DirCreate("C:\Acucorp\Acucbl722\AcuGT\bin")
FileCopy("\\helpdeskdev01\software\optim\files\*.*","C:\Acucorp\Acucbl722\AcuGT\bin",1)
FileCopy("C:\Acucorp\Acucbl722\AcuGT\bin\Optim Live System.lnk","C:\Documents and Settings\@UserName\Desktop",1)

; Show a message.
MsgBox(0, "Optim Live System Installed", "Any issues please contact the BIS Service desk on 0191 247 3999")
Edited by GTunney
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...