Kiosk System

Share your advanced PureBasic knowledge/code with the community.
PWS32
User
User
Posts: 85
Joined: Sat May 10, 2003 1:02 pm
Location: Germany

Kiosk System

Post by PWS32 »

with this code (PB4.0) you can realize a kiosksystem
this sample start a new Desktop without taskbar or desktopicons, build a window with the new desktopname and start a external program,
the best is: you cant interupt or kill this desktop not with the taskmanager, you can kill this desktop only
you close the window with the new desktopname, have fun!

many thanks by this users to help me
srod <-- english forum
ts-soft <-- english and german forum
Trond <-- english forum
uweb <-- german forum
friedhelm <-- german forum
falko <-- german forum

Code: Select all

#WINSTA_ALL  = #WINSTA_ACCESSCLIPBOARD | #WINSTA_ACCESSGLOBALATOMS | #WINSTA_CREATEDESKTOP | #WINSTA_ENUMDESKTOPS | #WINSTA_ENUMERATE | #WINSTA_EXITWINDOWS | #WINSTA_READATTRIBUTES | #WINSTA_READSCREEN | #WINSTA_WRITEATTRIBUTES | #DELETE | #READ_CONTROL | #WRITE_DAC | #WRITE_OWNER 
#DESKTOP_ALL = #DESKTOP_READOBJECTS | #DESKTOP_CREATEWINDOW | #DESKTOP_CREATEMENU | #DESKTOP_HOOKCONTROL | #DESKTOP_JOURNALRECORD | #DESKTOP_JOURNALPLAYBACK | #DESKTOP_ENUMERATE | #DESKTOP_WRITEOBJECTS | #DESKTOP_SWITCHDESKTOP | #STANDARD_RIGHTS_REQUIRED 

#UOI_NAME = $2
Global m_sDesktop.s
m_sDesktop = Space(128)

Global cmdline$
cmdline$="C:\WINDOWS\system32\notepad.exe"

Global FontID1 
FontID1 = LoadFont(1, "Arial", 22, #PB_Font_Bold) 

Global startupinfo.STARTUPINFO
startupinfo\cb=SizeOf(STARTUPINFO)
startupinfo\lpReserved=#NUL
startupinfo\lpDesktop=#NUL
startupinfo\lpTitle=#NUL
startupinfo\dwX=#NUL
startupinfo\dwY=#NUL
startupinfo\dwXSize=#NUL
startupinfo\dwYSize=#NUL
startupinfo\dwXCountChars=#NUL
startupinfo\dwYCountChars=#NUL
startupinfo\dwFillAttribute=#NUL
startupinfo\dwFlags=#STARTF_USESHOWWINDOW
startupinfo\wShowWindow=#SW_SHOW
startupinfo\cbReserved2=#NUL
startupinfo\lpReserved2=#NUL
startupinfo\hStdInput=#NUL
startupinfo\hStdOutput=#NUL
startupinfo\hStdError=#NUL

Global process_information.PROCESS_INFORMATION
process_information\hProcess=#NUL
process_information\hThread=#NUL
process_information\dwProcessId=#NUL
process_information\dwThreadId=#NUL

;Global tSi.STARTUPINFO


;Show an error 
Procedure Abort(s.s) 
  MessageRequester("", "Error: "+s.s) 
  Debug "Error: "+s.s 
  End 
EndProcedure 



Procedure.s GetDesktopName()
  Protected hDesktop, lR, lSize, sBuff.s, iPos
  hDesktop = OpenInputDesktop_(0, #False, #DESKTOP_READOBJECTS)
  If hDesktop
    lSize = (Len(m_sDesktop) + 1) * 2
    sBuff=Space(lSize+1)
    lR = GetUserObjectInformation_(hDesktop, #UOI_NAME, @sBuff, lSize, @lSize)
    CloseHandle_(hDesktop)  ; Should this be CloseDesktop_() ?
  EndIf
  ProcedureReturn sBuff
EndProcedure 

;Check a result and ev. abort 
Procedure Chk(a.l, s.s) 
  
  ;If a is false, abort. 
  ;If a is false and s contains an error message, show it before abort. 
  If Not(a) 
    If s.s 
      Abort(s.s) 
    Else 
      End 
    EndIf 
  EndIf 
EndProcedure 

hWinSta = OpenWindowStation_("WinSta0", 0, #WINSTA_ALL) 
Chk( SetProcessWindowStation_(hWinSta) , "Failed to set window station") 

hDefaultDesk = OpenDesktop_("Default", #DF_ALLOWOTHERACCOUNTHOOK, 0, #DESKTOP_SWITCHDESKTOP) 
Chk(hDefaultDesk, "Failed to open default desktop") 

hDesk = CreateDesktop_("My Desktop 2", 0, 0, #DF_ALLOWOTHERACCOUNTHOOK, #DESKTOP_ALL, 0) 
Chk( hDesk, "Failed to create desktop") 

SetThreadDesktop_(hDesk)  ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 

Chk( SwitchDesktop_(hDesk), "Failed to switch desktop") 



If OpenWindow(1, 216, 0, 255, 165, "Test",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar ) 
  If CreateGadgetList(WindowID(1)) 
    TextGadget(1, 20, 70, 210, 30, "Test", #PB_Text_Center) 
    SetGadgetFont(1, FontID1) 
  EndIf 
EndIf 

m_sDesktop = GetDesktopName()
SetGadgetText(1,m_sDesktop)

tSi.STARTUPINFO
tSi\lpTitle = @m_sDesktop
tSi\lpDesktop = @m_sDesktop

tPi.PROCESS_INFORMATION

ret=createprocess_(#NUL,@cmdline$,#NUL,#NUL,#False,0,#NUL,#NUL,@tSi,@tPi)

Repeat 
  Event = WaitWindowEvent() 
  WindowID = EventWindow() 
  GadgetID = EventGadget() 
  EventType = EventType() 
  If Event = #PB_Event_Gadget 
  EndIf 
Until Event = #PB_Event_CloseWindow 

;Delay(2000) 

Chk( SwitchDesktop_(hDefaultDesk), "Failed to switch desktop") 
SetThreadDesktop_(hDefaultDesk)  ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 

CloseDesktop_(hDesk) 
CloseDesktop_(hDefaultDesk) 
CloseWindowStation_(hWinSta)
oldBear
Enthusiast
Enthusiast
Posts: 121
Joined: Tue Jul 05, 2005 2:42 pm
Location: berrypatch

Post by oldBear »

Pretty impressive.

Didn't realize you could lock out taskmanager like that.

cheers
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Cool. 8)

Nice one.
I may look like a mule, but I'm not a complete ass.
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

nice!
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Very fine tip, thanks for posting!
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

Neat. Thanks for sharing.
Dare2 cut down to size
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

Most Excellent! Thanks!
Intrigued - Registered PureBasic, lifetime updates user
benny
Enthusiast
Enthusiast
Posts: 465
Joined: Fri Apr 25, 2003 7:44 pm
Location: end of www
Contact:

Post by benny »

Cool. 8)

Maybe you should add to disable the Task Manager (although just popping up
in background).

Nevertheless, great work and thanks for sharing :!:
regards,
benny!
-
pe0ple ar3 str4nge!!!
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Is there any way to show taskbar, systray, icons, etc on this new desktop?
naw
Enthusiast
Enthusiast
Posts: 573
Joined: Fri Apr 25, 2003 4:57 pm

Post by naw »

Oooh! now that has all sorts of possibilities...
- perhaps time to revisit my poor mans Set Top Box project ;-)
- thats so cool its positively chilly. Thanks for sharing...
Ta - N
CadeX
Enthusiast
Enthusiast
Posts: 124
Joined: Mon Oct 02, 2006 2:56 pm
Location: Australia
Contact:

Post by CadeX »

Whoa, awesome.

Do you know of a way to make runprogram work inside of it?

Appart from that, Great work!
Pro-Gamer, Programmer, Pro-Grammer
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post by Pantcho!! »

Very nice!
But it could be really really cool if we could disable the task manager and also running explorer.exe

because for example if you lock the task manager and run notepad and use the save as / load dialog you can just browse to windows directory and right click the "explorer.exe" -> open
and there you go you have all the icons and start toolbar + icons.

So first of all great start but to make it a really kiosk it need more features!.

I am willing to help (altough i don't really can understand the code ).
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

CadeX wrote: Do you know of a way to make runprogram work inside of it?

Code: Select all

cmdline$ = c:/myexe.exe
ret=CreateProcess_(#NUL,@cmdline$,#NUL,#NUL,#False,0,#NUL,#NUL,@tSi,@tPi) 

;find handle of created proccess
If ret
   ProcessID.l =tPi\dwProcessId 
   Repeat 
      win=FindWindow_(0,0) 
      While win<>0 And quit=0 
         GetWindowThreadProcessId_(win, @pid.l) 
         If pid=ProcessID 
            WinHandle=win 
            quit=1 
         EndIf 
         win=GetWindow_(win, #GW_HWNDNEXT)          
      Wend 
   Until WinHandle 
EndIf 
;Now in Winhandle you have the handle of process
CadeX
Enthusiast
Enthusiast
Posts: 124
Joined: Mon Oct 02, 2006 2:56 pm
Location: Australia
Contact:

Post by CadeX »

Ohh, i see. All i needed was createprocess. Thanks for that!
Pro-Gamer, Programmer, Pro-Grammer
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Nice one.

I made a simple Kiosk thing too. Not very impressive though, it just uses the Kiosk feature of Opera. By using the program parameter sent to Opera, many of the features such as file download, right-click menu etc are removed.

Code: Select all

; Opera Kiosk Mode
; Written by Robert Olsen.

RunProgram("J:\Opera Kiosk\KillTask.exe", "", "") ; Run a small extra program I made with a button that kills the Opera program and the Opera Kiosk Mode program and sends a force log off message to Windows.

ProgramName.s      = "D:\Program Files\Opera\Opera.exe"
Parameter.s        = "/KioskMode /kioskbuttons /nodownload /noexit /nomenu /kioskwindows /noprint /nosave"
WorkingDirectory.s = ""
RunProgram(ProgramName.s, Parameter.s, WorkingDirectory.s)
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Post Reply