Block screensaver - screensaver

Could you provide simple approach to block screensaver and prevent locking computer.
I need this for running automation tests and I have no rights to change this on local machine due to global computer locking company policy.

here's mouseJiggler
Mouse Jiggler is a very simple piece of software whose sole function
is to "fake" mouse input to Windows, and jiggle the mouse pointer back
and forth.
Useful for avoiding screensavers or other things triggered by idle
detection

a windows system? I did on Windows 2008 R2:
use notepad.exe to create c:\temp\idle.vbs
paste code
Dim objResult
Set objShell = WScript.CreateObject("WScript.Shell")
i = 0;
Do While i = 0
objResult = objShell.sendkeys("{NUMLOCK}{NUMLOCK}")
Wscript.Sleep (60000)
Loop
every 60 seconds, this script "press" numlock twice
run the script C:\Windows\System32\cscript.exe c:\temp\idle.vbs
Additonal you can create a new Shortcut, paste the command line and set to "run minimized", camouflagethe icon to explorer or other stuff.

Related

Run macro from desktop, hidden & with minimum system impact

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

RStudio lost focus when start up

When I start up RStudio on Windows, it lost focus. I have to click on it before I could input anything to the console or script window. I know that Ctrl-1 to focus on the Script Window, and Ctrl-2 to focus on the console window; however, both of these two shortcuts will work as long as I click on RStudio first.
Is there anything I need to set in RStudio?
Software Environment:
RStudio Version 0.99.446
Windows 7 Ultimate 64-bit
As a kludge, you can write a VBScript which first opens RStudio and then switches the focus to it:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.CurrentDirectory = "C:\Program Files\RStudio"
WshShell.Run """C:\Program Files\RStudio\bin\rstudio.exe"""
WScript.Sleep 200 'milliseconds
focused = WshShell.AppActivate("RStudio")
i = 1
Do While Not focused And i < 10
WScript.Sleep 100
focused = WshShell.AppActivate("RStudio")
i = i + 1
Loop
Save this to the desktop in a file with a name like ToRStudio.vbs. Then, when you click on the icon, it opens up Rstudio and then tries to repeatedly switch focus to the RStudio window. In my original version of the code, I relied on a fixed time delay before issuing a single call to AppActivate. But, I discovered that when my workspace saved from my last session was large then my VBScript would finish executing before RStudio was ready. With the above loop, it repeatedly tries to grab focus before timing out. Since I put in the loop, it has had a 100% success rate in opening RStudio with the proper focus. In some debugging code I removed, the variable i never once got above 3 in 10 consecutive attempts.
Obviously, you might have to change the path names, and tweak the timings.
In my comment above I said that certain things about how RStudio handled focus struck me as counterintuitive. Since then I discovered RStudio's option to automatically switch focus to console on sourcing. The lack of doing this by default is what I had in mind. The issue in this question was the only remaining focus issue for me. I'm somewhat used to it by now, so I'm not sure if I'll actually use this VBS script.

Can an already running program's window be hidden?

I have been using wsh to run vbscripts in conjunction with iMacros at my work for going on 3 years now. I know that the iMacros browser itself has an option to run hidden but the web-based db interface I have to work with does not function in the iMacros browser. For this reason I have had to use Internet Explorer. I have no problems with the script itself or how it runs. The thing I would like to improve is how the Internet Explorer window itself is handled.
Currently, when iMacros is initiated it creates the IE window in a non-maximized state cascaded from where the previous window was created. Because of iMacros's behavior, I then resize the window using an iMacros script so that enough of the page is rendered for the script to see everything it needs.
Set iim1 = CreateObject ("imacros")
iret = iim1.iimOpen ("-ie -iePrivate", TRUE, 300)
iret = iim1.iimPlayCode("SIZE X=" & scrWidth & " Y=" & scrHeight)
This all works fine and dandy. The scripts are scheduled to run at specific times, gather information out of the db and then imports that data into Excel spreadsheets and prints them out.
What I would like to do is make the IE window hidden while these scripts run. Because I do not create the IE window first (Set objIE = CreateObject("internetexplorer.Application")) I do not have access to the IE window object. I let iMacros create the window with the -iePrivate flag so that it will not disturb my own IE window if I should be logged in and working in the db while the script executes. However, it does try to take focus and become the active application while the script executes. Which can be very annoying at time. My goal is to be able to share these scripts with my co-workers but I don't want the IE windows popping up on them while they may be working on something else.
Is there a way to get to the IE object created by iMacros so that the window can be hidden?
This does Internet Explorer and Explorer windows (they used to be the same program).
Set objShell = CreateObject("Shell.Application")
Set AllWindows = objShell.Windows
For Each window in AllWindows
msgbox window.locationname
Next

How can I automatically cancel the Enter Network Password prompt in Outlook?

I have an unattended PC which does a very simple task : read emails from a POP server and run various tasks based the content of those emails... 24/7/365
The problem is that at least once a week "something" glitches and the processing stalls because Outlook is waiting for a user to confirm their password with the dreaded Enter Network Password dialog.
I have read so many articles in the past 6 months in an attempt to fix the root cause and nothing has worked. There's no WiFi involved and the email server is Google so it should be extremely reliable so I can only suspect that the broadband connection to my ISP is the culprit as I've read that "certain network conditions" can trigger the password prompt.
Yesterday, I gave up on the root cause approach and looked for an automated tool to cancel the annoying dialogue box when it appears. To my surprise, Windows can do this out-of-the-box via Windows Script Host. Here's how:
A. Open your preferred text editor.
B. Copy paste the following VB Script (you can also use JScript if you prefer but I'm not including the syntax here).
Set WshShell = WScript.CreateObject("WScript.Shell")
' Move focus to the network password dialog if it exists (if not, script continues)
If WshShell.AppActivate ("Enter Network Password") = True Then
' Suspend the script for 1/10th second to make sure the dialogue is in focus
WScript.Sleep 100
WshShell.SendKeys "{ESC}"
' Optionally save this event to a log file
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, file
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("C:\Temp", ForAppending, tristateFalse)
file.Write vbCrLf & Date & " " & Time
file.Close
End If
Set WshShell = Nothing
C. Save the file with a .vbs extension e.g. EscapePrompt.vbs
D. Next, open the Windows Task Scheduler (Click the Windows Start button and type "Task" and you should see Task Schedule appear at the top of the search result list, or just type "Task" from the Windows 8 tile view).
Create a new task that runs the script file above, every day, repeating every 5 minutes, indefinitely:
General tab : give the task a name and then check Run with highest privileges
New Trigger tab : click New and select Daily and then in the Advanced Settings, check Repeat task every: and choose 5 minutes. set the for a duration of: to Indefinitely. Check Enabled
Actions Tab : click New and then Browse to choose the script file you created above.
Conditions tab : Set any conditions as required by your environment.
Settings tab : I don't change anything here but you may want to.
Now, when the Enter Network Password prompt appears, there is a maximum delay of 5 minutes before it is automatically cancelled.
For more information on WScript and in particular, the SendKeys method, check out MSDN :
http://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx
You may also be interested in our free VBA examples at:
http://youpresent.biz/category/blog/vba/
Microsoft outlook keeps prompting network password if there registry value and network password mismatches. If you change the password for your account in ISP or Control Panel.Then, configure and login outlook with the new password.Then ,it will not prompt for outlook password again and again.

Minimize windows, application startup

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.

Resources