Jump to content

Copy files with admin rights


jcaspar
 Share

Recommended Posts

Hello ! :)

I would like to copy a file from a server to a pc from the network

but for this i need admin rights ..The script function only if you are admin

how should i do in order the script function for people who have user rights ?

Thank you very much for your advices ! :)

Jean Marc

#NoTrayIcon
Local $sUserName="administrateur"
Local $sPassword="xxxxx"
Local $pid=RunAs($sUserName, @ComputerName, $sPassword, 0, @ComSpec, @SystemDir,@SW_HIDE)
FileCopy("test.ini","C:\Program Files\OCS Inventory Agent",1)
$file="test.ini"
$array = IniReadSection($file,"Section"); remplace "Section" par le nom que tu veux (sera affiché dans le ini)
$tring = @ComputerName
$name = ("Nom PC")
    IniWrite($file,"Section",$name,$tring);marque dans $file, a la section "Section", a la ligne $name, la valeur $tring.
     MsgBox(64,"MsgBox","Tout c'est passé correctement.")
  
  
  $var = IniReadSection("C:\Program Files\OCS Inventory Agent\test.ini", "Section")
     If @error Then 
    MsgBox(4096, "", "Erreur rencontrée, le fichier ini est probablement manquant.")
Else
    For $i = 1 To $var[0][0]
        MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
    Next
EndIf
Link to comment
Share on other sites

Hello ! :)

I would like to copy a file from a server to a pc from the network

but for this i need admin rights ..The script function only if you are admin

how should i do in order the script function for people who have user rights ?

Thank you very much for your advices ! o:)

Jean Marc

#NoTrayIcon
Local $sUserName="administrateur"
Local $sPassword="xxxxx"
Local $pid=RunAs($sUserName, @ComputerName, $sPassword, 0, @ComSpec, @SystemDir,@SW_HIDE)
FileCopy("test.ini","C:\Program Files\OCS Inventory Agent",1)
$file="test.ini"
$array = IniReadSection($file,"Section"); remplace "Section" par le nom que tu veux (sera affiché dans le ini)
$tring = @ComputerName
$name = ("Nom PC")
    IniWrite($file,"Section",$name,$tring);marque dans $file, a la section "Section", a la ligne $name, la valeur $tring.
     MsgBox(64,"MsgBox","Tout c'est passé correctement.")
  
  
  $var = IniReadSection("C:\Program Files\OCS Inventory Agent\test.ini", "Section")
     If @error Then 
    MsgBox(4096, "", "Erreur rencontrée, le fichier ini est probablement manquant.")
Else
    For $i = 1 To $var[0][0]
        MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
    Next
EndIf
You are not using RunAS() correctly. Only the command you execute within RunAs() is run as the provided user. Your only command is @COMSPEC, so it opens command line shell, then closes it immediately, doing nothing. The rest of script has nothing to do with that RunAs(), and works as it otherwise would with the permissions of whoever ran the script.

What you want executed with the other permissions must be what gets run inside the RunAs() function. That usually means calling a batch file or another AutoIt script that actually did the copying.

P.S. It is a grave security risk to put admin accounts and passwords in a script. Don't assume that data can't be read from the compiled script.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...