System restart to windows using objective-c - objective-c

If a users wants to reboot to windows from OS X, he/she either needs to:
a) Reboot holding down the ALT key and select windows
b) Go to System
settings -> Startup disk -> Select windows -> Reboot
(Given that the user has a bootcamp partition and windows installed).
Since I now and then play some games, and prefer doing that directly in Windows and not using e.g. VMWare Fusion. I would like to develop a smarter and easier way of rebooting. I know how to reboot a machine using Objective-c, but how can I choose the boot partition and reboot to it? Basically how the system restart function works in the system settings (choose partition and reboot).

I don't know if there is a programmatic interface, but you can set the startup disk with the bless command, see "man bless".

Related

Can I run one WSL2 virtual machine instance on two system?

I'm new to the WSL2 and wondering if it's possible to run the same WSL2 ubuntu instance on both my desktop and laptop.
Now I am able to use wsl --export and wsl --import method to save and load the system to/from my portable hard drive. But these methods takes a long time.
I notice that wsl --import load a file named ext4.vhdx. Is there a way to load straightly from this file?
Update v2.0:
I was able to get a workaround and it works great.
Thanks to Booting from vhdx here, I was able to load straightly from my vhdx file on my portable hard disk. Windows track down its subsystem with regedit, So we can write our own(p.s: make sure to get BasePath right, it starts with "\\\\?", or you will not be able to access the subsystem' filesystem on your host system.):
Windows Registry Editor Version 5.00
[HKEY_USERS\【your SID here】\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{【UUID here】}]
"State"=dword:00000001
"DistributionName"="distribution name"
"Version"=dword:00000002
"BasePath"="vhdx folder path" 【 e.g. "\\\\?\\E:\\S061\\WSL\\ubuntu-20"】
"Flags"=dword:0000000f
"DefaultUid"=dword:000003e8
I suppose the best way to do this would be to store ext4.vhd on a network storage device accessible to both devices.
I have previosly mentioned how to move ext4.vhd. You can check that out here
Basically you need to export from one machine and import it while making sure the vhd file is configured for wsl to access from the network storage
Since this should *officially* not supported expect some performance hits
Another way would be to run WSL on one computer and ssh/remote desktop to it from another device on the network
I'm of the strong belief that sharing the same ext4 vhd between two VM's simultaneously would be a bad idea. See this and this Unix & Linux StackExchange, including the part about ...
note that sharing LVs/partitions on a single disk between the servers at the same time is NOT very safe. You should only access whole disks from any of the servers at one time.
However, as dopewind's answer mentioned, you can access the WSL instance on one computer (probably the desktop) from another (e.g. the laptop). There are several techniques you can use:
If you have Windows 10 Professional or Enterprise on one of the computers, you can enable Remote Desktop, which allows you to access pretty much everything on one computer from another. RDP ("Remote Desktop Protocol") even works from other devices such as an iPad or Android tablet (or even a phone, although that's a bit of a small screen for a "desktop"). That said, there are better, more idiomatic solutions for WSL ...
You could enable SSH server on the Windows 10 computer with the WSL instance (instructions). This may sound counterintuitive to some people, since Linux itself running in the WSL instance also includes an SSH server (by default). But by SSH'ing from (for example) your laptop into your desktop's Windows 10, you can then launch any WSL instance you have installed (if you choose to install more than one) via wsl -d <distroName>. You also avoid a lot of the network unpleasantness in the next option ...
You could, as mentioned above, enable SSH on the WSL instance (usually something like sudo service ssh start) and then ssh directly into it. However, note that WSL2 instances are NAT'd, so there's a whole lot more hackery that you have to do to get access to the network interface. There's a whole huge thread on the WSL Github about it. Personally, I'd recommend the "Windows SSH Server" option mentioned about to start out with, then you can worry about direct SSH access later if you need it.
Side note: Even though I have SSH enabled on my WSL instances, I still use Windows SSH to proxy to them, to avoid these networking issues.

Install new guest OS in virtual machine

I connect to a virtual machine using vsphere client. I have installed a guest os (windows 10), but now I want to change it to windows server 2016. The os was installed through a datastore iso file. The windows server iso file is also available there.
So, how can I do this? Is there a way to format the drive the windows are installed and start from the beginning? (I don't care to keep any previous files or programs installed). Some other way?
Keep in mind that I don't have complete authority over the vm, so I cannot delete it and recreate it.
Thank you
If you can mount the ISO to the VM itself, you should be fine.
Start by mounting the ISO to the VM, then restart the guest OS. There should be a prompt to boot from ISO, follow that and you will be able to install Server 2016 to the system.
I am going to answer my own question, in case someone else has the same problem.
The guest OS would load immediately, without allowing the user to go to the BIOS and select to boot from the ISO.
There is a setting you can adjust for waiting time before the windows are loaded. This was zero and had to add a few seconds, in order to be able to enter the BIOS.
I am not sure where this setting is, since I was not the one to change it (I didn't have the rights). Maybe someone else can add this.

Run real "Bios Setup" in virtual machine

Normally if we want to change Bios Setting, we need to restart the PC and when system boot up we press the hot key (F2 or F10) to go "Bios Setup", then change the setting.
However, I would want to do real Bios Setup from Window Environment...Is it possible to copy the image of Bios (of my computer) to a binary file? then setup a virtual machine to run it and do all the changes? If it is impossible with existing tool (VirtualBox, Qemu,VMWARE)...is it possible to write a special virtualization software to do that?
Thanks
Go to your settings of the virtual machine go to system > motherboard click EFI on
Boot your machine and type in the shell (you need to wait a bit)
"exit" then you will go into the BIOS EFI if you want to quit hard power it off and to turn off the bios for boot again reverse the settings...
(For virtualbox)

Working on remote server

My OS: Windows 8
Virtualbox guest: Ubuntu 12.10 server
I configured apache server on vbox guest and mapped http, https, ssh port successfully into ubuntu server. It works nice without any problem.
I tried several IDEs like PHPStorm, Netbeans, editors like Sublime, all they do is to copy whole project from server, edit on local machine then sync back.
But it is not what I need. I want to work directly on guest server using ssh/sftp connection. I know that notepad++ has this functionality but I love sublime look and feel.
Is there any way to work on guest server with sublime or any other ide for free? (There is sftp solution but it's paid and works just like other ide's, not directly on guest machine) Any suggestions?
There are two approaches you can choose from, you will probably select the second one:
Use the KDE desktop environment (yes, it also exists for MS Windows). It features so called 'kio-slaves' which allow to use any protocol out there as if you were doing local file system operations. That means when using a KDE editor like 'kate' or even a whole IDE like 'kdevelop4' you can simply say "open file/project" and not only choose a local file, but something like sftp://server/path/file and start working. The network stuff is handled transparently by the environment, it is fully network transparent. This is how systems should be like. I think the GNOME environment had something similar, but it probably has been removed with version 3 of GNOME.
You can 'mount' the guests file system into your MS-Windows file system. not sure about the details how this works in MS-Windows, but I am sure that at least newer versions of MS-Windows have gained such feature. Most likely you are still limited to creating something like a "network harddrive" or something, in other systems (linux, unix, macOS) you can mount whereever in the file system you like. You can use any protocol for this, as long as it is supported by the mounting tools of your local system.
Again two options:
2.a You mount the whole virtual disk. Easy, but might be a problem if that disk is currently used by the guest system.
2.b You export the virtual disk by starting some server in the virtual system: samba is most likely your choice. Then you can mount that smb file export inside your MS-Windows system and start hacking.
Have fun!

how to programmatically enable remote management under sharing in Mac OS X 10.8

I am working on a project which requires VNC Server to be run on my system (Mac OS X v10.8).
VNS server is installed in my Mac system, now I need to run VNC server, but for running the server sufficient privileges needs to be provided programmatically or using Apple Script(System Preference -> Sharing -> Remote Management -> Enable the check box).
How could I enable remote management through objective c program or apple script ?
or is there any API provided by Apple to manage sharing options?
You can enable and configure the remote management service with the kickstart command. It's not in the usual PATH, so you need to specify its full path:
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart
Its option format is a little cryptic, but with some experimentation you should be able to get the effect you want (see Apple's KB #HT2370 and SS64.com's "man page").
Also, it must run as root, so from AppleScript, use do shell script with administrator privileges. I think you'll need something close to this:
do shell script "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -restart -agent -privs -all" with administrator privileges