[Gambas-user] Gambas app run as root

M. Cs. mohareve at ...626...
Tue Oct 5 18:53:33 CEST 2010


1. Open your project
2. Add a new module, let's say "Sudo"
3. Paste these lines in:
' Gambas class file
PUBLIC wins AS Form
PUBLIC black AS Button
PUBLIC szoveg1 AS TextBox
PUBLIC hProcess AS Process

PUBLIC SUB ReadPassword()
DIM black AS Button
DIM labi, labi2 AS Label
wins = NEW Form
wins.Width = 200
wins.Height = 140
wins.Title = "Update: 'locate'"
labi = NEW Label(wins)
labi.X = 20
labi.Y = 10
labi.Width = 160
labi.Height = 25
labi.Text = "Enter the root password:"
szoveg1 = NEW TextBox(wins)
szoveg1.Width = 160
szoveg1.Height = 25
szoveg1.X = 20
szoveg1.Y = 40
szoveg1.Password = TRUE
labi2 = NEW Label(wins)
labi2.X = 20
labi2.Y = 70
labi2.Width = 160
labi2.Height = 25
labi2.Text = "Shell: su -c 'updatedb'"
black = NEW Button(wins)
black.Width = 100
black.Height = 25
black.X = 50
black.Y = 105
black.Text = "Update"
Object.Attach(black, ME, "runty")
wins.Center
wins.Show()
hProcess = SHELL "su -c 'updatedb'" FOR INPUT OUTPUT
END

PUBLIC SUB runty_Click()
PRINT #hProcess, szoveg1.Text
wins.Delete()
END
'
PUBLIC SUB Process_read()
DIM sOutput AS String
LINE INPUT #LAST, sOutput
PRINT sOutput

END

4. Customize the commands you want to execute
5. Call the module with reference Sudo.ReadPassword() from the main program.



More information about the User mailing list