Jump to content
Sign in to follow this  
gh0stid

Need help, runas create directory and copy of file from server to computer

Recommended Posts

gh0stid

Hello

really sorry to bother you with such stupid question but ive searched everywhere and didnt succeed to find a solution to my problem ..

lemme get it straight :

i need to copy file from server shared path to the computer running the script ( at logon ) users dont have the right to create directory in "c:\program files\" SO it need to be elevated right command. ( sorry for my english )

heres the script that work with admin right on the computer :

#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
;validation si installation déja présente
If FileExists ("C:\program Files\Cogep\GuideTI\connexion.xml") Then
   fin()
Else
   install()
   EndIf
  
Func install()
; Demarrer la désinstallation
DirCreate("c:\program files\cogep\guideti")
FileCopy("\\sc15\app\guideti\maj\*.*", "C:\program files\Cogep\GuideTI\")
EndFunc
;FIN DU SCRIPT
func fin()
   Exit
EndFunc

i need to run these function with admin right with a specific account and password ( hardcoded in the script )

please.. point me in the right direction, im having a bad time ... seriously lol

Share this post


Link to post
Share on other sites
water

In AutoIt you can't run just parts of a script with elevated permissions. It's all or nothing.

You could use RunAs with elevated permissions.

Use RunAs to run DOS shell (as described ifor function Run in the help file) and replace DirCreate with mkDir and FileCopy with copy.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
gh0stid

i know in autoti i cant run just part of the script with elevated persmission

but theres one problem ... our fortigate firewall keep the last login used to verify if you have access to internet or not.

if i elevate my whole script, our user will lose access to internet on each login ( since even the validation of the connexion.xml file will be run with elevated right ) and it will generate a lot of useless call to our IT department ..

i need to be able to do the verification first without runas function

then if needed, runas and create the directory then copie the file.

i tried that :

#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
;validation si installation déja présente
If FileExists ("C:program FilesCogepGuideTIconnexion.xml") Then
fin()
Else
install()
EndIf

Func install()
; Demarrer la désinstallation
RunAs ("USERNAME", "DOMAIN", "PASSWORD", 0, @ComSpec & " /c " "MKdir 'c:program filesCogepGuideTI'" ,"",@SW_HIDE)
EndFunc
;FIN DU SCRIPT
func fin()
Exit
EndFunc

still not working. please help and thank you for your fast answer.

Edited by gh0stid

Share this post


Link to post
Share on other sites
water

This works fine for me:

install()

Func install()
    $iResult = RunAs("user", "domain", "password", 0, @ComSpec & ' /c MKdir "c:tempx y z"', "", @SW_HIDE)
    MsgBox(0, "", $iResult)
EndFunc ;==>install

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
gh0stid

This works fine for me:

install()

Func install()
$iResult = RunAs("user", "domain", "password", 0, @ComSpec & ' /c MKdir "c:tempx y z"', "", @SW_HIDE)
MsgBox(0, "", $iResult)
EndFunc ;==>install

still not working for me ...

can it be cause i run windows 7 ?

it doesnt give any error, but the directory isnt create at all in program files ..

Share this post


Link to post
Share on other sites
water

What's the result of MsgBox?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
BrewManNH

RunAs ("USERNAME", "DOMAIN", "PASSWORD", 0, @ComSpec & " /c " "MKdir 'c:program filesCogepGuideTI'" ,"",@SW_HIDE)

still not working. please help and thank you for your fast answer.

You're missing an ampersand "&" in between the " /c " and the "MKdir statements in the RunAs command, which is why it didn't work for you, using water's code eliminates needing this.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
gh0stid

You're missing an ampersand "&" in between the " /c " and the "MKdir statements in the RunAs command, which is why it didn't work for you, using water's code eliminates needing this.

actual code :

#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator

;validation si installation déja présente
If FileExists ("C:program FilesCogepGuideTIconnexion.xml") Then
fin()
Else
install()
EndIf

Func install()
; Demarrer la désinstallation
RunAs ("USERNAME", "DOMAIN", "PASSWORD", 0, @ComSpec & ' /c MKdir "c:program filesCogepGuideTI"', "", @SW_HIDE)
RunAs ("USERNAME", "DOMAIN", "PASSWORD", 0, @Comspec & ' /c copy "sc15appguidetimaj*.*" "C:program filesCogepGuideTI"', "", @SW_HIDE)
;DirCreate("c:program filescogepguideti")
;FileCopy("sc15appguidetimaj*.*", "C:program filesCogepGuideTI")
EndFunc

;FIN DU SCRIPT
func fin()
Exit
EndFunc

i must be dumb, I still dont see what is wrong with my script :

>"C:Program FilesAutoIt3SciTE..autoit3.exe" /ErrorStdOut "C:Userspoa11546DesktopGuideTI_Install.au3"

>Exit code: 0 Time: 0.209

Edited by gh0stid

Share this post


Link to post
Share on other sites
water

Your script has absolutely no error checking.

So please do as I have advised in post #4 and #6. Assign the result of RunAs to a variable and tell us what MsgBox says. So we know if it is a problem with RunAs or DOS.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
BrewManNH

Can you run it under the local administrator account instead of the Domain account? Because it wouldn't create the folder(s) for me with my domain account, but does with the computer administrator account.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
gh0stid

Can you run it under the local administrator account instead of the Domain account? Because it wouldn't create the folder(s) for me with my domain account, but does with the computer administrator account.

no cause the local administrator account wont have access to the sc15 share. ( and will never have.. )

thank you.

result is 3408 for mkdir and 7244 for copy

Share this post


Link to post
Share on other sites
BrewManNH

You don't need to have access to the share to create the folder, you just need it to copy the files to the folder you created so you only need the domain credentials when you're copying from the server.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
gh0stid

You don't need to have access to the share to create the folder, you just need it to copy the files to the folder you created so you only need the domain credentials when you're copying from the server.

you are right

so that mean i wont be able to mkdir with the domain account ? how is that possible ?

by the way. i have to add something

the domain account im trying to use, is indeed admin on every pc on the domain ( the group assignation is made that way for that user )

Edited by gh0stid

Share this post


Link to post
Share on other sites
water

Thats fine. The numbers show that RunAs successfully started DOS.

Can you modify your script so that error messages get written to a file?

install()

Func install()
$iResult = RunAs("user", "domain", "password", 0, @ComSpec & ' /c MKdir "c:\temp\xyz 2>C:\temp\error.txt"', "", @SW_HIDE)
MsgBox(0, "", $iResult)
EndFunc ;==>install
This should create file C:\temp\error.txt. What's the content of this file?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
gh0stid

for some reason .. it doesnt write the file to c:temp

even if i give directly modify right to the runas user..

Share this post


Link to post
Share on other sites
BrewManNH

I'll bet it will create the file and the folder if you use the local admin account though. I'm a domain admin on the domain as well, and I can't create a folder using my credentials. But I can with the local Admin's credentials.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
gh0stid

I'll bet it will create the file and the folder if you use the local admin account though. I'm a domain admin on the domain as well, and I can't create a folder using my credentials. But I can with the local Admin's credentials.

ill give it a try

but is there any workaround to that domain problem ?

Share this post


Link to post
Share on other sites
BrewManNH

Yes, use the local administrator's credentials.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
gh0stid

not, still a no go.

lemme go try on a xp machine...

Edited by gh0stid

Share this post


Link to post
Share on other sites
water

Sorry, there was a bug in my script. This version should create the error file:

install()

Func install()
    $iResult = RunAs("user", domain", "password", 0, @ComSpec & ' /c MKdir "c:tempx y z" > C:tempOutput.txt 2>&1', "", @SW_HIDE)
    Run("Notepad C:tempOutput.txt")
EndFunc ;==>install

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

×