Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to open directory in same window

Status
Not open for further replies.

sqgtom

Programmer
Oct 23, 2007
4
GB
Hi there,

Hopefully someone can offer a simple answer to a problem I'm having...

I have successfully added an item to my My Computer listing using the instructions here ([URL unfurl="true"]http://forum.osnn.net/archive/index.php/index.php?t-4177.html[/url])

However, following these instructions... using the command "explorer /e,D:\files\clients\" opens this directory in a new window, rather than the current one.

I have been told elsewhere that I may need a VBScript to do this.

If so, could anyone give me any tips on how to acheive this?

Essentially, i need to feed script/command a directory name, and the current windows explorer window should CD to that directory.

Thanks in advance!
 
1. Why is the window already open?

2. How do you plan to invoke this script?

Mike
 
Hi Mike,

Scenario is as follows:

- Windows explorer is open at My Computer
- User dbl-clicks custom link (as set up in url above)
- Explorer changed directory to target.

Essentially is a standard shortcut, with exception that I need to use regedit to create link to appear in 'My Computer' list. At the moment, it currenly invokes "explorer /e,D:\files\clients\", which unfortunately opens in a new window, rather than the current one.

Hope that clarifies things.

Regards,

Tom
 
wonder if someone could figure this out.
Based on the above folder creation if I use a script to create the values, the default values remain and my default values are ignored
e.g The system creates a string value (Default)(value not set)
then creates a value Default My Folder.
If you then edit the registry manually and set the (Default) to My Folder it works. How do I fix it?

Code:
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
path = "HKEY_CLASSES_ROOT\CLSID\{FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}"
wshshell.regwrite Path &  "\Default", "My Folder", "REG_SZ"
wshshell.regwrite Path &  "\DefaultIcon", "C:\WINDOWS\Installer\{0EFDF2F9-836D-4EB7-A32D-038BD3F1FB2A}\folder.ico", "REG_SZ"
wshshell.regwrite Path &  "\InProcServer32\Default" , "shell32.dll", "REG_SZ"
wshshell.regwrite Path &  "\InProcServer32\ThreadingModel", "Apartment" ,"REG_SZ"
wshshell.regwrite Path &  "\Shell\Open My Folder\Command\Default", "explorer /e,c:\Backup","REG_SZ"
wshshell.regwrite Path &  "\ShellEx\PropertySheetHandlers\{FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}","REG_SZ"
wshshell.regwrite Path &  "\ShellFolder\Attributes", CLng(&H00000000), "REG_BINARY" 
wshshell.regwrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}\Default","", "REG_SZ"
wshshell.regwrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}\Default","", "REG_SZ"
 
[1] For all instance where default is set to "something".
>wshshell.regwrite Path & "\Default", "My Folder", "REG_SZ"
[tt]wshshell.regwrite Path & "[highlight]\[/highlight]", "My Folder", "REG_SZ"[/tt]

[2] If you want to set the leave default not set, leave out the second parameter and enclose the line with on error resume next and on error goto 0. I don't see the need of this, though, in your script. Just a note for completeness.
 
Thanks tsuji, works like a charm. Thats something I never knew.
 
and for those who wish to use it in a AD environment to point to a users folder, I used first 8 characters of there name, but change it if you want

Code:
On Error resume next
Set WshShell = CreateObject("Wscript.Shell")
Set objRootDSE = GetObject("LDAP://RootDSE")

If Err.Number = 0 Then
    strNamingContext = objRootDSE.Get("defaultNamingContext")
End If

Set objADSysInfo = CreateObject("ADSystemInfo")
strUserDN = objADSysInfo.username

' Bind to user object
Set objUser = Getobject("LDAP://" & strUserDN)
'WScript.Echo "First name:........ " & objUser.Get("givenName")

strcomputer = "."
UsersFirstName = objUser.Get("givenName")
enterName = (Left(UsersFirstName,8))
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
path = "HKEY_CLASSES_ROOT\CLSID\{FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}"
wshshell.regwrite Path &  "\", enterName & "'s Folder", "REG_SZ"
wshshell.regwrite Path &  "\DefaultIcon", "C:\WINDOWS\Installer\{0EFDF2F9-836D-4EB7-A32D-038BD3F1FB2A}\folder.ico", "REG_SZ"
wshshell.regwrite Path &  "\InProcServer32\" , "shell32.dll", "REG_SZ"
wshshell.regwrite Path &  "\InProcServer32\ThreadingModel", "Apartment" ,"REG_SZ"
wshshell.regwrite Path &  "\Shell\Open My Folder\Command\", "explorer /e,\\server1\share$\Users\" & enterName,"REG_SZ"
wshshell.regwrite Path &  "\ShellEx\PropertySheetHandlers\{FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}","REG_SZ"
wshshell.regwrite Path &  "\ShellFolder\Attributes", CLng(&H00000000), "REG_BINARY" 
wshshell.regwrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}\","", "REG_SZ"
wshshell.regwrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{FD4DF9E0-E3DE-11CE-BFCF-ABCD1DE12345}\","", "REG_SZ"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top