xdissent / ievms

Automated installation of the Microsoft IE App Compat virtual machines
http://xdissent.github.com/ievms
9.86k stars 497 forks source link

How can I "run as administrator" on a Win7 guest OS? #243

Closed airblade closed 9 years ago

airblade commented 9 years ago

Yesterday this script successfully set up VMs for IE9, 10, and 11 for me.

Now I am trying to modify each Windows' hosts file programatically. However it seems that IEUser/Passw0rd! does not have permission to copy files to C:\\Windows\\System32\\drivers\\etc\\hosts:

VBoxManage guestcontrol "IE9 - Win7" copyto ~/Desktop/hosts "C:\\Windows\\system32\\drivers\\etc\\hosts" --username IEUser --password Passw0rd\!  --verbose
Opening guest session as user 'IEUser' ...
Waiting for guest session to start ...
Guest session (ID 1) has been started
Copying from host to guest ...
Directory "." already exists
Source: /Users/andy/Desktop/hosts
Copying "/Users/andy/Desktop/hosts" to "./C:\Windows\system32\drivers\etc\hosts" ...
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...
Progress state: VBOX_E_IPRT_ERROR
VBoxManage: error: Copying file "/Users/andy/Desktop/hosts" failed with status 500, exit code 1.
VBoxManage: error: Error processing "/Users/andy/Desktop/hosts", rc=VERR_GENERAL_FAILURE
Closing guest session ...

I have also tried executing a bat file which modifies the hosts file, again as the IEUser, but although the command executed successfully the hosts file was unchanged.

VBoxManage guestcontrol "IE9 - Win7" exec --image "/Documents and Settings/IEUser/Desktop/hosts.bat" --username IEUser --password Passw0rd\! --wait-exit --verbose

Similarly if I go onto the Windows guest OS and double click my hosts.bat, a command window flashes up and vanishes but no changes are made to hosts.

But if I right-click on the bat file and choose Run as administrator, it does modify hosts.

So how can I "run as administrator" programatically?

Many thanks in advance.

drewreece commented 9 years ago

airblade, I finally got around to addressing this in the script… https://gist.github.com/drewreece/1239489

The hosts file now has the line to gain admin access via a UAC prompt… net session >NUL 2>&1|| powershell Start-Process '%0' -Verb RunAs&& exit /b|| exit /b

I found that on … http://www.sevenforums.com/general-discussion/12936-how-run-batch-file-admin-2.html?s=0c0b169bcd910dc62c1adc18ef279179

Hope it helps, I can't see any better way to 'run as admin' via VirtualBox's additions, it would need to tap into the cleverness that ievms uses when it edits the registry I guess.

You may want to close this - it is beyond the realm of what ievms is intended to do.

airblade commented 9 years ago

@drewreece Fantastic, thank you :-)

airblade commented 7 years ago

For the record I now use the ievms-ruby gem.