Sign in to follow this  
Followers 0
GTunney

Copy file as Domain User

18 posts in this topic

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)

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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

Know the feeling :)

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


My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Share this post


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

Share this post


Link to post
Share on other sites

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

Share this post


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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


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

Share this post


Link to post
Share on other sites

Any suggestions could really do with getting this resolved?

Share this post


Link to post
Share on other sites

You execute only the above code and you get 10 msgboxes ?

Share this post


Link to post
Share on other sites

Yes correct, also multiple instanced of the auto it script appear to be running. If i look in the task bar there is about 10 auto it icons load up then eventually close.

Share this post


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

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

You need to change it a little bit like this:

FileCopy("C:\Acucorp\Acucbl722\AcuGT\bin\Optim Live System.lnk","C:\Documents and Settings\"&@UserName&"\Desktop",1)

Share this post


Link to post
Share on other sites

Beautiful works a treat, knew it would be something simple.

Also anyway to ensure it kills the users session once the files have been copied over?

Thanks for your help.

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