[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1099
  • Last Modified:

Script to open a folder, refresh the view, and close the folder on Windows startup

My Windows 7 Professional SP-1 system has a number of shared drives which appear in My Computer as physical drives, but they are actually TrueCrypt volumes residing in a NAS.  When the system is rebooted, these volumes are mounted, and attributes for sharing and permissions are applied automatically.  However, the first time My Computer is opened, the sharing icons are not apparent until the view is refreshed.  I would like to automate this refresh process on startup.  But I don't want to do it by closing and restarting explorer.exe, because doing so removes customized desktop icon caption colors, and also removes several icons from the notification area.   So, on startup, I would like to run a batch file which opens, refreshes, and closes the folder "My Computer."  Thank you.
0
ddantes
Asked:
ddantes
  • 3
  • 3
1 Solution
 
Chris HInfrastructure ManagerCommented:
Paste the code below the line into notepad and save as run.vbs
Run to test
If good, add to startup folder

Locate startup folder:
Under start button->all programs)->startup  
Right click startup folder and select open

Worked like a charm for me:
____________________________________________

Set ShObj = CreateObject("wscript.shell")
Set WshShell = WScript.CreateObject("WScript.Shell")
ShObj.run "explorer.exe /root,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
Wscript.Sleep 500
WshShell.SendKeys "%v"
Wscript.Sleep 500
WshShell.SendKeys "r"
Wscript.Sleep 500
WshShell.SendKeys "r"
Wscript.Sleep 500
WshShell.SendKeys "{ENTER}"
Wscript.Sleep 500
WshShell.SendKeys "%F"
WshShell.SendKeys "c"
Wscript.Quit
0
 
Chris HInfrastructure ManagerCommented:
PS.  You can remove some of the sleep commands to speed up.  JUst make sure to test. You may also need to lengthen some if computer is sluggish on boot..
0
 
ddantesAuthor Commented:
Very nice, thank you!
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ddantesAuthor Commented:
I may have jumped the gun by closing this question after one test.  The refresh is inconsistent with this script.  I'll try increasing the sleep times.  Meanwhile, is there a way to make the performance more reliable?
0
 
Chris HInfrastructure ManagerCommented:
Increase all the sleep commands to 1500 and see if that atleast shows you where the program is crapping out.  If it isn't opening my computer, you may already have an explorer window open, which might cause an issue.
0
 
ddantesAuthor Commented:
Screenshot of My Computer, after vb script refreshes the window, and before it closes the windowScreenshot of My Computer, after script has run completelyThank you.  Increasing the sleep commands allowed me to observe the performance of the script, which appeared to do what it is intended to do.  A screenshot of My Computer, just before the script closes the window, shows that the drives in question (J:, P: and V:) are all shared, as expected.  But just afterwards, if I open My Computer on the desktop, the "shared drive" icons are missing from those drives, until I manually refresh the window.  These two My Computer windows have slightly different settings, but I don't understand why the sharing attribute isn't displayed, regardless of that.  

To resolve this, the VB script was edited, targeting a shortcut to the My Computer folder on the desktop, instead of the folder itself.  Why this was successful, I don't understand.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now