cpremo Posted June 10, 2008 Share Posted June 10, 2008 I can't seem to get the following script to copy the file to the "Windows" folder. It works if I'm logged in as an administrator to the PC. "INI File entries" [LogoData] Destination1=C:\WINDOWS\ Destination2=C:\WINNT\ FileName=MBC_Banner.bmp Script: ******************************************************************** If Not IsAdmin() Then RunAsSet("Administrator", @Computername, "password") EndIf Dim $Location Dim $Destination Dim $FileName If @OSVersion = "WIN_2000" Then ;This statement reads data from the referenced INI file to set the paramenter shown. $Destination = IniRead ( @ScriptDir & "\ClientLogo.ini", "LogoData", "Destination2", "default" ) ElseIf @OSVersion = "WIN_XP" or @OSVersion = "WIN_VISTA" Then ;This statement reads data from the referenced INI file to set the paramenter shown. $Destination = IniRead ( @ScriptDir & "\ClientLogo.ini", "LogoData", "Destination1", "default" ) EndIf ;This statement reads data from the referenced INI file to set the paramenter shown. $FileName = IniRead ( @ScriptDir & "\ClientLogo.ini", "LogoData", "FileName", "default" ) $Location = @ScriptDir & "\" & $FileName dim $Banner = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\NOVELL\LOGIN\BANNER","IMAGE") If not FileExists($Destination & $FileName) Then FileCopy($Location, $Destination, 9) ElseIf $Banner <> ($Destination & $FileName) Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\NOVELL\LOGIN\BANNER","IMAGE","Reg_SZ",$Destination & $FileName) Else EndIf *********************************************************************************** Link to comment Share on other sites More sharing options...
Airwolf Posted June 10, 2008 Share Posted June 10, 2008 RunAsSet only sets administrator privileges for the Run and RunWait commands. If you want to perform file copies and iniwrites, etc., you'll need to either do a RunAsSet then Run on this script from another, or use Run commands using DOS command line or other autoit scripts. BTW - RunAsSet no longer exists in the latest build, it has been replaced with RunAs and RunWaitAs. Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt Link to comment Share on other sites More sharing options...
cpremo Posted June 11, 2008 Author Share Posted June 11, 2008 (edited) I downloaded and installed the latest version and found the following script: ******************************************************** ; Fill in the username and password appropriate for your system. Local $sUserName = "Username" Local $sPassword = "Password" ; Run a command prompt as the other user. Local $pid = RunAsWait($sUserName, @ComputerName, $sPassword, 0, @ComSpec, @SystemDir) ; Wait for the process to close. ProcessWaitClose($pid) ; Show a message. MsgBox(0, "", "The process we were waiting for has closed.") ***************************************************** What the example fails to show or state is how to do the call to the other script. I assume that the $pid is some how related to the secondary script that we want to run, but I'm not sure how to do it exactly. I tried several options, but can't get the process to run within the RunAsWait process. This is what I tried: ; Run a command prompt as the other user. Local $pid = RunAsWait($sUserName, @ComputerName, $sPassword, 0, Run(@ScriptDir & "\ClientLogo") ) Edited June 11, 2008 by cpremo Link to comment Share on other sites More sharing options...
Airwolf Posted June 11, 2008 Share Posted June 11, 2008 I downloaded and installed the latest version and found the following script: ******************************************************** ; Fill in the username and password appropriate for your system. Local $sUserName = "Username" Local $sPassword = "Password" ; Run a command prompt as the other user. Local $pid = RunAsWait($sUserName, @ComputerName, $sPassword, 0, @ComSpec, @SystemDir) ; Wait for the process to close. ProcessWaitClose($pid) ; Show a message. MsgBox(0, "", "The process we were waiting for has closed.") ***************************************************** What the example fails to show or state is how to do the call to the other script. I assume that the $pid is some how related to the secondary script that we want to run, but I'm not sure how to do it exactly. I tried several options, but can't get the process to run within the RunAsWait process. This is what I tried: ; Run a command prompt as the other user. Local $pid = RunAsWait($sUserName, @ComputerName, $sPassword, 0, Run(@ScriptDir & "\ClientLogo") ) $pid would be the return value of the RunAs() function, which is the process's ID. The help file's example for RunAsWait() is actually incorrect; it does not return the process id, but it returns the exit code. Back to the RunAsWait() - you don't need to perform the Run command inside the function - it is implied by the RunAsWait function. Whatever you put as filename in RunAsWait ( "username", "domain", "password", logon_flags, "filename" [, "workingdir" [, flag]] is going to be run. $username = "username" $password = "password" $domain = @ComputerName $filename = "notepad.exe" $exitcode = RunAsWait($username, $domain, $password, 0, $filename, @ScriptDir) MsgBox(0,"","The exit code of " & $filename & " was: " & $exitcode) Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt Link to comment Share on other sites More sharing options...
smashly Posted June 12, 2008 Share Posted June 12, 2008 If your trying to run the compiled script with admin rights, you can use singlelton and make the script call itself with RunAs() again and once loaded the 2nd time close the first instance. Once the script has called itself with runas then any file operations work fine in a limited user account. I recently used the above method myself and it all works great . Other ways to just run a line with admin rights using runas() and AutoIt3ExecuteLine, the draw back to this though is the line called doesn't see any user declared variables from outside of the line. Cheers Link to comment Share on other sites More sharing options...
anixon Posted June 12, 2008 Share Posted June 12, 2008 If Vista you might need to include in your script #RequireAdmin ;Required by Windows Vista User Account Control (UAC) Link to comment Share on other sites More sharing options...
cpremo Posted June 12, 2008 Author Share Posted June 12, 2008 (edited) If I use just this example: $exitcode = RunAsWait($username, $domain, $password, 0, $filename, @ScriptDir) the executible ($filename) never fires off. If I use instead the "RunWait($Filename)" inside the command, the executible fires off. However, the file never gets copied. I tried to add the "SetACL.exe" command to assign rights to the C:\Windows folder, but that doesn't seem to work either. I get the "Msgbox" statement (except the "If FileExists($Destination & $FileName) Then MsgBox(1,"","File Copied")" message), but no file in the C:\windows directory. ;This statement reads data from the referenced INI file to set the paramenter shown. Dim $Location Dim $Destination Dim $FileName If @OSVersion = "WIN_2000" Then ;This statement reads data from the referenced INI file to set the paramenter shown. $Destination = IniRead ( @ScriptDir & "\ClientLogo.ini", "LogoData", "Destination2", "default" ) ElseIf @OSVersion = "WIN_XP" or @OSVersion = "WIN_VISTA" Then ;This statement reads data from the referenced INI file to set the paramenter shown. $Destination = IniRead ( @ScriptDir & "\ClientLogo.ini", "LogoData", "Destination1", "default" ) EndIf $FileName = IniRead ( @ScriptDir & "\ClientLogo.ini", "LogoData", "FileName", "default" ) $Location = @ScriptDir & "\" & $FileName If not FileExists($Destination & $FileName) Then MsgBox(1,"",@ScriptDir & "\" & $FileName & " Copied to: " & $Destination) Dim $ALCSET = @ScriptDir & "\SetACL.exe" Dim $test = ' -on "C:\Windows" -ot file -actn ace n:' & @ComputerName & '\users;p:full' RunWait($ALCSET & $test, @SystemDir) FileCopy($Location, $Destination, 9) MsgBox(1,"","Step 1a") If FileExists($Destination & $FileName) Then MsgBox(1,"","File Copied") EndIf Edited June 12, 2008 by cpremo Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now