Sodori

Trying to CMD copy as admin

13 posts in this topic

#1 ·  Posted (edited)

Hi!

Basically, trying to make default homepage on chrome. Need a file to be copied into chrome root. This is my issue:

RunAs($User, $Domain, $Password, 2, "CMD.exe Copy " & $File1 & " " & $File2)

It does open CMD in system32, so I know that part work. However it doesn't copy! Hoped this would be it.. Booth files are pointing towards the files (pat\file.exe). Doesn't need to go through CMD but this is the closest to success as of now for me. What am I doing wrong?

Edited by Sodori

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

try this:

RunAs($User, $Domain, $Password, 2, 'cmd.exe /c copy "' & $File1 & '" "' & $File2 & '"')

Keep in mind that AutoIt .exe files can be decompiled, so if your script contains a clear text password for an administrative domain account,
that might be a security issue if the .exe can be accessed by other users.

Edited by Radiance

Share this post


Link to post
Share on other sites

Thanks for the warning, and I have that in consideration. Planning to make it only accessible by me or change them to input boxes or something.

Unfortunately though, still ain't copying! >.< Outputting command in console looks like:

cmd.exe /c copy "[from path]" "[to path]"

Censoring to and from paths for security reasons. Confirmed paths are indeed valid by entering them in address bar.

Share this post


Link to post
Share on other sites

Do the paths contain mapped network drives? Like "\\server\share" as "Q:\" ?

As you use RunAs I assume you are running your stuff as a user which is not the one you are logged on with.

I think using mapped drives won't work.
Same problem as opening a mapped drive in windows explorer, taking any .exe, Shift+Rightclick -> RunAs and put in some different user credentials.

Share this post


Link to post
Share on other sites
#Region Setup Chrome
Switch @OSArch
    Case "X64"
        Local $cDir = "C:\Program Files (x86)\Google\Chrome\Application\master_preferences"
    Case "X86"
        Local $cDir = "C:\Program Files\Google\Chrome\Application\master_preferences"
EndSwitch

;~ If FileExists($cDir) = 0 Then
;~  MsgBox(0, "Error!", "Can't find path skipping Chrome defaults!" & @LF & $cDir)
;~ Else
    Local $cFile =  FileOpen("C:\Temp\master_preferences", 8+2)
    FileWrite($cFile,   '{"homepage":"***","homepage_is_newtabpage":false,"distribution":' _
                        & '{"skip_first_run_ui":false,"import_search_engine":false,"import_history":false,"create_all_shortcuts":true,"do_not_launch_chrome":true,"make_chrome_default":true,"verbose_logging":false,"ping_delay":-60},' _
                        & '"sync_promo":{"show_on_first_run_allowed":false},' _
                        & '"session":{"restore_on_startup":4,' _
                        & '"urls_to_restore_on_startup":["***"]},' _
                        & '"first_run_tabs":["***"]}')
    RunAs("$user", "$domain", "$password", 2, 'cmd.exe /c copy "' & "C:\Temp\master_preferences" & '" "' & $cDir & '"')
    FileClose($cFile)
;~ EndIf
#EndRegion

That is the code. No luck >.< (yes, it were in a network drive, no more though)

Share this post


Link to post
Share on other sites

Try putting the copy command after the FileClose () :)

Share this post


Link to post
Share on other sites

Still no luck.. the potato you be so stubborn AutoIt?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Had the brilliant *ironic* idea to take previous mentioned console line and simply input it manually. That worked!... So, it's a RunAs issue...

Edited by Sodori

Share this post


Link to post
Share on other sites

Since I happen to sit in a windows domain and having installed chrome I tried running your script 1:1.

I didn't change a thing except my login credentials. Used a profile with admin rights that is different from mine.

Works.

Either the user you are using is missing some rights or you might have mistyped the credentials.

Share this post


Link to post
Share on other sites

Actually, that makes sense! I am but a local admin on our network.. kinda forgot that..

Know any workaround? Preferably not listing having the main admins login credentials because that I dare not as you probably can understand xD

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

You could set up a computer startup script on your domain controller via group policy (note: not an user logon script).

Those are being run under the local system account so they have full access rights on the local machine - there's no need to type any login credentials in your script (Run() instead of RunAs())

 

If you can change the NTFS permissions from the chrome directory by default that would work too I guess.

  • Setting it to public will allow you to use Run() but everyone else will also be able to read and write in that directory
  • Setting read/write for your RunAs() user is the other option but then again your script will have to contain the logon credentials.
Edited by Radiance
1 person likes this

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Think I got it. Happen to know how I could possibly do a

Run(CMD.exe /c [code])

And keep the window open? For debugging purposes.

Edited by Sodori

Share this post


Link to post
Share on other sites

Use /k instead of /c

1 person likes this

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