How can you have a dialog box displayed when opening a program in windows xp? - windows

Does anyone know how to have a dialog box with a custom message pop up any time that a specific program is opened? The computer is running Windows XP Professional 2002 with Service Pack 3. The program is used to operate a scientific instrument that keeps getting damaged by lab users who disregard printed instructions around it. Ideally, I could have a dialog box pop up that requires users to click an "OK" button before the program opens. I've spent some time browsing the web for ideas, but have so far come back empty-handed. The program is usually opened from a shortcut on the desktop.
Many thanks,
Jeremy

A user on another forum answered this question for me. I created a small shell script (text file saved with .vbs extension) to display the dialog box when the program is opened from a Desktop shortcut targeting the script file.
Here's the link to the post in the other forum for more details:
The script that worked for me is shown below:
startupMessage = MsgBox("...close the lid gently and only use the button to open it.", 0, "To prevent instrument damage...")
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim cmd
cmd = "C:\Program Files\InstrumentApplication.exe"
cmd = chr(34) & cmd & chr(34)
WshShell.Run(cmd)

Related

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

Invoke 'Open' Dialog from Windows Desktop

Is there some way I can programmatically (in VBS) OR by using CMD/RUN open the 'Open' dialog that contains the places bar and a browser but without opening say notepad or MSpaint?
http://i.technet.microsoft.com/dynimg/IC354177.jpg
I'd like to use this on the desktop itself, it would be really cool if there was a DLL I can just use instead of having a VBS file but if not i'm sure its possible in VBS.
I'm busy searching where the actual open dialog box comes from, it should come from some DLL file somewhere.
I might even consider stopping the windows shell from opening all together and just using this open window as the shell on some computers.
Regards, Rocklore
What version of Windows are you on?
"UserAccounts.CommonDialog" was the way to do this in XP. But it no longer exists in Windows 7. You may be able to use some of the flags available for the BrowseForFolder() method to make it look like a file open dialog. See this page for an example.
XP Edit:
Here's an XP example using UserAccounts.CommonDialog.
With CreateObject("UserAccounts.CommonDialog")
.InitialDir = CreateObject("WScript.Shell").SpecialFolders("Desktop")
.Filter = "All Files|*.*"
' Show the dialog. If [Open] is clicked, save the name of the selected file...
If .ShowOpen Then strFile = .FileName
End With

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.

Using WSH (VBS) with iMacros - how do they do it?

(iMacros For Firefox 6.6.5.0; Firefox 3.6.3; Windows XP Pro SP3 w/all updates)
I made an iMacro to select "load next 25" (comments) on a web page (CNN.COM). Unfortunately, iMacros doesn't appear to do looping (do the above until that string doesn't appear on the page anymore - i.e. all the comments are loaded). I tried putting {!iloop} in the TAG command, and it didn't work - then I read it wouldn't.
So I tried the example at http://wiki.imacros.net/Loop_after_Query_or_Login
I can't find any information on how to actually run the script in the above example. I searched Google and found VBS scripting is handled with .wsh files with Windows XP Pro. (The examples and other references there say Windows does VBS natively, so I looked up how with Google.)
So I made the following .wsh file (modified the above example):
Option Explicit
Dim iim1, iret
'initialize iMacros instance
set iim1 = CreateObject ("imacros")
iret = iim1.iimInit()
do while not iret < 0
iret = iim1.iimPlay("Load All CNN Comments")
loop
' tell user we're done
msgbox "End."
' exit iMacros instance and quit script
iret = iim1.iimExit()
Wscript.Quit()
Here's the iMacro: (Load All CNN Comments.iim)
VERSION BUILD=6650406 RECORDER=FX
TAG POS=1 TYPE=A ATTR=TXT:Load<SP>next<SP>25
WAIT SECONDS=#DOWNLOADCOMPLETE#
The iMacro works by itself - I press Play (left iMacro panel) and the next 25 comments load on the CNN.com page in the current tab.
I put the .wsh file in the ...\iMacros\Macros directory - with the iMacro "Load All CNN Comments.iim"
When I run the .wsh file (by just double clicking on it's icon - I created it with Notepad, and Windows gave it an icon for that file type - it's executable) I get the message from "Windows Script Host" - "There is no script file specified." I wasn't actually expecting it to work, as I don't see how Windows would know to call iMacros to run the iim macro.
It would be nice if there was a simple, COMPLETE, example of how to use a VBS script with iMacros, that isn't bogged down with unnecessary complication like filling in a form, loading multiple pages, etc. I can't find ANY example.
So what do I need to do to get this to work? I just installed iMacros yesterday, because I am constantly having the problem that there are hundred of comments after a CNN.com article, and loading 25 more at a time until they are all on the page makes it impractical to read any replies to my comments.
It would also be nice if I could run the Macro from Firefox, rather than by double clicking on some file somewhere.
Thanks for any help.
Try changing the extension of your script from .WSH to .VBS.

Resources