Solved

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

Posted on 2013-02-05
6
849 Views
Last Modified: 2013-02-06
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
Comment
Question by:ddantes
  • 3
  • 3
6 Comments
 
LVL 16

Accepted Solution

by:
choward16980 earned 250 total points
Comment Utility
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
 
LVL 16

Expert Comment

by:choward16980
Comment Utility
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
 

Author Closing Comment

by:ddantes
Comment Utility
Very nice, thank you!
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:ddantes
Comment Utility
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
 
LVL 16

Expert Comment

by:choward16980
Comment Utility
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
 

Author Comment

by:ddantes
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A short article about problems I had with the new location API and permissions in Marshmallow
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now