Jump to content

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


gh0stid
 Share

Recommended Posts

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

What's the result of MsgBox?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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