Jump to content

Trying to CMD copy as admin


Sodori
 Share

Recommended Posts

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

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
Link to comment
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.

Link to comment
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.

Link to comment
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)

Link to comment
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.

Link to comment
Share on other sites

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