I want to know how to make a screen locker using VB6. I have tried maximizing the frame but it still can be minimized. Then I have made the frame very large to fit the entire screen and made the frame irresizeable but someone can press Alt+F4 and close it. I also want the task manager to be disabled. So can anyone please help me?
This is probably not what you are trying to do but, you can lock windows by calling the WINAPI function LockWorkStation.
Option Explicit
Private Declare Function LockWorkStation Lib "User32" () As Boolean
Call it with
Call LockWorkStation
If you put the declare statement in a .bas module and call it from a form you will want to change the declare scope to Public. This function is supported in Windows XP and up, and Windows Server 2003 and up.
There is no absolute way to completely prevent the application from stopping. And can we know why you would do that?
Still, you can prevent the user from closing the application with the cancel parameter.
private sub Form_unload(Cancel as Integer)
Cancel = 1
End Sub
You can remove the exit button and make the form immovable and irresizeable. The you can call a batch file that will stop the task manager as :
:run
taskkill /f /im taskmgr.exe
goto run
This will continuously stop the task manager if it is opened.
Related
Recently the IT policy at my work changed, and all scripts I have been using (.bat .cmd .py) no longer work. Where possible I have converted these to VBA macros that run in workbooks - as these are still enabled.
Here are two macros to schedule a force shutdown/ cancel it (respectively)
Private Sub Workbook_Open()
Application.Visible = False
Shell "SHUTDOWN /s /f" '/Scheduled shut down, /Forced (ignores any unsaved)
End Sub
And in a 2nd workbook
Private Sub Workbook_Open()
Application.Visible = False
Shell "shutdown /a" '/Abort scheduled shutdown
Application.Quit
End Sub
As you can see the macros run on Workbook_Open() events, with Application.Visible = False. The intent is for a desktop shortcut to open these workbooks as invisibly and quickly as possible.
Issues & solutions
It's slower - I used to run this as a batch script, now Excel has to open to run it
I've made it an .xlsb to reduce opening time, is there a faster method?
I'm not asking how to speed up my workbook, I just mean is there a different way of saving the file (an addin perhaps?) which can run without Excel opening?
I've also only chosen to close Excel when shutdown is aborted, not when it is scheduled, as if Excel is already open then the cancel macro opens faster (which is essential if I accidentally schedule shutdown)
The running is not invisible; although the workbook itself is never shown, the Excel startup image appears
I have tried adding switches to the shortcut target (/e to prevent standard template loading /r for readonly in the hope that it wouldn't display the sheet) - but they don't work
"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" /r /e "C:\Users\USERNAME\Documents\start.xlsb"
The Application calls are Excel-wide. Sometimes, I schedule a shutdown before I've saved everything. (I know it will take me a few seconds to save so I schedule shutdown first)
That was fine when I ran these as .bat/.cmd scripts, but if I run these and Excel is open then everything closes (or becomes invisible - although I have no way of checking which one), which is not ideal when I'm still working on something.
Can I make sure these only hide themeselves? Would opening another instance of Excel help?
TL;DR
I've saved macros as Workbook_Open() events in .xlsb workbooks, which run from desktop shortcuts
How can I improve on this in
Making the process hidden
Making the process faster
Preventing the process screwing up the rest of Excel
By
Flags in the desktop shortcut
Changes to the macro code
Changing how the macro is saved
And
Without just converting to scripts as they are blocked
NB, I would do this with VBS to circumvent Excel entirely, but that is blocked too
Fastest is a desktop shortcut with the shutdown command, i.e. %WINDIR%\system32\shutdown.exe /s /f
I have a program the opens a window, reads a config file, then closes the window a fraction of a second later, then continues running in background. I want to be able to start this program one way or another without the window appearing in the first place.
Is there a way for me to launch the program (preferably on PC startup) but suppress any windows it creates?
I do not have the source code for the program in question. In that regard I am an end-user.
use a vbs script to open it:
set obj = createobject("wscript.shell")
obj.run "prog.exe",0,false
call that prog.vbs or whatever, and put it in:
"%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\startup"
I am using nant, but this can apply to any thing, I just want to know if there is a way to set windows cmd or console2 or some kind of shell to give me a popup or make a noise when it is "finished" (i.e. when it is waiting and the screen says >C:\User\Random_FILE_PATH>_)
I'm using windows 7.
Valentine
sorry, to clarify, I am not running a script that I created, this is just when running anything in the console. I would like it to be that anytime my console is waiting for me it creates a pop up or a noise. This would ideally be some kind of setting
You may open a message box in the end of your batch file, using WSH with a simple VBScript or JScript. See Show a popup/message box from a Windows batch file for an example.
c:\> my_command & mshta.exe vbscript:Execute("msgbox ""finished"",0,""finished"":close")
this here uses conditional execution - when my_command is finished the mshta.exe will be executed with arguments in the brackets.As the parameter passing here is not so easy the string given to msgbox will not be displayed.
you can add a beep to your prompt:
set prompt=%prompt%^G
Don't type ^G. To get it, keep your alt-key pressed while entering 0 0 7 on your numeric keyboard.
Is there a way to minimize all windows automatically when launching an application?
I tried to call a .vbs file with the content above:
Set shell = wscript.CreateObject("Shell.Application")
Shell.MinimizeAll
But doing this, application is minimized too.
I'm not sure if this minimizes the windows, but it will probably satisfy your requirement:
set objShell = CreateObject("shell.application")
objShell.ToggleDesktop
This is equivalent to clicking the show desktop button.
Or as just extending your code:
shell.ToggleDesktop
Edit: Nevermind... this does the same thing as your code above. But why not just run this and then display your window? For instance, if it is your app... call the vbs and then display the window. Or if you have no control over the app, call it from a .bat file and run this vbs then your program.
What you want to do is first minimize all applications or toggle the desktop; THEN (perhaps even after a delay) open your application.
Is there any method in JScript to get the handle of the main window of a process by providing the process name? The Process.MainWindowHandle property works only in JScript .NET. Is anything similar available in classic JScript?
I am not sure if this works, just try to loop window.parent until its undefined.
something like -
var mainWindow = window;
while( mainWindow.parent ) {
mainWindow = mainWindow.parent;
}
you also have something like window.top which always returns you the topmost window. But not sure if this is supported by all browsers.
JScript and Windows Script Host don't have this functionality, and neither does WMI.
If PowerShell is an option for you, then you can use the Process.MainWindowHandle property you mentioned:
(Get-Process notepad).MainWindowHandle
Otherwise, you'll need to find or write an utility (COM object, command-line tool etc) that would provide this functionality, and call this tool from your script.
Edit: So you need to close the window — that's a UI automation task.
Windows Script Host provides very limited UI automation functionality. If you know the window title, you could try using the AppActivate to and SendKeys methods to activate that window and send the Alt+F4 shortcut to it. You can find an example this answer. (The code is in VBScript, but it should give you the idea.) However, this approach isn't reliable.
If you really really don't want to kill the process, the easiest solution is to use some third-party UI automation tool. For example, you could try the free AutoIt tool — I think it should be able to accomplish what you need.
Edit 2: Have you tried recording the closing of the window? You should get a script like this:
Sys.Process("notepad").Window("Notepad", "Untitled - Notepad").Close();
Isn't this what you need?
For a native win32 application, there is no such thing as a "main window". A process can have no windows at all, or several top level "main" windows.
Well once i had to write a add-in for Outlook. My boss wants a splash-screen to appear when Outlook loads. But Outlook window goes over the splash. After a lot of search i found FindWindow http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k%28FINDWINDOW%29%3bk%28TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22%29%3bk%28DevLang-CSHARP%29&rd=true this is help for it . This function finds window based on window caption and window class name. I p-invoked it and used it from C#. If you can use this function through JScript I think it could do the job for you. (I used Spy++ for finding lpClassName parameter)