AUTO RESTART

Hi,
Can u please advice how to restart my computer using Xojo at particular time (Linux and Windows).
Kindly help me from this.

use the shell class
with it launch the command line specific to your system to restart the computer.
use the timer class to launch the shell at the time you want.

Thanks Jean-Yves Pochez…

Dim s As Shell
s = New Shell
s.Execute(“sudo reboot”)

Am using above code… But it doesn’t work.

what about this command ??

sudo shutdown -r now

but seem like you will be ask for password. Can we include password in the command line

sudo shutdown -r now pwd:abc

Sudo will not work because you cannot have the authorization level from a shell.

IMHO this is a bad idea. But it is your karma …

Why on earth would you want to restart the user computer ? Any application doing that I would throw to the trash immediately. The user may have valuable tasks running you don’t know about, maybe backing up the hard drive or something that should not be interrupted.

Why not instead tell the user that modifications will not be complete before a restart, and let him decide when to do it ?

yea… michel… that is a much better way. inform the user and let him decide.

[quote=331637:@Richard Duke]what about this command ??

sudo shutdown -r now

but seem like you will be ask for password. Can we include password in the command line

sudo shutdown -r now pwd:abc[/quote]
This one also doesn’t work…

[quote=331639:@Michel Bujardet]Sudo will not work because you cannot have the authorization level from a shell.

IMHO this is a bad idea. But it is your karma …

Why on earth would you want to restart the user computer ? Any application doing that I would throw to the trash immediately. The user may have valuable tasks running you don’t know about, maybe backing up the hard drive or something that should not be interrupted.

Why not instead tell the user that modifications will not be complete before a restart, and let him decide when to do it ?[/quote]
Actually my application monitor the some other process… So if the process doesn’t run properly i want to restart my computer.
Thats y am looking for the solution for this.

None of the Sudo stuff will ever work this way, since shell cannot prompt for the password.

You can omit the sudo part. It will work fine.

on macos the sudo is not necessary
but on linux ? and windows ?

don’t know where I found this, but certainly on this forum or old realbasic.
you can pass argument to a shell

//make a constant (string) named passShell  

PW="$(osascript -e 'tell application "System Events" to display dialog "Password:" default answer "" with hidden answer' -e 'text returned of result' 2>/dev/null)" 

call it:  

  dim mshell as new shell
  mshell.Execute passShell
  mshell.Execute "echo ""$PW"" | sudo -S /usr/bin/true"
  mshell.Execute "echo ""$PW"" | sudo -S  //your next shell command
  mshell.Execute "exit"
     

[quote=331657:@Jean-Yves Pochez]on macos the sudo is not necessary
but on linux ? and windows ?[/quote]

Linux most certainly demands it.

Windows uses quite different commands, so what works for Mac and Linux won’t work there.

On linux and mac you can edit the “sudoers” file to change the permissions on sudo to include not requiring a password for certain users/groups and even for certain commands.

type “sudo visudo” - edit the options (with care).