Link to home
Start Free TrialLog in
Avatar of martinlest
martinlest

asked on

VBS script question

Though I have some basic knowledge of vbs syntax, I am (as will be clear I think from the nature of my question) pretty much a beginner here. I have a VBS script which shows and hides hidden files. I was looking to find an addition to the script that would close the 'OK' message box after a given timeout. I have two other 'autotimeout' scripts but I can't see how to integrate them into my HiddenFile script - the best I can get is for the three scripts to run one after the other from one vbs file.

Can someone kindly indicate how to get my the message box 'OK' of my HiddenFile script to close after, say 3 seconds, using (or not!) one of these other two autoclosing scripts? (These latter have messages obviously irrelevant to the main script - I've just posted them 'raw').

Many thanks,

Martin

Scripts:

' Script to toggle Windows Explorer display of hidden files and super-hidden
' files

Option Explicit
Dim dblHiddenData, strHiddenKey, strSuperHiddenKey, strFileExtKey
Dim strKey, WshShell

On Error Resume Next

strKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
strHiddenKey = strKey & "\Hidden"
strSuperHiddenKey = strKey & "\ShowSuperHidden"
strFileExtKey = strKey & "\HideFileExt"

Set WshShell = WScript.CreateObject("WScript.Shell")
dblHiddenData = WshShell.RegRead(strHiddenKey)

If dblHiddenData = 2 Then
   WshShell.RegWrite strHiddenKey, 1, "REG_DWORD"
   WshShell.RegWrite strSuperHiddenKey, 1, "REG_DWORD"
   WshShell.RegWrite strFileExtKey, 0, "REG_DWORD"
   WScript.Echo "Windows Explorer will show hidden files" & _
      ". You might need to change to another folder or " & _
      "press F5 to refresh the view for the change to take effect."
Else
   WshShell.RegWrite strHiddenKey, 2, "REG_DWORD"
   WshShell.RegWrite strSuperHiddenKey, 0, "REG_DWORD"
   WshShell.RegWrite strFileExtKey, 0, "REG_DWORD"
   WScript.Echo "Windows Explorer will not show hidden files" & _
      ". (These are the default settings.) You might " & _
      "need to change to another folder or press F5 to refresh the " & _
      "view for the change to take effect."
End If

-------------

dim naptime, objDOS
naptime = 2
set objDOS = CreateObject ("WScript.Shell")
objDOS.Popup "This box will close automatically "  , naptime, "Sleeper", 0

---------------

Const wshYes = 6
Const wshNo = 7
Const wshYesNoDialog = 4
Const wshQuestionMark = 32

Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

intReturn = objShell.Popup("Do you want to delete this file?", _
    2, "Delete File", wshYesNoDialog + wshQuestionMark)

If intReturn = wshNo Then
    Wscript.Quit
End If
Avatar of aikimark
aikimark
Flag of United States of America image

It looks like your dialog should time out in 2 seconds (as written).  What is actually happening?

Reference:
http://www.microsoft.com/technet/scriptcenter/guide/sas_wsh_ijhw.mspx
Avatar of martinlest
martinlest

ASKER

Hi. I've looked at many pages like that one but they haven't helped me to embed a script like this (or the ones I already posted):

Const TIMEOUT = 2
Set objShell = WScript.CreateObject("WScript.Shell")

objShell.Popup "Disk Report Complete", TIMEOUT

into my original script. (It doesn't matter whether the timeout value is 2, 3 0r 100 seconds by the way). Either my original script runs and the IK box just sits on the screen, or I get script error messages.

How do I incorporate one of the timeout scripts into the Show/Hide Hidden Files script so that the final message box (about F5) auto-closes? Nothing I have tried works.

Thank you
IK box = OK box, of course!
How are you launching this script?  

I've seen some references to different behavior, based on the runtime environment.
Double-click on a shortcut to the vbs file. All the scripts run fine individually that way, but I posted here because I don't know how to integrate the lines for auto-closing with the original script.
Try running it from a command prompt or the Start | Run dialog
WSCRIPT.EXE YourScriptWithPopup.vbs

or

CSCRIPT.EXE YourScriptWithPopup.vbs
But I don't have 'it' yet to run. That was what I was asking (not sure what it is that I am not making clear) - all I have is several separate scripts, all of which run OK individually. Maybe someone could post a version of the hidden files script that they think should autoclose?

Thanks.

M.
You earlier answered my question indicating that you double click on a VBS file icon.  Now you hint that some of these scripts might launch other scripts.  This is important information.  Please back up a minute and describe the sequence of events and how one script might launch another.

During my research, I read about such second-order invocation situations that cause the Popup with timer to misbehave.
You've totally lost me. All the scripts run fine individually, without launching any other scripts, when I click on them or their shortcut . I simply want to make the HiddenFile script message box to close itself instead of my having to click 'OK' using Popup+timeout, or other.
If "All the scripts run fine individually", then you don't have a problem with the messagebox timeout when you run them this way?
The individual timeout scripts work fine, but they are only demos - the HiddenFile script has no timeout element in it - that's what I am trying to include. How do I incorporate one of the timeout scripts into the HiddenFile script so that this latter closes automatically.
1. replace WScript.Echo  with Popup
2. try to detect differences between a timeout and a response and act accordingly
If I replace WScript.Echo with Popup I just get script error message.

I was hoping someone could just paste a script that worked into their reply, but no matter: don't worry about this any more, we are just going around in circles and I have spent too much time on this now. I thought it would be a simple thing but I'll just click on the 'OK' button.

M.
Don't give up.  The answer seemed rather simple to me and I didn't want to insult your intelligence with a snarky answer.  I don't know what kind of script error you are getting, but I envisioned something like the follow:
Set objShell = CreateObject("Wscript.Shell")
 
If dblHiddenData = 2 Then
   WshShell.RegWrite strHiddenKey, 1, "REG_DWORD"
   WshShell.RegWrite strSuperHiddenKey, 1, "REG_DWORD"
   WshShell.RegWrite strFileExtKey, 0, "REG_DWORD"
   objShell.Popup "Windows Explorer will show hidden files" & _
    ". You might need to change to another folder or " & _
    "press F5 to refresh the view for the change to take effect.", & _ 
    10, "Show Hidden Files", wshOKDialog
Else
   WshShell.RegWrite strHiddenKey, 2, "REG_DWORD"
   WshShell.RegWrite strSuperHiddenKey, 0, "REG_DWORD"
   WshShell.RegWrite strFileExtKey, 0, "REG_DWORD"
   objShell.Popup "Windows Explorer will not show hidden files" & _
     ". (These are the default settings.) You might " & _
     "need to change to another folder or press F5 to refresh the " & _
     "view for the change to take effect.", & _
     10, "Do Not Show Hidden Files", wshOKDialog
End If

Open in new window

Thanks but this gives me script errors. I can remove some errors by removing commas in the text, such as the comma in line 23 (why did you add the comma here?)

 .....effect.", & _  

but this for instance I can't see why it's wrong:

Line 12, Char 4, Error: Object required: 'WshShell'  Code 800A01A8

I won't have chance to do more on this for a while now I'm afraid..

M.
the code I posted was meant to replace the If...Else...End If construct in your initial script example.  I can not stand alone because I assumed that you would place it within the other script which does have the WshShell object initialization.
ASKER CERTIFIED SOLUTION
Avatar of martinlest
martinlest

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@martinlest

When will you return to this problem thread?