Ben Clark posted a way to make a program a service.
posted here
to be brief i have a need to reboot when the system date changes.
i found code to reboot here by Tonny Bjorn
i am having a difficult time merging the code to get what i need.
the program needs to be a service, because i do not want the users to kill my program through the task manager.
if i can get an example of another program using this Clark's program that would probably help me.
here is my program below
my program is a gui.
the program compares the date from the date against the date when the program started every 10 seconds, when it sees the date change, it forces a reboot.
the program below as written will not reboot, as i have remarked that line of code out and i added a line of code that just says "rebooted" for testing purposes.
A little background for the main purpose of this program. We run virtual machines with a windows guest operating system, and we use these virtual machines to let users access the internet freely. The other day, one employee's child came in and they let the child on the computer or maybe did not know it. We are like a lot places where you really do not want to put passwords everywhere but i am going to implement some. The problem arises when a virtual machine is not shutdown, but put into a saved state, sort of like hibernation. I would never ever hibernate a computer due to all the problems one can have, but this is different. So, when a user places the virtual machine in a saved state mode, the person can come up to the computer and restart the virtual computer from where it was left off, and i want our users to shutdown the virtual machines when they go home and if the virtual computer is in a saved state the next day, meaning anybody can use the virtual computer to go anywhere they want and not have to provide any passwords. it would serve me well to just have the virtual computer reboot by itself the next day if they bring the virtual computer out of a saved state. The virtual computers will have a password upon startup and each user will have their own password.
Also i am going to implement a program, not this program that keeps track to where the users go on the internet and store that information somehow to be viewed by the management.
if there are any suggestions to run this program from startup or any such ways where a non administrator user can remove this program, that will not work for me.
i have preset the start date to be 03-23-2008 to make the program simulate the condition to where the program will want to reboot.
posted here
to be brief i have a need to reboot when the system date changes.
i found code to reboot here by Tonny Bjorn
i am having a difficult time merging the code to get what i need.
the program needs to be a service, because i do not want the users to kill my program through the task manager.
if i can get an example of another program using this Clark's program that would probably help me.
here is my program below
my program is a gui.
the program compares the date from the date against the date when the program started every 10 seconds, when it sees the date change, it forces a reboot.
the program below as written will not reboot, as i have remarked that line of code out and i added a line of code that just says "rebooted" for testing purposes.
A little background for the main purpose of this program. We run virtual machines with a windows guest operating system, and we use these virtual machines to let users access the internet freely. The other day, one employee's child came in and they let the child on the computer or maybe did not know it. We are like a lot places where you really do not want to put passwords everywhere but i am going to implement some. The problem arises when a virtual machine is not shutdown, but put into a saved state, sort of like hibernation. I would never ever hibernate a computer due to all the problems one can have, but this is different. So, when a user places the virtual machine in a saved state mode, the person can come up to the computer and restart the virtual computer from where it was left off, and i want our users to shutdown the virtual machines when they go home and if the virtual computer is in a saved state the next day, meaning anybody can use the virtual computer to go anywhere they want and not have to provide any passwords. it would serve me well to just have the virtual computer reboot by itself the next day if they bring the virtual computer out of a saved state. The virtual computers will have a password upon startup and each user will have their own password.
Also i am going to implement a program, not this program that keeps track to where the users go on the internet and store that information somehow to be viewed by the management.
if there are any suggestions to run this program from startup or any such ways where a non administrator user can remove this program, that will not work for me.
i have preset the start date to be 03-23-2008 to make the program simulate the condition to where the program will want to reboot.
Code:
'program to reboot computer when the date changes 'vmshutdown.bas 'pbwin 8.04 #COMPILE EXE #DIM ALL #INCLUDE "WIN32API.INC" %IDC_DIALOG1 = 101 %IDC_LABEL1 = 1001 %IDC_TEXTBOX1 = 1002 %IDC_BUTTON1 = 1003 GLOBAL glastbooted AS STRING GLOBAL hDlg AS DWORD SUB ShutDownNT(BYVAL DoWhat AS LONG) LOCAL OSVersion AS OSVERSIONINFO LOCAL ProcessHandle AS LONG LOCAL TokenHandle AS LONG LOCAL TempLUID AS LUID LOCAL TokenPrivilleges AS TOKEN_PRIVILEGES LOCAL TKPDummy AS TOKEN_PRIVILEGES LOCAL lReturnLength AS LONG OSVersion.dwOSVersionInfoSize = SIZEOF(OSVersion) IF GetVersionEx(OSVersion) <> 0 THEN IF OSVersion.dwPlatformId = %VER_PLATFORM_WIN32_NT THEN ProcessHandle = GetCurrentProcess() CALL OpenProcessToken(ProcessHandle, %TOKEN_ADJUST_PRIVILEGES OR %TOKEN_QUERY, TokenHandle) CALL LookupPrivilegeValue("", "SeShutdownPrivilege", TempLUID) TokenPrivilleges.PrivilegeCount = 1 TokenPrivilleges.Privileges(0).pLuid = TempLUID TokenPrivilleges.Privileges(0).Attributes = %SE_PRIVILEGE_ENABLED IF AdjustTokenPrivileges(TokenHandle, %FALSE, TokenPrivilleges, LEN(TKPDummy), TKPDummy, lReturnLength) THEN ' Flags: %EWX_LOGOFF, %EWX_SHUTDOWN, %EWX_REBOOT, %EWX_FORCE, %EWX_POWEROFF SELECT CASE DoWhat CASE 1 ' Force Shut Down and ReBoot CALL ExitWindowsEx(%EWX_FORCE OR %EWX_SHUTDOWN OR %EWX_REBOOT, 0) CASE 2 ' Force Logoff user' Force Logoff user CALL ExitWindowsEx(%EWX_FORCE OR %EWX_LOGOFF, 0) CASE ELSE ' Force Shut Down and Power Off CALL ExitWindowsEx(%EWX_FORCE OR %EWX_SHUTDOWN OR %EWX_POWEROFF, 0) END SELECT END IF END IF END IF END SUB FUNCTION TimerProc( BYVAL hDlg AS LONG, BYVAL Msg AS LONG, BYVAL EvntID AS LONG, BYVAL Time AS LONG ) AS LONG STATIC t AS LONG INCR T CONTROL SET TEXT hDlg, %IDC_LABEL1, STR$(31-T)+" seconds left" IF T=31 THEN DIALOG END HDLG END FUNCTION 'TimerProc CALLBACK FUNCTION ShowDIALOG1Proc() STATIC hTimer AS LONG SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG ' Initialization handler hTimer = SetTimer( hDlg, 1, 1000, CODEPTR(TimerProc) ) CASE %WM_DESTROY IF hTimer THEN KillTimer hDlg, hTimer CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN ' Save control focus hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_COMMAND ' Process control notifications SELECT CASE AS LONG CBCTL CASE %IDC_BUTTON1 DIALOG END HDLG END SELECT END SELECT END FUNCTION FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG LOCAL hFont1 AS DWORD LOCAL message AS STRING message="A forced shutdown is scheduled in 30 seconds."+$CRLF+_ "This virtual machine needs restarting daily."+$CRLF+_ "The last time it was booted was on "+glastbooted+"." DIALOG FONT "",10 DIALOG NEW hParent, "", 70, 70, 165, 42, %WS_POPUP OR _ %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _ %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _ OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Reboot Now", 102, 32, 50, 10 CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "", 5, 32, 90, 10 CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, message, 5, 5, 155, 25,%ES_MULTILINE DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt FUNCTION = lRslt END FUNCTION FUNCTION PBMAIN() glastbooted=DATE$ glastbooted="03-23-2008" CHECKTHEDATE: IF glastbooted=DATE$ THEN SLEEP 10000:GOTO checkthedate ShowDIALOG1 %HWND_DESKTOP MSGBOX "rebooted " ' CALL ShutDownNT(1) END FUNCTION
Comment